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

Add trailing_fill() toggle to Slider #2660

Merged
merged 4 commits into from
Feb 5, 2023
Merged

Conversation

hinto-janai
Copy link
Contributor

Adds a boolean toggle to Slider that enables trailing color behind the circle. The color used is the same as a ProgressBar, it is sourced from ui.visuals().selection.bg_fill.

Usage:

ui.add(Slider::new(&mut my_slider_value, 0.0..=100.0));                      // No-color (default)
ui.add(Slider::new(&mut my_slider_value, 0.0..=100.0).trailing_color(true)); // Trailing color

Before:
before

After:
after

Vertical & Horizontal:
orientation

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice feature!

But I wonder if we can come up with a better name for it. trailing_fill?

I also think the option belong in egui::Visuals instead of (or addition to) having it for every slider. Presumably a user would want to turn this on for all sliders, or none of them?

CHANGELOG.md Outdated Show resolved Hide resolved
crates/egui/src/widgets/slider.rs Outdated Show resolved Hide resolved
@hinto-janai hinto-janai changed the title Add trailing_color() toggle to Slider Add trailing_fill() toggle to Slider Feb 4, 2023
@hinto-janai
Copy link
Contributor Author

Suggestions added. The option is now in egui::Visuals with a per Slider override:

ui.add(Slider::new(&mut my_slider_value, 0.0..=100.0));                      // No fill (default)
ui.add(Slider::new(&mut my_slider_value, 0.0..=100.0).trailing_fill(true));  // Fill (override)

ui.visuals_mut().slider_trailing_fill = true;

ui.add(Slider::new(&mut my_slider_value, 0.0..=100.0));                      // Fill (global)
ui.add(Slider::new(&mut my_slider_value, 0.0..=100.0).trailing_fill(false)); // No fill (override)

The ui.painter() code was copied from the code that was already there, so I changed its style as well.

crates/egui/src/style.rs Outdated Show resolved Hide resolved
@emilk emilk merged commit 628c84c into emilk:master Feb 5, 2023
@emilk
Copy link
Owner

emilk commented Feb 5, 2023

thanks!

lictex pushed a commit to lictex/egui that referenced this pull request Feb 5, 2023
* slider: add trailing_color toggle

* slider/visuals: add global option in visuals with override toggle

* slider: add to demos

* use `.unwrap_or_else()` instead of match
@hinto-janai hinto-janai deleted the trailing-slider branch February 7, 2023 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants