First kind of working FTXUI for the game.

This commit is contained in:
Zed A. Shaw 2024-08-20 17:29:58 -04:00
parent 6fc74ca199
commit 6d4aa9390a
3 changed files with 127 additions and 58 deletions

View file

@ -37,33 +37,13 @@ int main() {
vector<string> lines;
// Create a component counting the number of frames drawn and event handled.
int custom_loop_count = 0;
int frame_count = 0;
int event_count = 0;
float scroll_x = 0.1;
float scroll_y = 1.0;
int hp = 100;
int row = 0;
auto hit_button = Button("Hit", [&] {
hp -= 1;
lines.push_back(fmt::format("You were hit! HP now {}", hp));
}, Style());
auto hard_button = Button("Hard", [&] {
hp -= 10;
lines.push_back(fmt::format("You were hit HARD! HP now {}", hp));
}, Style());
auto heal_button = Button("Heal", [&] {
hp += 10;
lines.push_back(fmt::format("You healed! HP now {}", hp));
}, Style());
auto buttons = Container::Horizontal({
hit_button, hard_button, heal_button}, &row);
auto status = Renderer([&] {
return vbox({
paragraph(fmt::format("HP {} frames {} events {} custom {}",
hp, frame_count, event_count, custom_loop_count)),
paragraph(fmt::format("HP {}", hp)),
separator(),
hbox({
text("HP"),
@ -89,27 +69,22 @@ int main() {
| frame | flex;
});
auto component = Renderer(buttons, [&] {
frame_count++;
auto component = Renderer(scrollable_content, [&] {
return vbox({
status->Render(),
separator(),
buttons->Render(),
scrollable_content->Render() | vscroll_indicator | yframe | size(HEIGHT, LESS_THAN, 20),
}) |
border;
});
component |= CatchEvent([&](Event) -> bool {
event_count++;
return false;
});
Loop loop(&screen, component);
while (!loop.HasQuitted()) {
custom_loop_count++;
loop.RunOnce();
screen.Post(Event::Custom);
std::this_thread::sleep_for(std::chrono::milliseconds(10));