FTXUI 7.0.3
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// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <memory> // for allocator, __shared_ptr_access, shared_ptr
5#include <string> // for to_string, operator+
6
7#include "ftxui/component/app.hpp" // for App
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Button, Renderer, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/component_options.hpp" // for ButtonOption
12#include "ftxui/dom/elements.hpp" // for operator|, text, Element, hbox, separator, size, vbox, border, frame, vscroll_indicator, HEIGHT, LESS_THAN
13#include "ftxui/screen/color.hpp" // for Color, Color::Default, Color::GrayDark, Color::White
14
15using namespace ftxui;
16
17int main() {
18 int counter = 0;
19 auto on_click = [&] { counter++; };
20
21 auto style = ButtonOption::Animated(Color::Default, Color::GrayDark,
22 Color::Default, Color::White);
23
24 auto container = Container::Vertical({});
25 for (int i = 0; i < 30; ++i) {
26 auto button = Button("Button " + std::to_string(i), on_click, style);
27 container->Add(button);
28 }
29
30 auto renderer = Renderer(container, [&] {
31 return vbox({
32 hbox({
33 text("Counter:"),
34 text(std::to_string(counter)),
35 }),
36 separator(),
37 container->Render() | vscroll_indicator | frame |
38 size(HEIGHT, LESS_THAN, 20),
39 }) |
40 border;
41 });
42
43 auto screen = App::FitComponent();
44 screen.Loop(renderer);
45
46 return 0;
47}
int main()
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
繪製一個按鈕。點擊時執行一個函式。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的 Component,類似 |child|,但使用 |render| 作為 Component::Render() 事件。
Element text(std::string_view text)
顯示一段 UTF8 編碼的 Unicode 文字。
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
對元素的大小套用限制。
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element vbox(Elements children)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:96
FTXUI ftxui:: 命名空間
Definition animation.hpp:11
@ LESS_THAN
Definition elements.hpp:191
Element hbox(Elements children)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94