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

Progress bar #519

Merged
merged 9 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
allow toggling the animation by clicking
  • Loading branch information
EmbersArc committed Jun 27, 2021
commit 49ba4001a3f20dcd441b3e5d46782c75cdb4c5b7
2 changes: 1 addition & 1 deletion egui/src/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Widget for ProgressBar {
let desired_width = desired_width.unwrap_or(ui.available_size_before_wrap().x);
let height = ui.spacing().interact_size.y;
let (outer_rect, response) =
ui.allocate_exact_size(vec2(desired_width, height), Sense::hover());
ui.allocate_exact_size(vec2(desired_width, height), Sense::click());
EmbersArc marked this conversation as resolved.
Show resolved Hide resolved
let visuals = ui.style().visuals.clone();
let corner_radius = outer_rect.height() / 2.0;
ui.painter().rect(
Expand Down
13 changes: 12 additions & 1 deletion egui_demo_lib/src/apps/demo/widget_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct WidgetGallery {
scalar: f32,
string: String,
color: egui::Color32,
animate_progress_bar: bool,
}

impl Default for WidgetGallery {
Expand All @@ -28,6 +29,7 @@ impl Default for WidgetGallery {
scalar: 42.0,
string: Default::default(),
color: egui::Color32::LIGHT_BLUE.linear_multiply(0.5),
animate_progress_bar: false,
}
}
}
Expand Down Expand Up @@ -95,6 +97,7 @@ impl WidgetGallery {
scalar,
string,
color,
animate_progress_bar,
} = self;

ui.add(doc_link_label("Label", "label,heading"));
Expand Down Expand Up @@ -159,7 +162,15 @@ impl WidgetGallery {

ui.add(doc_link_label("ProgressBar", "ProgressBar"));
let progress = *scalar / 360.0;
ui.add(egui::ProgressBar::new(progress).text(format!("{}%", (progress * 100.0) as usize)));
let progress_bar = egui::ProgressBar::new(progress)
.text(format!("{}%", (progress * 100.0) as usize))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something so common that we should have a helper for it, e.g. .show_percentage()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 1d0d86f

.animate(*animate_progress_bar);
let progress_bar_response = ui
.add(progress_bar)
.on_hover_text("Click to enable the animation!");
if progress_bar_response.clicked() {
*animate_progress_bar = !*animate_progress_bar;
}
ui.end_row();

ui.add(doc_link_label("DragValue", "DragValue"));
Expand Down