50class SliderBase :
public SliderOption<T>,
public ComponentBase {
52 explicit SliderBase(SliderOption<T> options)
53 : SliderOption<T>(std::move(options)) {}
57 Focused() ?
color(this->color_active) : color(this->color_inactive);
59 float(this->
value() - this->min()) / float(this->max() - this->min());
61 flexDirection(this->direction) |
reflect(gauge_box_) | gauge_color;
65 if (pressed == this->direction) {
66 this->
value() += this->increment();
70 if (pressed == Opposite(this->direction)) {
71 this->
value() -= this->increment();
76 bool OnEvent(Event event)
final {
77 if (event.is_mouse()) {
78 return OnMouseEvent(event);
81 T old_value = this->
value();
82 if (event == Event::ArrowLeft || event == Event::Character(
'h')) {
85 if (event == Event::ArrowRight || event == Event::Character(
'l')) {
88 if (event == Event::ArrowUp || event == Event::Character(
'k')) {
91 if (event == Event::ArrowDown || event == Event::Character(
'j')) {
95 this->
value() = std::max(this->min(), std::min(this->max(), this->
value()));
96 if (old_value != this->
value()) {
97 App::PostEventOrExecute(this->on_change);
101 return ComponentBase::OnEvent(event);
104 bool OnCapturedMouseEvent(Event event) {
105 if (event.mouse().motion == Mouse::Released) {
106 captured_mouse_ =
nullptr;
110 T old_value = this->
value();
111 switch (this->direction) {
113 this->
value() = this->min() + (
event.mouse().x - gauge_box_.x_min) *
114 (this->max() - this->min()) /
115 (gauge_box_.x_max - gauge_box_.x_min);
120 this->
value() = this->max() - (
event.mouse().x - gauge_box_.x_min) *
121 (this->max() - this->min()) /
122 (gauge_box_.x_max - gauge_box_.x_min);
126 this->
value() = this->min() + (
event.mouse().
y - gauge_box_.y_min) *
127 (this->max() - this->min()) /
128 (gauge_box_.y_max - gauge_box_.y_min);
132 this->
value() = this->max() - (
event.mouse().
y - gauge_box_.y_min) *
133 (this->max() - this->min()) /
134 (gauge_box_.y_max - gauge_box_.y_min);
139 this->
value() = std::max(this->min(), std::min(this->max(), this->
value()));
141 if (old_value != this->
value()) {
142 App::PostEventOrExecute(this->on_change);
147 bool OnMouseEvent(Event event) {
148 if (captured_mouse_) {
149 return OnCapturedMouseEvent(event);
152 if (event.mouse().button != Mouse::Left) {
155 if (event.mouse().motion != Mouse::Pressed) {
159 if (!gauge_box_.Contain(event.mouse().x, event.mouse().y)) {
163 captured_mouse_ = CaptureMouse(event);
165 if (captured_mouse_) {
167 return OnCapturedMouseEvent(event);
173 bool Focusable() const final {
return true; }
180class SliderWithLabel :
public ComponentBase {
182 SliderWithLabel(ConstStringRef label,
Component inner)
183 : label_(std::move(label)) {
184 Add(std::move(inner));
185 SetActiveChild(ChildAt(0));
189 bool OnEvent(Event event)
final {
190 if (ComponentBase::OnEvent(event)) {
194 if (!event.is_mouse()) {
198 mouse_hover_ = box_.Contain(event.mouse().x, event.mouse().y);
204 if (!CaptureMouse(event)) {
212 auto gauge_color = (Focused() || mouse_hover_) ?
color(Color::White)
213 :
color(Color::GrayDark);
223 gauge_color | xflex |
reflect(box_);
229 ConstStringRef label_;
231 bool mouse_hover_ =
false;
268 auto slider = Make<SliderBase<int>>(option);
282 auto slider = Make<SliderBase<float>>(option);
295 auto slider = Make<SliderBase<long>>(option);
316 return Make<SliderBase<T>>(std::move(options));
アダプター。不変オブジェクトを所有または参照します。
アダプター。可変オブジェクトを所有または参照します。
#define FTXUI_EXPORT(component)
Element text(std::string_view text)
UTF8エンコードされたユニコードテキストを表示します。
Element xflex(Element)
必要に応じてX軸上で拡大・縮小します。
Element gaugeDirection(float progress, Direction direction)
指定された方向に進行する高精細プログレスバーを描画します。
Element yflex(Element)
必要に応じてY軸上で拡大・縮小します。
Element underlined(Element child)
指定された要素に下線を追加します。
Direction
Directionは、東西南北の4つの基本方向を表す列挙型です。
Element focus(Element child)
子要素を兄弟要素の中でフォーカスされたものとして設定します。
Element vcenter(Element child)
要素を垂直方向に中央揃えします。
Element color(Color color, Element child)
要素の前景色を設定します。
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements children)
要素を水平方向に1つずつ表示するコンテナ。
std::function< Element(Element)> Decorator
Component Slider(SliderOption< T > options)
任意の方向のスライダー。
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component