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();
}

HorNiceSlider

Below you can see the same example using different valuator widgets.

Valuator widgets examples

Adjuster widget

Adjuster

Counter widget

Counter

Dial widget

Dial

FillDial widget

FillDial

FillSlider widget

FillSlider

HorFillSlider widget

HorFillSlider

HorNiceSlider widget

HorNiceSlider

HorSlider widget

HorSlider

HorValueSlider widget

HorValueSlider

LineDial widget

LineDial

NiceSlider widget

NiceSlider

Roller widget

Roller

Scrollbar widget

Scrollbar

Slider widget

Slider

ValueInput widget

ValueInput

ValueOutput widget

ValueOutput

ValueSlider widget

ValueSlider


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.

Valuator type enums examples

CounterType::Normal

CounterTypeNormal

CounterType::Simple

CounterTypeSimple


DialType::Normal

DialTypeNormal

DialType::Line

DialTypeLine

DialType::Fill

DialTypeFill


ScrollbarType::Vertical

ScrollbarTypeVertical

ScrollbarType::Horizontal

ScrollbarTypeHorizontal

ScrollbarType::VerticalFill

ScrollbarTypeVerticalFill

ScrollbarType::HorizontalFill

ScrollbarTypeHorizontalFill

ScrollbarType::VerticalNice

ScrollbarTypeVerticalNice

ScrollbarType::HorizontalNice

ScrollbarTypeHorizontalNice


SliderType::Vertical

SliderTypeVertical

SliderType::VerticalFill

SliderTypeVerticalFill

SliderType::HorizontalFill

SliderTypeHorizontalFill

SliderType::VerticalNice

SliderTypeVerticalNice

SliderType::HorizontalNice

SliderTypeHorizontalNice