FTXUI
0.8.1
C++ functional terminal UI.
|
Go to the documentation of this file.
18 class SliderBase :
public ComponentBase {
20 SliderBase(ConstStringRef label, T* value, T min, T max, T increment)
25 increment_(increment) {}
30 float percent = float(*value_ - min_) / float(max_ - min_);
42 bool OnEvent(Event event)
final {
44 return OnMouseEvent(event);
47 *value_ -= increment_;
48 *value_ = std::max(*value_, min_);
53 *value_ += increment_;
54 *value_ = std::min(*value_, max_);
61 bool OnMouseEvent(Event event) {
63 captured_mouse_ =
nullptr;
67 if (box_.Contain(event.mouse().x, event.mouse().y) &&
CaptureMouse(event)) {
73 gauge_box_.Contain(event.mouse().x, event.mouse().y) &&
78 if (captured_mouse_) {
79 *value_ = min_ + (
event.mouse().x - gauge_box_.x_min) * (max_ - min_) /
80 (gauge_box_.x_max - gauge_box_.x_min);
81 *value_ = std::max(min_, std::min(max_, *value_));
87 bool Focusable() const final {
return true; }
90 ConstStringRef label_;
124 return Make<SliderBase<T>>(std::move(label), value, min, max, increment);
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
std::shared_ptr< ComponentBase > Component
Element vcenter(Element)
Center an element vertically.
Decorator color(Color)
Decorate using a foreground color.
static const Event ArrowLeft
static Event Character(std::string)
Decorator reflect(Box &box)
Element hbox(Elements)
A container displaying elements horizontally one by one.
bool Focused() const
Returns if the elements if focused by the user. True when the ComponentBase is focused by the user....
Element underlined(Element)
Make the underlined element to be underlined.
Element gauge(float ratio)
Draw a high definition progress bar.
Component Slider(ConstStringRef label, T *value, T min, T max, T increment)
An horizontal slider.
CapturedMouse CaptureMouse(const Event &event)
Take the CapturedMouse if available. There is only one component of them. It represents a component t...
std::shared_ptr< Node > Element
std::unique_ptr< CapturedMouseInterface > CapturedMouse
void TakeFocus()
Configure all the ancestors to give focus to this component.
Element dim(Element)
Use a light font, for elements with less emphasis.
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
static const Event ArrowRight
virtual bool OnEvent(Event)
Called in response to an event.
Element text(std::wstring text)
Display a piece of unicode text.