Skip to content

Commit

Permalink
Merge branch 'main' into add-catalincd-resource-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni authored Sep 18, 2023
2 parents 840fd3b + 5db2be0 commit 2cbeaee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ Feel free to add your projects here:
- [Path Finder](https://github.com/Ruebled/Path_Finder)
- [rw-tui](https://github.com/LeeKyuHyuk/rw-tui)
- [resource-monitor](https://github.com/catalincd/resource-monitor)
- [ftxuiFileReader](https://github.com/J0sephDavis/ftxuiFileReader)
- [ftxui_CPUMeter](https://github.com/tzzzzzzzx/ftxui_CPUMeter)
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
Expand Down
43 changes: 33 additions & 10 deletions examples/component/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,51 @@

using namespace ftxui;

// This is a helper function to create a button with a custom style.
// The style is defined by a lambda function that takes an EntryState and
// returns an Element.
// We are using `center` to center the text inside the button, then `border` to
// add a border around the button, and finally `flex` to make the button fill
// the available space.
ButtonOption ButtonStyle() {
auto option = ButtonOption::Animated();
option.transform = [](const EntryState& s) {
auto element = text(s.label);
if (s.focused) {
element |= bold;
}
return element | center | borderEmpty | flex;
};
return option;
}

int main() {
int value = 50;


// The tree of components. This defines how to navigate using the keyboard.
auto buttons = Container::Horizontal({
Button("Decrease", [&] { value--; }),
Button("Increase", [&] { value++; }),
});
auto buttons =
Container::Vertical({
Container::Horizontal({
Button("-1", [&] { value--; }, ButtonStyle()),
Button("+1", [&] { value++; }, ButtonStyle()),
}) | flex,
Container::Horizontal({
Button("-10", [&] { value -= 10; }, ButtonStyle()),
Button("-10", [&] { value += 10; }, ButtonStyle()),
}) | flex,
});

// Modify the way to render them on screen:
auto component = Renderer(buttons, [&] {
return vbox({
text("value = " + std::to_string(value)),
separator(),
gauge(value * 0.01f),
separator(),
buttons->Render(),
}) |
border;
buttons->Render() | flex,
}) | flex | border;
});

auto screen = ScreenInteractive::FitComponent();
auto screen = ScreenInteractive::Fullscreen();
screen.Loop(component);
return 0;
}

0 comments on commit 2cbeaee

Please sign in to comment.