Valuators
Valuator widgets implement the ValuatorExt trait. These keep track (graphically and internally) of numerical values along with steps, ranges and bounds. Such valuators which you might be familiar with are scrollbars and sliders. The list offered by fltk is found in the valuator module:
- Slider
- NiceSlider
- ValueSlider
- Dial
- LineDial
- Counter
- Scrollbar
- Roller
- Adjuster
- ValueInput
- ValueOutput
- FillSlider
- FillDial
- HorSlider (Horizontal slider)
- HorFillSlider
- HorNiceSlider
- HorValueSlider
Changing the valuator's value in the gui triggers its callback. The current value of the valuator can be queried using the value() method. It can also be set using set_value(). The ranges and step can also be queried and changed to your use case:
use fltk::{prelude::*, *}; fn main() { let a = app::App::default(); let mut win = window::Window::default().with_size(400, 300); let mut slider = valuator::HorNiceSlider::default().with_size(400, 20).center_of_parent(); slider.set_minimum(0.); slider.set_maximum(100.); slider.set_step(1., 1); // increment by 1.0 at each 1 step slider.set_value(50.); // start in the middle win.end(); win.show(); slider.set_callback(|s| { println!("slider at {}", s.value()); }); a.run().unwrap(); }
Below you can see the same example using different valuator widgets.
Valuator widgets examples
Adjuster widget
Counter widget
Dial widget
FillDial widget
FillSlider widget
HorFillSlider widget
HorNiceSlider widget
HorSlider widget
HorValueSlider widget
LineDial widget
NiceSlider widget
Roller widget
Scrollbar widget
Slider widget
ValueInput widget
ValueOutput widget
ValueSlider widget
Valuator enums
Some valuators offer different types which can be set using the set_type
method (or with_type
builder function). The value passed is an enum value of <Widget>Type
usually.
In the following example, we instantiate a Counter, then set its type to a Simple counter.
#![allow(unused)] fn main() { let mut counter = valuator::Counter::default().with_size(200, 50).center_of_parent(); counter.set_type(fltk::valuator::CounterType::Simple); }
Check below for more types associated with different valuator widgets.