FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
button_in_frame.cpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. All rights reserved.
2// 使用此原始碼受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3#include <memory> // for allocator, __shared_ptr_access, shared_ptr
4#include <string> // for to_string, operator+
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Button, Renderer, Vertical
8#include "ftxui/component/component_base.hpp" // for ComponentBase
9#include "ftxui/component/component_options.hpp" // for ButtonOption
10#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for operator|, text, Element, hbox, separator, size, vbox, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
12#include "ftxui/screen/color.hpp" // for Color, Color::Default, Color::GrayDark, Color::White
13
14using namespace ftxui;
15
16int main() {
17 int counter = 0;
18 auto on_click = [&] { counter++; };
19
22
23 auto container = Container::Vertical({});
24 for (int i = 0; i < 30; ++i) {
25 auto button = Button("Button " + std::to_string(i), on_click, style);
26 container->Add(button);
27 }
28
29 auto renderer = Renderer(container, [&] {
30 return vbox({
31 hbox({
32 text("Counter:"),
33 text(std::to_string(counter)),
34 }),
35 separator(),
36 container->Render() | vscroll_indicator | frame |
37 size(HEIGHT, LESS_THAN, 20),
38 }) |
39 border;
40 });
41
42 auto screen = ScreenInteractive::FitComponent();
43 screen.Loop(renderer);
44
45 return 0;
46}
int main()
auto button
Definition gallery.cpp:84
static ButtonOption Animated()
創建一個 ButtonOption,使用動畫顏色。
static ScreenInteractive FitComponent()
Component Button(ButtonOption options)
繪製一個按鈕。點擊時執行一個函數。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
virtual void Render(Screen &screen)
Decorator size(WidthOrHeight, Constraint, int value)
限制元素的大小。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94
@ LESS_THAN
Definition elements.hpp:159