FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
src/ftxui/component/collapsible.cpp
Go to the documentation of this file.
1// Copyright 2021 Arthur Sonzogni. All rights reserved.
2// このソースコードは、LICENSEファイルにあるMITライセンスに基づいて使用されます。
3#include <functional> // for function
4#include <utility> // for move
5
6#include "ftxui/component/component.hpp" // for Checkbox, Maybe, Make, Vertical, Collapsible
7#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
8#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
9#include "ftxui/dom/elements.hpp" // for operator|=, text, hbox, Element, bold, inverted
10#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef
11
12namespace ftxui {
13
14/// @brief 折りたたみ可能なコンポーネント。矢印付きのチェックボックスを表示します。アクティブ化されると、子が
15/// 表示されます。
16/// @param label チェックボックスのラベル。
17/// @param child 表示する子。
18/// @param show 子が表示されているかどうかを示す状態を保持します。
19///
20/// ### 例
21/// ```cpp
22/// auto component = Collapsible("Show details", details);
23/// ```
24///
25/// ### 出力
26/// ```
27///
28/// ▼ Show details
29/// <details component>
30/// ```
31// NOLINTNEXTLINE
33 class Impl : public ComponentBase {
34 public:
35 Impl(ConstStringRef label, Component child, Ref<bool> show) : show_(show) {
37 opt.transform = [](EntryState s) { // NOLINT
38 auto prefix = text(s.state ? "▼ " : "▶ "); // NOLINT
39 auto t = text(s.label);
40 if (s.active) {
41 t |= bold;
42 }
43 if (s.focused) {
44 t |= inverted;
45 }
46 return hbox({prefix, t});
47 };
48 Add(Container::Vertical({
49 Checkbox(std::move(label), show_.operator->(), opt),
50 Maybe(std::move(child), show_.operator->()),
51 }));
52 }
53 Ref<bool> show_;
54 };
55
56 return Make<Impl>(std::move(label), std::move(child), show);
57}
58
59} // namespace ftxui
アダプター。定数文字列を所有または参照します。便宜上、このクラスは複数の不変文字列を共有表現に変換します。
Definition ref.hpp:91
アダプター。可変オブジェクトを所有または参照します。
Definition ref.hpp:45
std::function< Element(const EntryState &)> transform
ftxui::Elementとして自身のレンダリングを実装します。ftxui::Eventに応答してキーボードナビゲーションを実装します。
Checkboxコンポーネントのオプション。
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
折りたたみ可能なコンポーネント。矢印付きのチェックボックスを表示します。アクティブ化されると、子が 表示されます。
std::shared_ptr< ComponentBase > Component
|ButtonOption|、|CheckboxOption|、|RadioboxOption|、|MenuEntryOption|、|MenuOption|からの変換の引数。