Skip to content

Commit 87f12d7

Browse files
authored
Allow setting the progress bar height (#3183)
* allow setting the progress bar height * changelog entry * remove the changelog entry
1 parent c722b7f commit 87f12d7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/egui/src/widgets/progress_bar.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum ProgressBarText {
1212
pub struct ProgressBar {
1313
progress: f32,
1414
desired_width: Option<f32>,
15+
desired_height: Option<f32>,
1516
text: Option<ProgressBarText>,
1617
fill: Option<Color32>,
1718
animate: bool,
@@ -23,6 +24,7 @@ impl ProgressBar {
2324
Self {
2425
progress: progress.clamp(0.0, 1.0),
2526
desired_width: None,
27+
desired_height: None,
2628
text: None,
2729
fill: None,
2830
animate: false,
@@ -35,6 +37,12 @@ impl ProgressBar {
3537
self
3638
}
3739

40+
/// The desired height of the bar. Will use the default interaction size if not set.
41+
pub fn desired_height(mut self, desired_height: f32) -> Self {
42+
self.desired_height = Some(desired_height);
43+
self
44+
}
45+
3846
/// The fill color of the bar.
3947
pub fn fill(mut self, color: Color32) -> Self {
4048
self.fill = Some(color);
@@ -67,6 +75,7 @@ impl Widget for ProgressBar {
6775
let ProgressBar {
6876
progress,
6977
desired_width,
78+
desired_height,
7079
text,
7180
fill,
7281
animate,
@@ -76,7 +85,7 @@ impl Widget for ProgressBar {
7685

7786
let desired_width =
7887
desired_width.unwrap_or_else(|| ui.available_size_before_wrap().x.at_least(96.0));
79-
let height = ui.spacing().interact_size.y;
88+
let height = desired_height.unwrap_or(ui.spacing().interact_size.y);
8089
let (outer_rect, response) =
8190
ui.allocate_exact_size(vec2(desired_width, height), Sense::hover());
8291

0 commit comments

Comments
 (0)