FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/resizable_split.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼受 MIT 授權條款約束,詳情請參閱 LICENSE 文件。
3#include <memory> // for shared_ptr, allocator, __shared_ptr_access
4
5#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
6#include "ftxui/component/component_base.hpp" // for ComponentBase
7#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
8#include "ftxui/dom/elements.hpp" // for Element, operator|, text, center, border
9
10using namespace ftxui;
11
12int main() {
13 auto screen = ScreenInteractive::Fullscreen();
14
15 // 狀態:
16 int left_size = 20;
17 int right_size = 20;
18 int top_size = 10;
19 int bottom_size = 10;
20
21 // 渲染器:
22 auto RendererInfo = [](const std::string& name, int* size) {
23 return Renderer([name, size] {
24 return text(name + ": " + std::to_string(*size)) | center;
25 });
26 };
27 auto middle = Renderer([] { return text("Middle") | center; });
28 auto left = RendererInfo("Left", &left_size);
29 auto right = RendererInfo("Right", &right_size);
30 auto top = RendererInfo("Top", &top_size);
31 auto bottom = RendererInfo("Bottom", &bottom_size);
32
33 auto container = middle;
34 container = ResizableSplitLeft(left, container, &left_size);
35 container = ResizableSplitRight(right, container, &right_size);
36 container = ResizableSplitTop(top, container, &top_size);
37 container = ResizableSplitBottom(bottom, container, &bottom_size);
38
39 auto renderer =
40 Renderer(container, [&] { return container->Render() | border; });
41
42 screen.Loop(renderer);
43}
static ScreenInteractive Fullscreen()
Component ResizableSplitTop(Component main, Component back, int *main_size)
兩個元件之間的垂直分割,可透過滑鼠設定。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
Component ResizableSplitRight(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過滑鼠設定。
Component ResizableSplitBottom(Component main, Component back, int *main_size)
兩個元件之間的垂直分割,可透過滑鼠設定。
Component ResizableSplitLeft(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過滑鼠設定。
Decorator size(WidthOrHeight, Constraint, int value)
限制元素的大小。
Element center(Element)
水平與垂直置中一個元素。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element border(Element)
在元素周圍繪製邊框。
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::uint8_t top
Definition screen.cpp:131
std::uint8_t left
Definition screen.cpp:130
std::uint8_t right
Definition screen.cpp:132