FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
resizable_split_clamp.cpp
浏览该文件的文档.
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("Drag the separator with the mouse"),
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)
在 ftxui::Screen 上显示元素。
Element flex(Element)
使子元素按比例扩展以填充容器中剩余的空间。
Element center(Element)
水平并垂直居中一个元素。
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
Component ResizableSplit(ResizableSplitOption options)
两个组件之间的分割。
Element window(Element title, Element content, BorderStyle border=ROUNDED)