linebender / linebender/druid

GTK double click handling causes Stepper to skip values.

Open
#1,029 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug shell/gtk
Dominant language
Rust
Stars
9.7k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

The Stepper, despite being (currently, see #762 ) exclusively for floats, does not seem to implement clamping against rounding errors.

Given the following compilable example (with warnings):

```rs
use druid::{AppLauncher, WindowDesc, Widget, PlatformError, LensWrap, Lens, Data, LensExt};
use druid::widget::{
Padding, Stepper, Switch, WidgetExt, Flex, Label, TextBox, Parse
};
fn main() {
AppLauncher::with_window(WindowDesc::new(build_ui)).launch(State {
n_value: 20.0
});
}
fn build_ui() -> impl Widget {
let mut row = Flex::row();
let n_textbox = LensWrap::new(
Parse::new(TextBox::new()),
State::n_value.map(|x| Some(*x), |x, y| *x = y.unwrap_or(0.0)),
);
let stepper = LensWrap::new(
Stepper::new()
.with_range(0.0, u32::MAX.into())
.with_step(1.0)
.with_wraparound(false),
State::n_value,
);
row.add_child(Padding::new(5.0, n_textbox));
row.add_child(Padding::new(5.0, stepper));
row.center()
}

#[derive(Lens, Data, Clone)]
struct State {
n_value: f64,
}
```

Use the buttons to go up and down a few times, and you'll note that some values will end up being skipped.

As a note, I'm building off of 0.6.0, and would state that building off of master is something that should be discouraged (so if this is fixed in master, I request this not be closed until the release is pushed onto crates.io)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the skipped values with the compilable Rust example in the issue, then inspect the Stepper implementation and its handling of floating-point ranges, steps, and button events. Done means repeated upward and downward clicks no longer skip values within the configured range; add or run a regression test if the existing test structure supports it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.