Added button to go to page 2, fixed string issue.

This commit is contained in:
Yohan Boujon 2025-05-08 18:35:16 +02:00
parent c90b0bcabb
commit f63c6e83a8
3 changed files with 22 additions and 8 deletions

View file

@ -16,13 +16,15 @@ private:
ftxui::Element transform(ftxui::InputState state);
ftxui::Element render_input();
ftxui::Element render_log();
ftxui::Element render_status();
ftxui::Component render_status();
bool catch_event(ftxui::Event event);
void change_screen();
std::string _input_str;
ftxui::InputOption _input_option;
bool _input_selected;
ftxui::Component _input_component;
ftxui::Component _button;
};
#endif // HEADER_PAGE1_FTXUI

View file

@ -101,9 +101,22 @@ ftxui::Element Page1::render_log()
flex;
}
ftxui::Element Page1::render_status()
ftxui::Component Page1::render_status()
{
return window(text("status") | hcenter | bold, text("content") | center | dim, BorderStyle::EMPTY) | flex | size(WIDTH, GREATER_THAN, 30);
_button = Button("Go to Page2", [&]
{ return change_screen(); });
return Renderer(_button, [this]
{ return window(
text("status") | hcenter | bold,
vbox({text("content") | center | dim,
_button->Render() | center})) |
flex | size(WIDTH, GREATER_THAN, 30); });
}
void Page1::change_screen()
{
this->send_event(EventType::SWITCH_SCREEN, static_cast<size_t>(1));
}
Page1::Page1(EventHandler &handler)
@ -128,8 +141,7 @@ Page1::Page1(EventHandler &handler)
Component log = Renderer([&]()
{ return render_log(); });
Component status = Renderer([&]()
{ return render_status(); });
Component status = render_status();
_page = Container::Vertical({
Container::Horizontal({log,

View file

@ -12,7 +12,7 @@ inline const std::vector<std::string> create_entries(const size_t num)
{
std::vector<std::string> ret;
for (size_t i = 0; i < num; i++)
ret.push_back("Sample " + std::to_string(num));
ret.push_back("Sample " + std::to_string(i));
return ret;
}