mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
List ftxui_CPUMeter (#744)
This commit is contained in:
parent
e5978a8e76
commit
8d1665022a
@ -325,6 +325,7 @@ Feel free to add your projects here:
|
|||||||
- [eCAL monitor](https://github.com/eclipse-ecal/ecal)
|
- [eCAL monitor](https://github.com/eclipse-ecal/ecal)
|
||||||
- [Path Finder](https://github.com/Ruebled/Path_Finder)
|
- [Path Finder](https://github.com/Ruebled/Path_Finder)
|
||||||
- [rw-tui](https://github.com/LeeKyuHyuk/rw-tui)
|
- [rw-tui](https://github.com/LeeKyuHyuk/rw-tui)
|
||||||
|
- [ftxui_CPUMeter](https://github.com/tzzzzzzzx/ftxui_CPUMeter)
|
||||||
|
|
||||||
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
|
### [cpp-best-practices/game_jam](https://github.com/cpp-best-practices/game_jam)
|
||||||
|
|
||||||
|
@ -12,28 +12,51 @@
|
|||||||
|
|
||||||
using namespace ftxui;
|
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 main() {
|
||||||
int value = 50;
|
int value = 50;
|
||||||
|
|
||||||
|
|
||||||
// The tree of components. This defines how to navigate using the keyboard.
|
// The tree of components. This defines how to navigate using the keyboard.
|
||||||
auto buttons = Container::Horizontal({
|
auto buttons =
|
||||||
Button("Decrease", [&] { value--; }),
|
Container::Vertical({
|
||||||
Button("Increase", [&] { value++; }),
|
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:
|
// Modify the way to render them on screen:
|
||||||
auto component = Renderer(buttons, [&] {
|
auto component = Renderer(buttons, [&] {
|
||||||
return vbox({
|
return vbox({
|
||||||
text("value = " + std::to_string(value)),
|
text("value = " + std::to_string(value)),
|
||||||
separator(),
|
separator(),
|
||||||
gauge(value * 0.01f),
|
buttons->Render() | flex,
|
||||||
separator(),
|
}) | flex | border;
|
||||||
buttons->Render(),
|
|
||||||
}) |
|
|
||||||
border;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
auto screen = ScreenInteractive::FitComponent();
|
auto screen = ScreenInteractive::Fullscreen();
|
||||||
screen.Loop(component);
|
screen.Loop(component);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user