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

Allow setting the progress bar height #3183

Merged
merged 4 commits into from
Aug 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/egui/src/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum ProgressBarText {
pub struct ProgressBar {
progress: f32,
desired_width: Option<f32>,
desired_height: Option<f32>,
text: Option<ProgressBarText>,
fill: Option<Color32>,
animate: bool,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -67,6 +75,7 @@ impl Widget for ProgressBar {
let ProgressBar {
progress,
desired_width,
desired_height,
text,
fill,
animate,
Expand All @@ -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());

Expand Down
Loading