diff --git a/CHANGELOG.md b/CHANGELOG.md index ca0b4b68..645f25e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `Response::on_hover_and_drag_cursor`. * 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)) ### Changed 🔧 diff --git a/crates/egui/src/widgets/progress_bar.rs b/crates/egui/src/widgets/progress_bar.rs index 7a10dd40..6762a2dd 100644 --- a/crates/egui/src/widgets/progress_bar.rs +++ b/crates/egui/src/widgets/progress_bar.rs @@ -13,6 +13,7 @@ pub struct ProgressBar { progress: f32, desired_width: Option, text: Option, + fill: Option, animate: bool, } @@ -23,6 +24,7 @@ impl ProgressBar { progress: progress.clamp(0.0, 1.0), desired_width: None, text: None, + fill: None, animate: false, } } @@ -33,6 +35,12 @@ impl ProgressBar { 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. pub fn text(mut self, text: impl Into) -> Self { self.text = Some(ProgressBarText::Custom(text.into())); @@ -60,6 +68,7 @@ impl Widget for ProgressBar { progress, desired_width, text, + fill, animate, } = self; @@ -98,7 +107,9 @@ impl Widget for ProgressBar { ui.painter().rect( inner_rect, 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, );