FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
selection_style.cpp
Go to the documentation of this file.
1// Copyright 2024 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されます。
3#include <functional> // for function
4#include <memory> // for make_shared
5#include <utility> // for move
6
7#include "ftxui/dom/elements.hpp" // for Element, Decorator, bgcolor, color
8#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
9#include "ftxui/screen/color.hpp" // for Color
10#include "ftxui/screen/pixel.hpp" // for Pixel
11#include "ftxui/screen/screen.hpp" // for Screen
12
13namespace ftxui {
14
15namespace {
16
17class SelectionStyleReset : public NodeDecorator {
18 public:
19 explicit SelectionStyleReset(Element child)
20 : NodeDecorator(std::move(child)) {}
21
22 void Render(Screen& screen) final {
23 auto old_style = screen.GetSelectionStyle();
24 screen.SetSelectionStyle([](Pixel&) {});
26 screen.SetSelectionStyle(old_style);
27 }
28};
29
30class SelectionStyle : public NodeDecorator {
31 public:
32 SelectionStyle(Element child, const std::function<void(Pixel&)>& style)
33 : NodeDecorator(std::move(child)), style_(style) {}
34
35 void Render(Screen& screen) final {
36 auto old_style = screen.GetSelectionStyle();
37 auto new_style = [&, old_style](Pixel& pixel) {
38 old_style(pixel);
39 style_(pixel);
40 };
41 screen.SetSelectionStyle(new_style);
43 screen.SetSelectionStyle(old_style);
44 }
45
46 std::function<void(Pixel&)> style_;
47};
48
49} // namespace
50
51/// @brief 要素の選択スタイルをリセットします。
52/// @param child 入力要素。
53/// @return 選択スタイルがリセットされた出力要素。
55 return std::make_shared<SelectionStyleReset>(std::move(child));
56}
57
58/// @brief 要素が選択されたときの背景色を設定します。
59/// スタイルは既存のスタイルに重ねて適用されることに注意してください。
61 return selectionStyle([foreground](Pixel& pixel) { //
62 pixel.background_color = foreground;
63 });
64}
65
66/// @brief 要素が選択されたときの描画色を設定します。
67/// スタイルは既存のスタイルに重ねて適用されることに注意してください。
69 return selectionStyle([foreground](Pixel& pixel) { //
70 pixel.foreground_color = foreground;
71 });
72}
73
74/// @brief 要素が選択されたときの色を設定します。
75/// @param foreground 適用する色。
76/// スタイルは既存のスタイルに重ねて適用されることに注意してください。
78 return selectionForegroundColor(foreground);
79}
80
81/// @brief 要素が選択されたときのスタイルを設定します。
82/// @param style 適用するスタイル。
83/// スタイルは既存のスタイルに重ねて適用されることに注意してください。
84// NOLINTNEXTLINE
85Decorator selectionStyle(std::function<void(Pixel&)> style) {
86 return [style](Element child) -> Element {
87 return std::make_shared<SelectionStyle>(std::move(child), style);
88 };
89}
90
91} // namespace ftxui
friend void Render(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:96
void Render(Screen &screen, const Element &element)
要素をftxui::Screenに表示します。
Definition node.cpp:84
Color foreground_color
Definition pixel.hpp:48
Color background_color
Definition pixel.hpp:47
Colorは、ターミナルユーザーインターフェースにおける色を表すクラスです。
Definition color.hpp:25
Unicode文字とそれに関連付けられたスタイル。
Definition pixel.hpp:14
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::function< Element(Element)> Decorator
Definition elements.hpp:23
std::shared_ptr< Node > Element
Definition elements.hpp:21
Decorator selectionStyle(std::function< void(Pixel &)> style)
要素が選択されたときのスタイルを設定します。
Decorator selectionForegroundColor(Color foreground)
要素が選択されたときの描画色を設定します。 スタイルは既存のスタイルに重ねて適用されることに注意してください。
Decorator selectionBackgroundColor(Color foreground)
要素が選択されたときの背景色を設定します。 スタイルは既存のスタイルに重ねて適用されることに注意してください。
Decorator selectionColor(Color foreground)
要素が選択されたときの色を設定します。
Element selectionStyleReset(Element)
要素の選択スタイルをリセットします。
std::function< void(Pixel &)> style_