|
|
|
@ -1,4 +1,3 @@ |
|
|
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
|
// the LICENSE file.
|
|
|
|
@ -15,8 +14,10 @@ |
|
|
|
|
#include "ftxui/component/component.hpp" // for CatchEvent, Renderer, operator|= |
|
|
|
|
#include "ftxui/component/loop.hpp" // for Loop |
|
|
|
|
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive |
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
using namespace ftxui; |
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
ButtonOption Style() { |
|
|
|
|
auto option = ButtonOption::Animated(); |
|
|
|
@ -32,26 +33,35 @@ ButtonOption Style() { |
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
|
auto screen = ScreenInteractive::Fullscreen(); |
|
|
|
|
screen.TrackMouse(true); |
|
|
|
|
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; }, Style()); |
|
|
|
|
auto hard_button = Button("Hard", [&] { hp -= 10; }, Style()); |
|
|
|
|
auto heal_button = Button("Heal", [&] { hp += 10; }, Style()); |
|
|
|
|
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 component = Renderer(buttons, [&] { |
|
|
|
|
frame_count++; |
|
|
|
|
|
|
|
|
|
auto status = Renderer([&] { |
|
|
|
|
return vbox({ |
|
|
|
|
paragraph("I'm baby mustache hammock squid, stumptown echo park lumbersexual PBR&B glossier iceland pabst irony mlkshk skateboard migas kombucha. Lyft meggings organic tacos. IPhone microdosing bodega boys, fit locavore jawn cloud bread neutral milk hotel trust fund live-edge selfies portland lyft vice. Pug swag af slow-carb."), |
|
|
|
|
separator(), |
|
|
|
|
paragraph(fmt::format("HP {} frames {} events {} custom {}", |
|
|
|
|
hp, frame_count, event_count, custom_loop_count)), |
|
|
|
|
separator(), |
|
|
|
@ -59,8 +69,34 @@ int main() { |
|
|
|
|
text("HP"), |
|
|
|
|
gauge(hp / 100.0f), |
|
|
|
|
}), |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
auto content = Renderer([&] { |
|
|
|
|
vector<Element> output; |
|
|
|
|
|
|
|
|
|
for(const auto line : lines) { |
|
|
|
|
output.push_back(text(line)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return vbox(output); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
auto scrollable_content = Renderer(content, |
|
|
|
|
[&, content] { |
|
|
|
|
return content->Render() |
|
|
|
|
| focusPositionRelative(scroll_x, scroll_y) |
|
|
|
|
| frame | flex; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
auto component = Renderer(buttons, [&] { |
|
|
|
|
frame_count++; |
|
|
|
|
|
|
|
|
|
return vbox({ |
|
|
|
|
status->Render(), |
|
|
|
|
separator(), |
|
|
|
|
buttons->Render(), |
|
|
|
|
scrollable_content->Render() | vscroll_indicator | yframe | size(HEIGHT, LESS_THAN, 20), |
|
|
|
|
}) | |
|
|
|
|
border; |
|
|
|
|
}); |
|
|
|
|