18class SliderBase :
public ComponentBase {
20 SliderBase(ConstStringRef label, T* value, T min, T max, T increment)
21 : label_(std::move(label)),
25 increment_(increment) {}
30 float percent = float(*value_ - min_) / float(max_ - min_);
42 bool OnEvent(Event event)
final {
43 if (event.is_mouse()) {
44 return OnMouseEvent(event);
48 *value_ -= increment_;
49 *value_ = std::max(*value_, min_);
54 *value_ += increment_;
55 *value_ = std::min(*value_, max_);
62 bool OnMouseEvent(Event event) {
64 captured_mouse_ =
nullptr;
74 gauge_box_.
Contain(event.mouse().x, event.mouse().y) &&
79 if (captured_mouse_) {
80 *value_ = min_ + (
event.mouse().x - gauge_box_.
x_min) * (max_ - min_) /
82 *value_ = std::max(min_, std::min(max_, *value_));
88 bool Focusable() const final {
return true; }
91 ConstStringRef label_;
bool Focused() const
Returns if the elements if focused by the user. True when the ComponentBase is focused by the user....
CapturedMouse CaptureMouse(const Event &event)
Take the CapturedMouse if available. There is only one component of them. It represents a component t...
void TakeFocus()
Configure all the ancestors to give focus to this component.
virtual bool OnEvent(Event)
Called in response to an event.
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
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.
Decorator reflect(Box &box)
Element dim(Element)
Use a light font, for elements with less emphasis.
Component Slider(ConstStringRef label, T *value, T min, T max, T increment)
An horizontal slider.
Element vcenter(Element)
Center an element vertically.
Element gauge(float progress)
Draw a high definition progress bar.
std::shared_ptr< ComponentBase > Component
Decorator color(Color)
Decorate using a foreground color.
bool Contain(int x, int y) const
static const Event ArrowLeft
static const Event ArrowRight