Skip to content

チートシート ​

日々の FTXUI 開発で参照できる1ページ早見表です。

ヘッダ ​

cpp
#include <ftxui/screen/screen.hpp>       // Screen, Surface, Cell, Color, Box
#include <ftxui/dom/elements.hpp>        // hbox, vbox, text, border, flex, ...
#include <ftxui/dom/table.hpp>           // Table
#include <ftxui/dom/canvas.hpp>          // Canvas
#include <ftxui/component/component.hpp> // Button, Input, Menu, Container, ...
#include <ftxui/component/app.hpp>       // App
#include <ftxui/component/loop.hpp>      // Loop (manual event loop)

レイアウト要素 (ftxui/dom) ​

要素用途
hbox({...}) / vbox({...})水平 / 垂直ボックス
dbox({...})重ね合わせレイヤー(深度ボックス。clear_under と併用)
flexbox({...}, config)CSS 風の折り返しレイアウト(省略形として hflow, vflow)
gridbox({ {...}, {...} })2次元グリッド配置
filler() / emptyElement()伸縮する空白 / 0×0 要素
separator()水平または垂直の区切り線(separatorLight, Double, Heavy, Dashed)
window(title, content)タイトルバー付きの枠線ボックス

デコレータ(左から | で連結) ​

cpp
auto el = text("Hello")
          | bold
          | color(Color::Cyan)
          | bgcolor(Color::Black)
          | borderRounded
          | center
          | flex;
カテゴリデコレータ
テキストスタイルbold, dim, italic, inverted, underlined, underlinedDouble, blink, strikethrough
色color(Color::Red), bgcolor(Color::Blue), color(LinearGradient(...))
枠線border, borderLight, borderHeavy, borderDouble, borderRounded, borderDashed, borderEmpty, borderStyled(...)
伸縮・サイズflex, flex_grow, flex_shrink, xflex, yflex, notflex, size(WIDTH, EQUAL, 20)(LESS_THAN, GREATER_THAN)
配置center, hcenter, vcenter, align_right
スクロールframe, xframe, yframe, vscroll_indicator, hscroll_indicator, focus, focusPositionRelative(x, y)
ユーティリティclear_under, reflect(box), automerge, hyperlink(url)

インタラクティブコンポーネント (ftxui/component) ​

コンポーネント代表的な使い方
Buttonauto btn =Button("Click", [&] { ... });
Inputauto in =Input(&str, "placeholder");
Checkboxauto cb =Checkbox("Enable", &flag);
Menuauto m =Menu(&entries, &selected);
Radioboxauto rb =Radiobox(&entries, &selected);
Dropdownauto dd =Dropdown(&entries, &selected);
Toggleauto tg =Toggle(&entries, &selected);
Sliderauto sl =Slider("Volume:", &val, 0, 100, 5);
Collapsibleauto col = Collapsible("Details", child);
Modalauto ui = main |Modal(dialog, &show);
Windowauto win =Window({.inner = child, .title = "Title"});
ResizableSplitResizableSplitLeft(left, right, &size)(Right, Top, Bottom)
ContainerContainer::Vertical({...}), Horizontal, Tab({...}, &idx), Stacked
RendererRenderer(container, [&] { returnvbox({...}); })
CatchEventcomp |CatchEvent([&](Event e) { return false; })
Maybecomp |Maybe(&visible)
Hoverablecomp |Hoverable(&hovered)

よく使うイベント (ftxui::Event) ​

キー / 操作イベント
印字可能文字Event::Character('q'), event.is_character(), event.character()
矢印キーEvent::ArrowUp, ArrowDown, ArrowLeft, ArrowRight(*Ctrl, *Alt)
ナビゲーションEvent::Tab, TabReverse, Home, End, PageUp, PageDown
編集Event::Return, Escape, Backspace, Delete, Insert
制御・ファンクションEvent::CtrlC, CtrlD, CtrlA..CtrlZ, AltA..AltZ, F1..F12
マウスevent.is_mouse(), event.mouse().button(Mouse::Left, WheelUp, WheelDown), event.mouse().motion(Pressed, Released, Moved), x, y

App ライフサイクル ​

cpp
auto app = App::Fullscreen();      // or TerminalOutput(), FitComponent(), FixedSize(w, h)
app.Loop(root_component);          // Blocking main loop
app.Exit();                        // Exit loop (or app.ExitLoopClosure())
app.Post([&] { /* state */ });     // Thread-safe callback on main loop thread
app.RequestAnimationFrame();       // Schedule a redraw
app.PrintAbove(element);           // Permanent scrollback output (TerminalOutput mode)
app.WithRestoredIO([&] { ... });   // Suspend raw mode to run external CLI/editor