FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/focus.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
3#include <memory> // for allocator, shared_ptr, __shared_ptr_access
4#include <string> // for operator+, char_traits, to_string, string
5#include <vector> // for vector
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Slider, Renderer, Vertical
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for Elements, Element, operator|, separator, text, focusPositionRelative, size, border, flex, frame, bgcolor, gridbox, vbox, EQUAL, center, HEIGHT, WIDTH
12#include "ftxui/screen/color.hpp" // for Color
13
14using namespace ftxui;
15
16Element make_box(int x, int y) {
17 std::string title = "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
18 return text(title) | center | size(WIDTH, EQUAL, 18) |
19 size(HEIGHT, EQUAL, 9) | border |
20 bgcolor(Color::HSV(x * 255 / 15, 255, y * 255 / 15));
21};
22
24 std::vector<Elements> rows;
25 for (int i = 0; i < 15; i++) {
26 std::vector<Element> cols;
27 for (int j = 0; j < 15; j++) {
28 cols.push_back(make_box(i, j));
29 }
30 rows.push_back(cols);
31 }
32
33 return gridbox(rows);
34};
35
36int main() {
37 float focus_x = 0.5f;
38 float focus_y = 0.5f;
39
40 auto slider_x = Slider("x", &focus_x, 0.f, 1.f, 0.01f);
41 auto slider_y = Slider("y", &focus_y, 0.f, 1.f, 0.01f);
42
43 auto renderer = Renderer(
44 Container::Vertical({
45 slider_x,
46 slider_y,
47 }),
48 [&] {
49 auto title = "focusPositionRelative(" + //
50 std::to_string(focus_x) + ", " + //
51 std::to_string(focus_y) + ")"; //
52 return vbox({
53 text(title),
54 separator(),
55 slider_x->Render(),
56 slider_y->Render(),
57 separator(),
58 make_grid() | focusPositionRelative(focus_x, focus_y) |
59 frame | flex,
60 }) |
61 border;
62 });
63
64 auto screen = ScreenInteractive::Fullscreen();
65 screen.Loop(renderer);
66
67 return 0;
68}
Element make_grid()
Element make_box(int x, int y)
static ScreenInteractive Fullscreen()
Component Renderer(Component child, std::function< Element()>)
|child|に似ていますが、|render|をComponentRender()イベントとして使用する新しいコンポーネントを返します。
virtual void Render(Screen &screen)
要素をftxui::Screenに表示します。
Definition node.cpp:59
Decorator bgcolor(Color)
背景色を使用して装飾します。
Decorator focusPositionRelative(float x, float y)
frame内で使用され、ビューを特定の位置にスクロールさせます。位置は要求されたサイズの割合で表されます。
Element flex(Element)
子要素をコンテナに残されたスペースに比例して拡大させます。
Definition flex.cpp:120
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
Definition vbox.cpp:94
static Color HSV(uint8_t hue, uint8_t saturation, uint8_t value)
HSV表現から色を構築します。 https://en.wikipedia.org/wiki/HSL_and_HSV.
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< Node > Element
Definition elements.hpp:21
Component Slider(SliderOption< T > options)
どの方向にも対応するスライダー。
Element gridbox(std::vector< Elements > lines)
要素のグリッドを表示するコンテナ。
Element separator()
return size
Definition string.cpp:1516