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// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <functional> // for function
5#include <utility> // for move
6
7#include "ftxui/component/component.hpp" // for Checkbox, Maybe, Make, Vertical, Collapsible
8#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
9#include "ftxui/component/component_options.hpp" // for CheckboxOption, EntryState
10#include "ftxui/dom/elements.hpp" // for operator|=, text, hbox, Element, bold, inverted
11#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef
12
13namespace ftxui {
14
15/// @brief 可折疊元件。它顯示一個帶有箭頭的核取方塊。一旦啟用,子元件就會顯示。
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:92
一個適配器。擁有或引用一個可變的物件。
Definition ref.hpp:46
std::function< Element(const EntryState &)> transform
它將自己實作為 ftxui::Element 進行渲染。它透過回應 ftxui::Event 來實現鍵盤導航。
核取方塊元件的選項。
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
return Make< Impl >(option)
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
可折疊元件。它顯示一個帶有箭頭的核取方塊。一旦啟用,子元件就會顯示。
std::shared_ptr< ComponentBase > Component
來自 |ButtonOption|、|CheckboxOption|、 |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的轉換參數。