Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DragValue range clamping #5118

Merged
merged 1 commit into from
Sep 17, 2024
Merged

Fix DragValue range clamping #5118

merged 1 commit into from
Sep 17, 2024

Conversation

emilk
Copy link
Owner

@emilk emilk commented Sep 17, 2024

When using a DragValue, there are three common modes of range clamping that the user may want:

A) no clamping
B) clamping only user input (dragging or editing text), but leave existing value intact
C) always clamp

The difference between mode B and C is:

let mut x = 42.0;
ui.add(DragValue::new(&mut x).range(0.0..=1.0));
// What will `x` be here?

With this PR, we now can get the three behaviors with:

  • A): don't call .range() (or use -Inf..=Inf)
  • B) call .range() and .clamp_existing_to_range(false)
  • C) call .range()

Slider clamping

Slider clamping is slightly different, since a slider always has a range.

For a slider, there are these three cases to consider:

A) no clamping
B) clamp any value that the user enters, but leave existing values intact
C) always clamp all values

Out of this, C should probably be the default.

I'm not sure what the best API is for this yet. Maybe an enum 🤔

I'll take a pass on that in a future PR.

Related

@emilk emilk marked this pull request as draft September 17, 2024 10:40
@emilk emilk added bug Something is broken feature New feature or request egui labels Sep 17, 2024
@emilk emilk force-pushed the emilk/fix-clamp-value branch from 304525e to 728ad87 Compare September 17, 2024 10:48
@emilk emilk changed the title Replace .clamp_to_range with .clamp_existing_to_range Fix DragValue range clamping Sep 17, 2024
@emilk emilk marked this pull request as ready for review September 17, 2024 10:50
@emilk emilk merged commit 7d6c83b into master Sep 17, 2024
39 checks passed
@emilk emilk deleted the emilk/fix-clamp-value branch September 17, 2024 12:44
@emilk emilk restored the emilk/fix-clamp-value branch September 17, 2024 13:04
emilk added a commit that referenced this pull request Sep 17, 2024
This deprecates `.clamp_to_range` in favor of more control using
`.clamping`.

## Related
* #4728
* Closes #4881
* #4882
* #5118
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
When using a `DragValue`, there are three common modes of range clamping
that the user may want:

A) no clamping
B) clamping only user input (dragging or editing text), but leave
existing value intact
C) always clamp

The difference between mode B and C is:

```rs
let mut x = 42.0;
ui.add(DragValue::new(&mut x).range(0.0..=1.0));
// What will `x` be here?
```

With this PR, we now can get the three behaviors with:

* A): don't call `.range()` (or use `-Inf..=Inf`)
* B) call `.range()` and `.clamp_existing_to_range(false)`
* C) call `.range()`

## Slider clamping
Slider clamping is slightly different, since a slider always has a
range.

For a slider, there are these three cases to consider:

A) no clamping
B) clamp any value that the user enters, but leave existing values
intact
C) always clamp all values

Out of this, C should probably be the default.

I'm not sure what the best API is for this yet. Maybe an `enum` 🤔 


I'll take a pass on that in a future PR.

## Related
* emilk#4728
* emilk#4881
* emilk#4882
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
This deprecates `.clamp_to_range` in favor of more control using
`.clamping`.

## Related
* emilk#4728
* Closes emilk#4881
* emilk#4882
* emilk#5118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant