FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
modal.cpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. 全著作権所有。
2// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスに従います。
3#include <ftxui/component/event.hpp> // for Event
4#include <ftxui/dom/elements.hpp> // for operator|, Element, center, clear_under, dbox
5#include <memory> // for __shared_ptr_access, shared_ptr
6#include <utility> // for move
7
8#include "ftxui/component/component.hpp" // for Make, Tab, ComponentDecorator, Modal
9#include "ftxui/component/component_base.hpp" // for Component, ComponentBase
10
11namespace ftxui {
12
13// |main| コンポーネントの上に |modal| ウィンドウを追加します。
14// |show_modal| が true の場合、もう一方の上に表示されます。
15/// @ingroup component
16// NOLINTNEXTLINE
17Component Modal(Component main, Component modal, const bool* show_modal) {
18 class Impl : public ComponentBase {
19 public:
20 explicit Impl(Component main, Component modal, const bool* show_modal)
21 : main_(std::move(main)),
22 modal_(std::move(modal)),
23 show_modal_(show_modal) {
24 Add(Container::Tab({main_, modal_}, &selector_));
25 }
26
27 private:
28 Element OnRender() override {
29 selector_ = *show_modal_;
30 auto document = main_->Render();
31 if (*show_modal_) {
32 document = dbox({
33 document,
34 modal_->Render() | clear_under | center,
35 });
36 }
37 return document;
38 }
39
40 bool OnEvent(Event event) override {
41 selector_ = *show_modal_;
42 return ComponentBase::OnEvent(event);
43 }
44
45 Component main_;
46 Component modal_;
47 const bool* show_modal_;
48 int selector_ = *show_modal_;
49 };
50 return Make<Impl>(main, modal, show_modal);
51}
52
53// コンポーネントを装飾します。その上に |modal| ウィンドウを追加します。
54// |show_modal| が true の場合、もう一方の上に表示されます。
55/// @ingroup component
56// NOLINTNEXTLINE
57ComponentDecorator Modal(Component modal, const bool* show_modal) {
58 return [modal, show_modal](Component main) {
59 return Modal(std::move(main), modal, show_modal);
60 };
61}
62
63} // namespace ftxui
ftxui::Elementとして自身のレンダリングを実装します。ftxui::Eventに応答してキーボードナビゲーションを実装します。
Component Modal(Component main, Component modal, const bool *show_modal)
Definition modal.cpp:17
イベントを表します。キープレスイベント、ターミナルのリサイズなど、さまざまなイベントがあります。
Definition event.hpp:28
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
std::shared_ptr< Node > Element
Definition elements.hpp:21
std::shared_ptr< ComponentBase > Component