Rust fltk-rs scrollbar increment issue

Scrollbars typically have 2 types of increments using a mouse, a "line" increment and a "block" increment. A line increment is done by clicking on either arrow at the ends of the scrollbar, while a block increment is done by clicking on either side of the slider. I have a scrollbar that I want to represent a range from 0 to 360 (degrees), with a line increment of 1 (degree), and a block increment of 15 (degrees). How do I do this with the fltk toolkit. I have the following sample Rust program:

Screenshot from 2024-09-21 14-19-25

// Testing the fltk scrollbar
// Be sure to have the following line in Cargo.toml after [dependencies]:
// fltk = { version = "1.4.15", features = ["fltk-bundled"] }
use fltk::{prelude::*, window::Window, *};

fn main() {
    let app = app::App::default();
    let mut wind = Window::default()
        .with_size(400, 100)
        .with_label("Scrollbar test");

    let mut col = group::Flex::default_fill().column();
    col.set_pad(0);

    let mut text = frame::Frame::default().with_label("0");

    let mut bar = valuator::Scrollbar::default()
        .with_type(valuator::ScrollbarType::Horizontal);
    bar.set_range(0.0, 360.0);
    bar.set_value(0.0);
    // bar.set_step(<f64>, <i32>);
    col.fixed(&bar, 20);

    col.end();

    wind.end();
    wind.show();

    bar.set_callback({
        move |s| {
            text.set_label(&(s.value().round() as i32).to_string());
            s.parent().unwrap().redraw();
        }
    });

    app.run().unwrap();
}

I tried using different parameters for bar.set_step(...), but could not get line increment to be different than block increment, and there seems to be a built-in default of 16. Is there something else I should try? Desiring to have a line increment of 1, and a block increment of 15. Thanks in advance for any help.

From a quick glance it looks hard coded fltk/src/Fl_Scrollbar.cxx at da20d8397df263db882e914405bb03b9792f4692 · fltk/fltk · GitHub

1 Like

Fl_Scrollbar (fltk-rs Scrollbar) has a linesize setter and getter. It also has a step setter and getter. The linesize change is visible when pushing the widget or the associated arrows, while the step change is visible when dragging the widget’s slider box. OP is asking how pushing the widget can change it by step instead of by linesize.
I’ve posted a question to the FLTK mailing list to see if block increments can be done by step and not linesize, and keep linesize chages solely to pushing the arrows. It would require changing the behavior upstream.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.