1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:57:44 +00:00

LibGUI: Paint slider track shorter to ensure the knob covers it

A 1px drop shadow from the track was peeking out behind the knob when
at rightmost or lowest position. That made it look like it was possible
to drag the knob even further right or down. Painting the track 1px
shorter seems like a good compromise to avoid the problem.
This commit is contained in:
Andreas Oppebøen 2023-03-01 21:33:28 +01:00 committed by Andreas Kling
parent 0e4586dd3e
commit c943ab823d

View file

@ -35,14 +35,16 @@ void Slider::paint_event(PaintEvent& event)
Gfx::IntRect track_rect;
// To avoid drop shadow peeking out behind the slider knob, we paint the track slightly shorter
int shadow_thickness = 1;
if (orientation() == Orientation::Horizontal) {
track_rect = { inner_rect().x(), 0, inner_rect().width(), track_size() };
track_rect = { inner_rect().x(), 0, inner_rect().width() - shadow_thickness, track_size() };
track_rect.center_vertically_within(inner_rect());
} else {
track_rect = { 0, inner_rect().y(), track_size(), inner_rect().height() };
track_rect = { 0, inner_rect().y(), track_size(), inner_rect().height() - shadow_thickness };
track_rect.center_horizontally_within(inner_rect());
}
Gfx::StylePainter::paint_frame(painter, track_rect, palette(), Gfx::FrameShape::Panel, Gfx::FrameShadow::Sunken, 1);
Gfx::StylePainter::paint_frame(painter, track_rect, palette(), Gfx::FrameShape::Panel, Gfx::FrameShadow::Sunken, shadow_thickness);
if (is_enabled())
Gfx::StylePainter::paint_button(painter, knob_rect(), palette(), Gfx::ButtonStyle::Normal, false, m_knob_hovered);
else