39class SliderBase :
public ComponentBase {
50 :
color(options_.color_inactive);
58 switch (options_.direction) {
60 value_() -= increment_();
63 value_() += increment_();
72 switch (options_.direction) {
74 value_() += increment_();
77 value_() -= increment_();
86 switch (options_.direction) {
88 value_() -= increment_();
91 value_() += increment_();
100 switch (options_.direction) {
102 value_() -= increment_();
105 value_() += increment_();
113 bool OnEvent(Event
event)
final {
114 if (
event.is_mouse()) {
115 return OnMouseEvent(
event);
140 bool OnMouseEvent(Event
event) {
141 if (captured_mouse_) {
143 captured_mouse_ =
nullptr;
147 switch (options_.direction) {
149 value_() = min_() + (
event.mouse().x - gauge_box_.x_min) *
151 (gauge_box_.x_max - gauge_box_.x_min);
155 value_() = max_() - (
event.mouse().x - gauge_box_.x_min) *
157 (gauge_box_.x_max - gauge_box_.x_min);
161 value_() = min_() + (
event.mouse().y - gauge_box_.y_min) *
163 (gauge_box_.y_max - gauge_box_.y_min);
167 value_() = max_() - (
event.mouse().y - gauge_box_.y_min) *
169 (gauge_box_.y_max - gauge_box_.y_min);
173 value_() = std::max(min_(), std::min(max_(), value_()));
182 if (!gauge_box_.Contain(
event.mouse().x,
event.mouse().y)) {
186 captured_mouse_ = CaptureMouse(
event);
188 if (captured_mouse_) {
208class SliderWithLabel :
public ComponentBase {
210 SliderWithLabel(ConstStringRef label,
Component inner)
212 Add(std::move(inner));
213 SetActiveChild(ChildAt(0));
217 bool OnEvent(Event
event)
final {
222 if (!
event.is_mouse()) {
226 mouse_hover_ = box_.Contain(
event.mouse().x,
event.mouse().y);
232 if (!CaptureMouse(
event)) {
254 ConstStringRef label_;
256 bool mouse_hover_ =
false;
291 option.increment = increment;
305 option.increment = increment;
318 option.increment = increment;
virtual Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::C...
virtual bool OnEvent(Event)
Called in response to an event.
An adapter. Own or reference an immutable object.
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
An adapter. Own or reference an mutable object.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
std::function< Element(Element)> Decorator
Element nothing(Element element)
A decoration doing absolutely nothing.
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Element hbox(Elements)
A container displaying elements horizontally one by one.
Element underlined(Element)
Make the underlined element to be underlined.
Element text(std::wstring text)
Display a piece of unicode text.
Element select(Element)
Set the child to be the one selected among its siblings.
Element focus(Element)
Set the child to be the one in focus globally.
Component Slider(SliderOption< T > options)
A slider in any direction.
Decorator reflect(Box &box)
Element dim(Element)
Use a light font, for elements with less emphasis.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element vcenter(Element)
Center an element vertically.
Decorator color(Color)
Decorate using a foreground color.
static const Event ArrowUp
static const Event ArrowDown
static const Event ArrowLeft
static const Event ArrowRight