1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Add clamp_to_range option to DragValue, rename clamp_range to range (deprecating the former) (#4728)

Adds the ability to have `DragValue` not clamp values its presented with
and instead apply clamping only once there's any user input.

In action:


https://github.com/emilk/egui/assets/1220815/af42fd67-86d0-4364-8ae6-48a2ec15646a




Alternative name could be `only_clamp_on_change`, not entirely certain
which one is better 🤔
This commit is contained in:
Andreas Reich
2024-06-28 16:06:59 +02:00
committed by GitHub
parent 3b9f964aed
commit 10f092d9d4
11 changed files with 140 additions and 117 deletions

View File

@@ -43,15 +43,11 @@ impl CodeExample {
r#"
ui.add(
egui::DragValue::new(age)
.clamp_range(0..=120)
.range(0..=120)
.suffix(" years"),
);"#,
);
ui.add(
egui::DragValue::new(age)
.clamp_range(0..=120)
.suffix(" years"),
);
ui.add(egui::DragValue::new(age).range(0..=120).suffix(" years"));
ui.end_row();
show_code(

View File

@@ -95,13 +95,13 @@ impl crate::View for ContextMenus {
egui::Grid::new("button_grid").show(ui, |ui| {
ui.add(
egui::DragValue::new(&mut self.width)
.clamp_range(0.0..=f32::INFINITY)
.range(0.0..=f32::INFINITY)
.speed(1.0)
.prefix("Width: "),
);
ui.add(
egui::DragValue::new(&mut self.height)
.clamp_range(0.0..=f32::INFINITY)
.range(0.0..=f32::INFINITY)
.speed(1.0)
.prefix("Height: "),
);

View File

@@ -174,7 +174,7 @@ impl LineDemo {
ui.add(
egui::DragValue::new(circle_radius)
.speed(0.1)
.clamp_range(0.0..=f64::INFINITY)
.range(0.0..=f64::INFINITY)
.prefix("r: "),
);
ui.horizontal(|ui| {
@@ -353,7 +353,7 @@ impl MarkerDemo {
ui.add(
egui::DragValue::new(&mut self.marker_radius)
.speed(0.1)
.clamp_range(0.0..=f64::INFINITY)
.range(0.0..=f64::INFINITY)
.prefix("Radius: "),
);
ui.checkbox(&mut self.automatic_colors, "Automatic colors");
@@ -432,7 +432,7 @@ impl LegendDemo {
ui.add(
egui::DragValue::new(&mut config.background_alpha)
.speed(0.02)
.clamp_range(0.0..=1.0),
.range(0.0..=1.0),
);
ui.end_row();
});

View File

@@ -87,7 +87,7 @@ impl crate::View for WidgetGallery {
(ui.add(
egui::DragValue::new(&mut self.opacity)
.speed(0.01)
.clamp_range(0.0..=1.0),
.range(0.0..=1.0),
) | ui.label("Opacity"))
.on_hover_text("Reduce this value to make widgets semi-transparent");
}