17class ContainerBase :
public ComponentBase {
19 ContainerBase(
Components children,
int* selector)
20 : selector_(selector ? selector : &selected_) {
22 Add(std::move(child));
27 bool OnEvent(Event event)
override {
28 if (event.is_mouse()) {
29 return OnMouseEvent(event);
36 if (ActiveChild() && ActiveChild()->OnEvent(event)) {
40 return EventHandler(event);
52 for (
size_t i = 0; i <
children_.size(); ++i) {
54 *selector_ =
static_cast<int>(i);
62 virtual bool EventHandler(Event ) {
return false; }
64 virtual bool OnMouseEvent(Event event) {
69 int* selector_ =
nullptr;
71 void MoveSelector(
int dir) {
72 for (
int i = *selector_ + dir; i >= 0 && i < int(
children_.size());
81 void MoveSelectorWrap(
int dir) {
85 for (
size_t offset = 1; offset <
children_.size(); ++offset) {
96class VerticalContainer :
public ContainerBase {
98 using ContainerBase::ContainerBase;
104 elements.push_back(it->Render());
106 if (elements.empty()) {
112 bool EventHandler(Event event)
override {
113 const int old_selected = *selector_;
121 for (
int i = 0; i < box_.
y_max - box_.
y_min; ++i) {
126 for (
int i = 0; i < box_.
y_max - box_.
y_min; ++i) {
131 for (
size_t i = 0; i <
children_.size(); ++i) {
136 for (
size_t i = 0; i <
children_.size(); ++i) {
141 MoveSelectorWrap(+1);
144 MoveSelectorWrap(-1);
147 *selector_ = std::max(0, std::min(
int(
children_.size()) - 1, *selector_));
148 return old_selected != *selector_;
151 bool OnMouseEvent(Event event)
override {
152 if (ContainerBase::OnMouseEvent(event)) {
161 if (!box_.
Contain(event.mouse().x, event.mouse().y)) {
165 const int old_selected = *selector_;
172 *selector_ = std::max(0, std::min(
int(
children_.size()) - 1, *selector_));
174 return old_selected != *selector_;
180class HorizontalContainer :
public ContainerBase {
182 using ContainerBase::ContainerBase;
188 elements.push_back(it->Render());
190 if (elements.empty()) {
191 return text(
"Empty container");
193 return hbox(std::move(elements));
196 bool EventHandler(Event event)
override {
197 const int old_selected = *selector_;
205 MoveSelectorWrap(+1);
208 MoveSelectorWrap(-1);
211 *selector_ = std::max(0, std::min(
int(
children_.size()) - 1, *selector_));
212 return old_selected != *selector_;
216class TabContainer :
public ContainerBase {
218 using ContainerBase::ContainerBase;
221 const Component active_child = ActiveChild();
223 return active_child->Render();
225 return text(
"Empty container");
228 bool Focusable()
const override {
235 bool OnMouseEvent(Event event)
override {
236 return ActiveChild() && ActiveChild()->OnEvent(event);
240class StackedContainer :
public ContainerBase {
242 explicit StackedContainer(
Components children)
243 : ContainerBase(std::move(children), nullptr) {}
249 elements.push_back(child->Render());
252 std::reverse(elements.begin(), elements.end());
253 return dbox(std::move(elements));
256 bool Focusable() const final {
258 if (child->Focusable()) {
280 [child](
const Component& c) { return c.get() == child; });
284 std::rotate(
children_.begin(), it, it + 1);
287 bool OnEvent(Event event)
final {
289 if (child->OnEvent(event)) {
315 return Vertical(std::move(children),
nullptr);
338 return std::make_shared<VerticalContainer>(std::move(children), selector);
358 return Horizontal(std::move(children),
nullptr);
381 return std::make_shared<HorizontalContainer>(std::move(children), selector);
404 return std::make_shared<TabContainer>(std::move(children), selector);
431 return std::make_shared<StackedContainer>(std::move(children));
static const Event TabReverse
virtual bool Focusable() const
コンポーネントがフォーカス可能な要素を含んでいる場合にtrueを返します。 フォーカス不可能なコンポーネントは、キーボードでナビゲートする際にスキップされます。
bool Focused() const
要素がユーザーによってフォーカスされているかどうかを返します。 ComponentBaseがユーザーによってフォーカスされている場合にtrueを返します。要素は、そのすべての子孫が親のActiveChi...
static const Event PageUp
void Add(Component children)
子を追加します。 @param child 添付する子。
static const Event ArrowUp
static const Event ArrowDown
virtual bool OnEvent(Event)
イベントに応じて呼び出されます。
static const Event PageDown
static const Event ArrowLeft
static const Event ArrowRight
Component Horizontal(Components children)
コンポーネントのリスト。水平方向に1つずつ描画され、左右の矢印キーまたは'h'/'l'キーを使用して水平方向にナビゲートされます。
Component Vertical(Components children)
コンポーネントのリスト。垂直方向に1つずつ描画され、上下の矢印キーまたは'j'/'k'キーを使用して垂直方向にナビゲートされます。
Component Stacked(Components children)
互いの上にスタックされるコンポーネントのリスト。 イベントは、最初のコンポーネントに伝播され、処理されない場合は2番目のコンポーネントに伝播されます。 コンポーネントは与えられた順序とは逆の順序で描画さ...
Component Tab(Components children, int *selector)
コンポーネントのリスト。一度に1つだけ描画され、操作されます。|selector|は選択されたコンポーネントのインデックスを提供します。これはタブを実装するのに便利です。
Element text(std::wstring text)
ユニコードテキストを表示します。
Element dbox(Elements)
複数の要素を重ねて表示します。
Element vbox(Elements)
要素を縦に一つずつ表示するコンテナ。
bool Contain(int x, int y) const
FTXUIのftxui::Container::名前空間
std::shared_ptr< Node > Element
std::vector< Component > Components
Element hbox(Elements)
要素を水平方向に1つずつ表示するコンテナ。
std::vector< Element > Elements
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component