mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-18 17:18:08 +08:00
Add more documentation.
This commit is contained in:

committed by
Arthur Sonzogni

parent
f2dc080a35
commit
114ab4ae2a
@@ -3,6 +3,8 @@
|
||||
#include <algorithm>
|
||||
|
||||
namespace ftxui {
|
||||
/// @return the biggest Box contained in both |a| and |b|.
|
||||
/// @ingroup screen
|
||||
// static
|
||||
Box Box::Intersection(Box a, Box b) {
|
||||
return Box{
|
||||
|
@@ -67,14 +67,46 @@ void WindowsEmulateVT100Terminal() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) {
|
||||
if (next.bold != previous.bold)
|
||||
ss << (next.bold ? BOLD_SET : BOLD_RESET);
|
||||
|
||||
if (next.dim != previous.dim)
|
||||
ss << (next.dim ? DIM_SET : DIM_RESET);
|
||||
|
||||
if (next.underlined != previous.underlined)
|
||||
ss << (next.underlined ? UNDERLINED_SET : UNDERLINED_RESET);
|
||||
|
||||
if (next.blink != previous.blink)
|
||||
ss << (next.blink ? BLINK_SET : BLINK_RESET);
|
||||
|
||||
if (next.inverted != previous.inverted)
|
||||
ss << (next.inverted ? INVERTED_SET : INVERTED_RESET);
|
||||
|
||||
if (next.foreground_color != previous.foreground_color ||
|
||||
next.background_color != previous.background_color) {
|
||||
ss << L"\x1B[" +
|
||||
to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m";
|
||||
ss << L"\x1B[" +
|
||||
to_wstring(std::to_string(10 + (uint8_t)next.background_color)) +
|
||||
L"m";
|
||||
}
|
||||
|
||||
previous = next;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/// A fixed dimension.
|
||||
/// @see Fit
|
||||
/// @see Full
|
||||
Dimension Dimension::Fixed(int v) {
|
||||
return Dimension{v, v};
|
||||
}
|
||||
|
||||
/// The minimal dimension that will fit the given element.
|
||||
/// @see Fixed
|
||||
/// @see Full
|
||||
Dimension Dimension::Fit(Element& e) {
|
||||
e->ComputeRequirement();
|
||||
Terminal::Dimensions size = Terminal::Size();
|
||||
@@ -83,6 +115,8 @@ Dimension Dimension::Fit(Element& e) {
|
||||
}
|
||||
|
||||
/// Use the terminal dimensions.
|
||||
/// @see Fixed
|
||||
/// @see Fit
|
||||
Dimension Dimension::Full() {
|
||||
Terminal::Dimensions size = Terminal::Size();
|
||||
return Dimension{size.dimx, size.dimy};
|
||||
@@ -117,34 +151,6 @@ Screen::Screen(int dimx, int dimy)
|
||||
#endif
|
||||
}
|
||||
|
||||
void UpdatePixelStyle(std::wstringstream& ss, Pixel& previous, Pixel& next) {
|
||||
if (next.bold != previous.bold)
|
||||
ss << (next.bold ? BOLD_SET : BOLD_RESET);
|
||||
|
||||
if (next.dim != previous.dim)
|
||||
ss << (next.dim ? DIM_SET : DIM_RESET);
|
||||
|
||||
if (next.underlined != previous.underlined)
|
||||
ss << (next.underlined ? UNDERLINED_SET : UNDERLINED_RESET);
|
||||
|
||||
if (next.blink != previous.blink)
|
||||
ss << (next.blink ? BLINK_SET : BLINK_RESET);
|
||||
|
||||
if (next.inverted != previous.inverted)
|
||||
ss << (next.inverted ? INVERTED_SET : INVERTED_RESET);
|
||||
|
||||
if (next.foreground_color != previous.foreground_color ||
|
||||
next.background_color != previous.background_color) {
|
||||
ss << L"\x1B[" +
|
||||
to_wstring(std::to_string((uint8_t)next.foreground_color)) + L"m";
|
||||
ss << L"\x1B[" +
|
||||
to_wstring(std::to_string(10 + (uint8_t)next.background_color)) +
|
||||
L"m";
|
||||
}
|
||||
|
||||
previous = next;
|
||||
}
|
||||
|
||||
/// Produce a std::string that can be used to print the Screen on the terminal.
|
||||
std::string Screen::ToString() {
|
||||
std::wstringstream ss;
|
||||
|
@@ -9,11 +9,13 @@ namespace ftxui {
|
||||
#pragma warning(disable : 4996) // codecvt_utf8_utf16 is deprecated
|
||||
#endif
|
||||
|
||||
/// Convert a UTF8 std::string into a std::wstring.
|
||||
std::string to_string(const std::wstring& s) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.to_bytes(s);
|
||||
}
|
||||
|
||||
/// Convert a std::wstring into a UTF8 std::string.
|
||||
std::wstring to_wstring(const std::string& s) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.from_bytes(s);
|
||||
|
Reference in New Issue
Block a user