51class SliderBase :
public SliderOption<T>,
public ComponentBase {
53 explicit SliderBase(SliderOption<T> options) : SliderOption<T>(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();
95 this->value() = std::max(this->min(), std::min(this->max(), this->value()));
96 if (old_value != this->value()) {
97 if (this->on_change) {
106 bool OnCapturedMouseEvent(Event event) {
108 captured_mouse_ =
nullptr;
112 T old_value = this->value();
113 switch (this->direction) {
115 this->value() = this->min() + (
event.mouse().x - gauge_box_.x_min) *
116 (this->max() - this->min()) /
117 (gauge_box_.x_max - gauge_box_.x_min);
122 this->value() = this->max() - (
event.mouse().x - gauge_box_.x_min) *
123 (this->max() - this->min()) /
124 (gauge_box_.x_max - gauge_box_.x_min);
128 this->value() = this->min() + (
event.mouse().y - gauge_box_.y_min) *
129 (this->max() - this->min()) /
130 (gauge_box_.y_max - gauge_box_.y_min);
134 this->value() = this->max() - (
event.mouse().y - gauge_box_.y_min) *
135 (this->max() - this->min()) /
136 (gauge_box_.y_max - gauge_box_.y_min);
141 this->value() = std::max(this->min(), std::min(this->max(), this->value()));
143 if (old_value != this->value() && this->on_change) {
149 bool OnMouseEvent(Event event) {
150 if (captured_mouse_) {
151 return OnCapturedMouseEvent(event);
161 if (!gauge_box_.Contain(event.mouse().x, event.mouse().y)) {
165 captured_mouse_ = CaptureMouse(event);
167 if (captured_mouse_) {
169 return OnCapturedMouseEvent(event);
175 bool Focusable() const final {
return true; }
182class SliderWithLabel :
public ComponentBase {
184 SliderWithLabel(ConstStringRef label,
Component inner)
185 : label_(std::move(label)) {
186 Add(std::move(inner));
187 SetActiveChild(ChildAt(0));
191 bool OnEvent(Event event)
final {
196 if (!event.is_mouse()) {
200 mouse_hover_ = box_.Contain(event.mouse().x, event.mouse().y);
206 if (!CaptureMouse(event)) {
216 auto element =
hbox({
224 gauge_color | xflex |
reflect(box_);
230 ConstStringRef label_;
232 bool mouse_hover_ =
false;
265 option.
value = value;
269 auto slider = Make<SliderBase<int>>(option);
279 option.
value = value;
283 auto slider = Make<SliderBase<float>>(option);
292 option.
value = value;
296 auto slider = Make<SliderBase<long>>(option);
317 return Make<SliderBase<T>>(options);
Un adaptador. Posee o referencia un objeto inmutable.
Un adaptador. Posee o referencia una cadena constante. Para mayor comodidad, esta clase convierte múl...
Un adaptador. Posee o referencia un objeto mutable.
Element Render()
Dibuja el componente. Construye un ftxui::Element para ser dibujado en la ftxui::Screen representando...
static const Event ArrowUp
static const Event ArrowDown
virtual bool OnEvent(Event)
Llamado en respuesta a un evento.
static const Event ArrowLeft
static const Event ArrowRight
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.
Direction
Direction es una enumeración que representa las cuatro cardinales direcciones.
Element yflex(Element)
Expandir/Minimizar si es posible/necesario en el eje Y.
Element underlined(Element)
Subraya el elemento dado.
Element text(std::wstring text)
Muestra un fragmento de texto Unicode.
Element focus(Element)
Establece que child sea el elemento enfocado entre sus hermanos.
Element vcenter(Element)
Centra un elemento verticalmente.
Decorator color(Color)
Decora usando un color de primer plano.
El espacio de nombres ftxui:: de FTXUI.
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)
Un contenedor que muestra elementos horizontalmente uno por uno.
Component Slider(SliderOption< T > options)
Un deslizador en cualquier dirección.
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component