FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
resizable_split_clamp.cpp
Go to the documentation of this file.
1// 版權所有 2025 Arthur Sonzogni。保留所有權利。
2// 本原始碼受 MIT 授權條款約束,詳情請參閱
3// LICENSE 檔案。
4#include <memory> // for shared_ptr, allocator, __shared_ptr_access
5
6#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop
7#include "ftxui/component/component_base.hpp" // for ComponentBase
8#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
9#include "ftxui/dom/elements.hpp" // for Element, operator|, text, center, border
10
11using namespace ftxui;
12
13int main() {
14 auto screen = ScreenInteractive::Fullscreen();
15
16 // 狀態:
17 int size = 40;
18 int size_min = 10;
19 int size_max = 80;
20
21 // 渲染器:
22 auto split = ResizableSplit({
23 .main = Renderer([] { return text("Left") | center; }),
24 .back = Renderer([] { return text("Right") | center; }),
25 .direction = Direction::Left,
26 .main_size = &size,
27 .min = &size_min,
28 .max = &size_max,
29 });
30
31 auto renderer = Renderer(split, [&] {
32 return window(text("用滑鼠拖曳分隔線"),
33 vbox({
34 text("Min: " + std::to_string(size_min)),
35 text("Max: " + std::to_string(size_max)),
36 text("Size: " + std::to_string(size)),
37 separator(),
38 split->Render() | flex,
39 }));
40 });
41
42 screen.Loop(renderer);
43}
static ScreenInteractive Fullscreen()
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
virtual void Render(Screen &screen)
Element window(Element title, Element content, BorderStyle border=ROUNDED)
繪製帶有標題和邊框的視窗。
Element flex(Element)
使子元素按比例擴展以佔據容器中剩餘的空間。
Definition flex.cpp:140
Element center(Element)
水平與垂直置中一個元素。
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
Component ResizableSplit(ResizableSplitOption options)
兩個元件之間的分隔。