From 87f12d782e569d03df4f242495c6134e41329748 Mon Sep 17 00:00:00 2001 From: Sven Niederberger <73159570+s-nie@users.noreply.github.com> Date: Sun, 27 Aug 2023 14:28:55 +0200 Subject: [PATCH] Allow setting the progress bar height (#3183) * allow setting the progress bar height * changelog entry * remove the changelog entry --- crates/egui/src/widgets/progress_bar.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/progress_bar.rs b/crates/egui/src/widgets/progress_bar.rs index ef6d16c3..23906959 100644 --- a/crates/egui/src/widgets/progress_bar.rs +++ b/crates/egui/src/widgets/progress_bar.rs @@ -12,6 +12,7 @@ enum ProgressBarText { pub struct ProgressBar { progress: f32, desired_width: Option, + desired_height: Option, text: Option, fill: Option, animate: bool, @@ -23,6 +24,7 @@ impl ProgressBar { Self { progress: progress.clamp(0.0, 1.0), desired_width: None, + desired_height: None, text: None, fill: None, animate: false, @@ -35,6 +37,12 @@ impl ProgressBar { self } + /// The desired height of the bar. Will use the default interaction size if not set. + pub fn desired_height(mut self, desired_height: f32) -> Self { + self.desired_height = Some(desired_height); + self + } + /// The fill color of the bar. pub fn fill(mut self, color: Color32) -> Self { self.fill = Some(color); @@ -67,6 +75,7 @@ impl Widget for ProgressBar { let ProgressBar { progress, desired_width, + desired_height, text, fill, animate, @@ -76,7 +85,7 @@ impl Widget for ProgressBar { let desired_width = desired_width.unwrap_or_else(|| ui.available_size_before_wrap().x.at_least(96.0)); - let height = ui.spacing().interact_size.y; + let height = desired_height.unwrap_or(ui.spacing().interact_size.y); let (outer_rect, response) = ui.allocate_exact_size(vec2(desired_width, height), Sense::hover());