Clean source code. Add to_wstring<T> T={int, float, double, ...}

This commit is contained in:
Arthur Sonzogni 2019-01-06 16:10:57 +01:00
parent c854d07d63
commit 805c9061e5
9 changed files with 52 additions and 71 deletions

View File

@ -8,41 +8,41 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
using namespace ftxui::dom; using namespace ftxui::dom;
auto document = auto document =
hbox( hbox(
window(hcenter(text(L" main frame ")), window(text(L" main frame ") | hcenter,
vbox( vbox(
text(L"Line 1"), text(L"Line 1"),
text(L"Line 2"), text(L"Line 2"),
text(L"Line 3"), text(L"Line 3"),
frame( frame(
vbox( vbox(
text(L"Line 4"), text(L"Line 4"),
text(L"Line 5"), text(L"Line 5"),
text(L"Line 6") text(L"Line 6")
) )
), ),
hbox( hbox(
window(text(L"frame 2"), window(text(L"frame 2"),
vbox( vbox(
text(L"Line 4"), text(L"Line 4"),
text(L"Line 5"), text(L"Line 5"),
text(L"Line 6") text(L"Line 6")
) )
), ),
window(text(L"frame 3"), window(text(L"frame 3"),
vbox( vbox(
text(L"Line 7"), text(L"Line 7"),
text(L"Line 8"), text(L"Line 8"),
text(L"Line 9") text(L"Line 9")
) )
) )
), ),
text(L"footer footer footer footer footer") text(L"footer footer footer footer footer")
) )
), ),
filler() filler()
); );
auto screen = ftxui::Screen::TerminalOutput(document); auto screen = ftxui::Screen::TerminalOutput(document);
Render(screen, document.get()); Render(screen, document.get());
std::cout << screen.ToString() << std::endl; std::cout << screen.ToString() << std::endl;

View File

@ -44,7 +44,7 @@ int main(int argc, const char *argv[])
int nb_done = 0; int nb_done = 0;
auto to_text = [](int number) { auto to_text = [](int number) {
std::wstring t = to_wstring(std::to_string(number)); std::wstring t = to_wstring(number);
while(t.size() < 3) while(t.size() < 3)
t = L" " + t; t = L" " + t;
return text(t); return text(t);

View File

@ -23,7 +23,7 @@ class Input : public Component {
// Component implementation. // Component implementation.
dom::Element Render() override; dom::Element Render() override;
bool OnEvent(Event) override; bool OnEvent(Event) override;
private: private:
int cursor_position = 0; int cursor_position = 0;

View File

@ -27,7 +27,7 @@ class Menu : public Component {
// Component implementation. // Component implementation.
dom::Element Render() override; dom::Element Render() override;
bool OnEvent(Event) override; bool OnEvent(Event) override;
}; };
} // namespace component } // namespace component

View File

@ -52,20 +52,8 @@ Element nothing(Element element);
Element operator|(Element, Decorator); Element operator|(Element, Decorator);
Decorator operator|(Decorator, Decorator); Decorator operator|(Decorator, Decorator);
// Make container able to take several children. // Make container able to take any number of children as input.
template <class... Args> #include "take_any_args.hpp"
Children unpack(Args... args) {
Children vec;
(vec.push_back(std::forward<Args>(args)), ...);
return vec;
}
#define TAKE_ANY_ARGS(container) \
template <class... Args> \
Element container(Args... children) { \
return container(unpack(std::forward<Args>(children)...)); \
} \
TAKE_ANY_ARGS(vbox) TAKE_ANY_ARGS(vbox)
TAKE_ANY_ARGS(hbox) TAKE_ANY_ARGS(hbox)
TAKE_ANY_ARGS(dbox) TAKE_ANY_ARGS(dbox)

View File

@ -4,23 +4,11 @@
namespace ftxui { namespace ftxui {
struct Requirement { struct Requirement {
// Minimal dimensions. // The required size to fully draw the element.
struct { struct { int x = 0; int y = 0; } min;
int x = 0;
int y = 0;
} min;
// Maximal dimensions. // How much flexibility is given to the component.
struct { struct { int x = 0; int y = 0; } flex;
int x = -1;
int y = -1;
} max;
// Flex.
struct {
int x = 0;
int y = 0;
} flex;
}; };
}; // namespace ftxui }; // namespace ftxui

View File

@ -2,3 +2,8 @@
std::string to_string(const std::wstring& s); std::string to_string(const std::wstring& s);
std::wstring to_wstring(const std::string& s); std::wstring to_wstring(const std::string& s);
template<typename T>
std::wstring to_wstring(T s) {
return to_wstring(std::to_string(s));
}

View File

@ -18,8 +18,8 @@ TEST(GaugeTest, half) {
Screen screen(11,1); Screen screen(11,1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("█████▏▋ ", screen.ToString()); EXPECT_EQ("█████ ", screen.ToString());
//" ▏▎▍▌▊▉█"; //" ▏▎▍▌▊▉█";
} }
TEST(GaugeTest, one) { TEST(GaugeTest, one) {

View File

@ -10,7 +10,7 @@ TEST(VBoxTest, ScreenSmaller1) {
Screen screen(6, 1); Screen screen(6, 1);
Render(screen, root.get()); Render(screen, root.get());
EXPECT_EQ("text_1", screen.ToString()); EXPECT_EQ("text_2", screen.ToString());
} }
TEST(VBoxTest, ScreenFit) { TEST(VBoxTest, ScreenFit) {