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));
Un adaptador. Posee o referencia un objeto inmutable.
Un adaptador. Posee o referencia un objeto mutable.
#define FTXUI_EXPORT(component)
Element text(std::string_view text)
Muestra un fragmento de texto Unicode codificado en UTF8.
Element xflex(Element)
Expandir/Minimizar si es posible/necesario en el eje X.
Element gaugeDirection(float progress, Direction direction)
Dibuja una barra de progreso de alta definición que avanza en la dirección especificada.
Element yflex(Element)
Expandir/Minimizar si es posible/necesario en el eje Y.
Element underlined(Element child)
Subraya el elemento dado.
Direction
Direction es una enumeración que representa las cuatro cardinales direcciones.
Element focus(Element child)
Establece que child sea el elemento enfocado entre sus hermanos.
Element vcenter(Element child)
Centra un elemento verticalmente.
Element color(Color color, Element child)
Establece el color de primer plano de un elemento.
El espacio de nombres ftxui:: de FTXUI.
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements children)
Un contenedor que muestra elementos horizontalmente uno por uno.
std::function< Element(Element)> Decorator
Component Slider(SliderOption< T > options)
Un control deslizante en cualquier dirección.
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component