50class SliderBase :
public SliderOption<T>,
public ComponentBase {
52 explicit SliderBase(SliderOption<T> options) : SliderOption<T>(options) {}
56 Focused() ?
color(this->color_active) : color(this->color_inactive);
58 float(this->value() - this->min()) / float(this->max() - this->min());
60 flexDirection(this->direction) |
reflect(gauge_box_) | gauge_color;
64 if (pressed == this->direction) {
65 this->value() += this->increment();
69 if (pressed == Opposite(this->direction)) {
70 this->value() -= this->increment();
75 bool OnEvent(Event event)
final {
76 if (event.is_mouse()) {
77 return OnMouseEvent(event);
80 T old_value = this->value();
94 this->value() = std::max(this->min(), std::min(this->max(), this->value()));
95 if (old_value != this->value()) {
96 if (this->on_change) {
105 bool OnCapturedMouseEvent(Event event) {
107 captured_mouse_ =
nullptr;
111 T old_value = this->value();
112 switch (this->direction) {
114 this->value() = this->min() + (
event.mouse().x - gauge_box_.x_min) *
115 (this->max() - this->min()) /
116 (gauge_box_.x_max - gauge_box_.x_min);
121 this->value() = this->max() - (
event.mouse().x - gauge_box_.x_min) *
122 (this->max() - this->min()) /
123 (gauge_box_.x_max - gauge_box_.x_min);
127 this->value() = this->min() + (
event.mouse().y - gauge_box_.y_min) *
128 (this->max() - this->min()) /
129 (gauge_box_.y_max - gauge_box_.y_min);
133 this->value() = this->max() - (
event.mouse().y - gauge_box_.y_min) *
134 (this->max() - this->min()) /
135 (gauge_box_.y_max - gauge_box_.y_min);
140 this->value() = std::max(this->min(), std::min(this->max(), this->value()));
142 if (old_value != this->value() && this->on_change) {
148 bool OnMouseEvent(Event event) {
149 if (captured_mouse_) {
150 return OnCapturedMouseEvent(event);
160 if (!gauge_box_.Contain(event.mouse().x, event.mouse().y)) {
164 captured_mouse_ = CaptureMouse(event);
166 if (captured_mouse_) {
168 return OnCapturedMouseEvent(event);
174 bool Focusable() const final {
return true; }
181class SliderWithLabel :
public ComponentBase {
183 SliderWithLabel(ConstStringRef label,
Component inner)
184 : label_(std::move(label)) {
185 Add(std::move(inner));
186 SetActiveChild(ChildAt(0));
190 bool OnEvent(Event event)
final {
195 if (!event.is_mouse()) {
199 mouse_hover_ = box_.Contain(event.mouse().x, event.mouse().y);
205 if (!CaptureMouse(event)) {
215 auto element =
hbox({
223 gauge_color | xflex |
reflect(box_);
229 ConstStringRef label_;
231 bool mouse_hover_ =
false;
264 option.
value = value;
268 auto slider = Make<SliderBase<int>>(option);
278 option.
value = value;
282 auto slider = Make<SliderBase<float>>(option);
291 option.
value = value;
295 auto slider = Make<SliderBase<long>>(option);
316 return Make<SliderBase<T>>(options);
アダプター。不変オブジェクトを所有または参照します。
アダプター。定数文字列を所有または参照します。便宜上、このクラスは複数の不変文字列を共有表現に変換します。
アダプター。可変オブジェクトを所有または参照します。
Element Render()
コンポーネントを描画します。 このftxui::ComponentBaseを表すftxui::Screen上に描画されるftxui::Elementを構築します。レンダリングを変更するにはOnRende...
static const Event ArrowUp
static const Event ArrowDown
virtual bool OnEvent(Event)
イベントに応じて呼び出されます。
static const Event ArrowLeft
static const Event ArrowRight
Element xflex(Element)
必要に応じてX軸上で拡大・縮小します。
Element gaugeDirection(float progress, Direction direction)
指定された方向に進行する高精細プログレスバーを描画します。
Direction
Directionは、東西南北の4つの基本方向を表す列挙型です。
Element yflex(Element)
必要に応じてY軸上で拡大・縮小します。
Element underlined(Element)
指定された要素に下線を追加します。
Element text(std::wstring text)
ユニコードテキストを表示します。
Element focus(Element)
子要素を兄弟要素の中でフォーカスされたものとして設定します。
Element vcenter(Element)
要素を垂直方向に中央揃えします。
Decorator color(Color)
前景色を使用して装飾します。
std::function< Element(Element)> Decorator
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements)
要素を水平方向に1つずつ表示するコンテナ。
Component Slider(SliderOption< T > options)
どの方向にも対応するスライダー。
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component