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 adaptateur. Possède ou référence un objet immuable.
Un adaptateur. Possède ou référence un objet mutable.
#define FTXUI_EXPORT(component)
Element text(std::string_view text)
Affiche un morceau de texte unicode encodé en UTF8.
Element xflex(Element)
Développer/Réduire si possible/nécessaire sur l'axe X.
Element gaugeDirection(float progress, Direction direction)
Dessine une barre de progression haute définition progressant dans la direction spécifiée.
Element yflex(Element)
Développer/Réduire si possible/nécessaire sur l'axe Y.
Element underlined(Element child)
Souligne l'élément donné.
Direction
Direction est une énumération qui représente les quatre directions cardinales.
Element focus(Element child)
Définit l'élément child comme étant celui qui est focalisé parmi ses frères.
Element vcenter(Element child)
Centre un élément verticalement.
Element color(Color color, Element child)
Définit la couleur de premier plan d'un élément.
L'espace de noms FTXUI ftxui::
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements children)
Un conteneur affichant les éléments horizontalement un par un.
std::function< Element(Element)> Decorator
Component Slider(SliderOption< T > options)
Un curseur dans n'importe quelle direction.
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component