Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

ui_kit slider: cover egui's own handle at the top of the range (#5708) (#5712)

N3MI-DG9d0b5099612a
diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rs
index 3560349458..286e225b8f 100644
--- a/crates/ui-egui/src/ui_kit/fields.rs
+++ b/crates/ui-egui/src/ui_kit/fields.rs
@@ -483,7 +483,10 @@ pub(crate) fn slider<T: egui::emath::Numeric>(ui: &mut Ui, value: &mut T, range:
let slider = egui::Rect::from_min_size(response.rect.min, vec2(ui.spacing().slider_width, response.rect.height()));
let mut background = ui.painter().clone();
background.set_opacity(if ui.is_visible() { 1.0 } else { 0.0 });
- background.rect_filled(slider, 0.0, t.dialog_body);
+ // At the top of the range egui's own handle reaches `slider.right()` exactly, and a fill
+ // that stops there leaves its last column showing beside the editor (#5708). The gap
+ // before the editor is `item_spacing.x`, so a pixel past the edge covers nothing else.
+ background.rect_filled(slider.with_max_x(slider.right() + 1.0), 0.0, t.dialog_body);
// Match egui's native input range (handle_radius = thickness / 2.5), so the
// painted thumb stays under the pointer even at the two ends of the range.
let input_radius = ui.text_style_height(&egui::TextStyle::Body).max(ui.spacing().interact_size.y) / 2.5;
diff --git a/crates/ui-egui/src/ui_kit/slider_tests.rs b/crates/ui-egui/src/ui_kit/slider_tests.rs
index e01be89c94..b1ad106abc 100644
--- a/crates/ui-egui/src/ui_kit/slider_tests.rs
+++ b/crates/ui-egui/src/ui_kit/slider_tests.rs
@@ -153,3 +153,42 @@ fn a_sliders_value_box_takes_typed_numbers_and_clamps_them_to_its_range() {
assert!((value - expected).abs() < 1e-3, "typed {typed}: {value}");
}
}
+
+/// At the top of its range egui's own handle reaches the right edge of the rectangle the kit
+/// paints over it, so the mask has to pass that edge; flush with it, the handle's last column
+/// survives as a light sliver beside the value box (#5708).
+#[test]
+fn the_mask_passes_the_edge_of_egui_s_own_handle_at_the_top_of_the_range() {
+ let ctx = crate::fonts::test_context();
+ let t = Tokens::get();
+ let mut value: f64 = 2.0;
+ let mut output =
+ ctx.run_ui(egui::RawInput { screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(400.0, 200.0))), ..Default::default() }, |ui| {
+ scope(ui, |ui| {
+ slider(ui, &mut value, 0.0..=2.0, Slider { step: Some(0.05), ..Default::default() });
+ });
+ });
+ output.textures_delta.clear();
+ let handle = output
+ .shapes
+ .iter()
+ .find_map(|s| match &s.shape {
+ egui::Shape::Circle(c) if c.stroke.color != t.form_primary => Some(*c),
+ _ => None,
+ })
+ .expect("egui's own slider handle");
+ let mask = output
+ .shapes
+ .iter()
+ .find_map(|s| match &s.shape {
+ egui::Shape::Rect(r) if r.fill == t.dialog_body => Some(r.rect),
+ _ => None,
+ })
+ .expect("the rectangle the kit paints over egui's slider");
+ assert!(
+ mask.right() > handle.center.x + handle.radius,
+ "the mask ends at {} and egui's handle at {}: its last column would show",
+ mask.right(),
+ handle.center.x + handle.radius
+ );
+}