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

The kit slider adds a real `egui::Slider`, lets egui paint it, then paints an
opaque rectangle over it and draws the kit's track and thumb on top. That mask
was exactly `slider_width` wide, and egui places its handle so the circle's
right edge lands on `rect.right()` at the maximum, so the fill stopped flush
with the handle and its last column survived as a light sliver beside the
value box. The kit's own thumb cannot hide it either: its radius is
`t.space_8` while egui's handle radius is `input_radius`, about two pixels
larger.

Extend the mask one pixel past its right edge. The gap before the editor is
`item_spacing.x`, so nothing else is covered, and only the maximum was
affected: at the minimum the handle's left edge coincides with the mask's left
edge, which a fill does cover.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
N3MI-DG
2026-10-26 10:42:38 +00:00
committed by GitHub
parent 7ae17e6dd5
commit 9d0b509961
2 changed files with 43 additions and 1 deletions
+4 -1
View File
@@ -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;
+39
View File
@@ -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
);
}