Allow changing ProgressBar fill color (#2618)
This commit is contained in:
parent
d4f9f6984d
commit
518b4f447e
2 changed files with 13 additions and 1 deletions
|
@ -13,6 +13,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
|
||||||
* Add `ScrollArea::drag_to_scroll` if you want to turn off that feature.
|
* Add `ScrollArea::drag_to_scroll` if you want to turn off that feature.
|
||||||
* Add `Response::on_hover_and_drag_cursor`.
|
* Add `Response::on_hover_and_drag_cursor`.
|
||||||
* Add `Window::default_open` ([#2539](https://github.com/emilk/egui/pull/2539))
|
* Add `Window::default_open` ([#2539](https://github.com/emilk/egui/pull/2539))
|
||||||
|
* Add `ProgressBar::fill` if you want to set the fill color manually. ([#2618](https://github.com/emilk/egui/pull/2618))
|
||||||
* Add `Button::rounding` to enable round buttons ([#2539](https://github.com/emilk/egui/pull/2539))
|
* Add `Button::rounding` to enable round buttons ([#2539](https://github.com/emilk/egui/pull/2539))
|
||||||
|
|
||||||
### Changed 🔧
|
### Changed 🔧
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub struct ProgressBar {
|
||||||
progress: f32,
|
progress: f32,
|
||||||
desired_width: Option<f32>,
|
desired_width: Option<f32>,
|
||||||
text: Option<ProgressBarText>,
|
text: Option<ProgressBarText>,
|
||||||
|
fill: Option<Color32>,
|
||||||
animate: bool,
|
animate: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ impl ProgressBar {
|
||||||
progress: progress.clamp(0.0, 1.0),
|
progress: progress.clamp(0.0, 1.0),
|
||||||
desired_width: None,
|
desired_width: None,
|
||||||
text: None,
|
text: None,
|
||||||
|
fill: None,
|
||||||
animate: false,
|
animate: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +35,12 @@ impl ProgressBar {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The fill color of the bar.
|
||||||
|
pub fn fill(mut self, color: Color32) -> Self {
|
||||||
|
self.fill = Some(color);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// A custom text to display on the progress bar.
|
/// A custom text to display on the progress bar.
|
||||||
pub fn text(mut self, text: impl Into<WidgetText>) -> Self {
|
pub fn text(mut self, text: impl Into<WidgetText>) -> Self {
|
||||||
self.text = Some(ProgressBarText::Custom(text.into()));
|
self.text = Some(ProgressBarText::Custom(text.into()));
|
||||||
|
@ -60,6 +68,7 @@ impl Widget for ProgressBar {
|
||||||
progress,
|
progress,
|
||||||
desired_width,
|
desired_width,
|
||||||
text,
|
text,
|
||||||
|
fill,
|
||||||
animate,
|
animate,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -98,7 +107,9 @@ impl Widget for ProgressBar {
|
||||||
ui.painter().rect(
|
ui.painter().rect(
|
||||||
inner_rect,
|
inner_rect,
|
||||||
rounding,
|
rounding,
|
||||||
Color32::from(Rgba::from(visuals.selection.bg_fill) * color_factor as f32),
|
Color32::from(
|
||||||
|
Rgba::from(fill.unwrap_or(visuals.selection.bg_fill)) * color_factor as f32,
|
||||||
|
),
|
||||||
Stroke::NONE,
|
Stroke::NONE,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue