LibGUI: Paint some knurling in the middle of GUI::Splitter

This makes splitters stand out visually so you can actually spot them.
Before this, you had to guess/know where they were, which was weird.

The look of the knurling is the same as GUI::ResizeCorner, to build on
the established visual language.
This commit is contained in:
Andreas Kling 2021-05-26 22:01:31 +02:00
parent 89272e810a
commit 7a24a60e72
Notes: sideshowbarker 2024-07-18 17:21:19 +09:00

View File

@ -37,8 +37,33 @@ void Splitter::paint_event(PaintEvent& event)
painter.add_clip_rect(event.rect());
auto palette = this->palette();
auto paint_knurl = [&](int x, int y) {
painter.set_pixel(x, y, palette.threed_shadow1());
painter.set_pixel(x + 1, y, palette.threed_shadow1());
painter.set_pixel(x, y + 1, palette.threed_shadow1());
painter.set_pixel(x + 1, y + 1, palette.threed_highlight());
};
constexpr size_t knurl_width = 2;
constexpr size_t knurl_spacing = 1;
constexpr size_t knurl_count = 10;
constexpr size_t total_knurling_width = knurl_count * (knurl_width + knurl_spacing);
if (m_hovered_index.has_value())
painter.fill_rect(m_grabbables[m_hovered_index.value()].paint_rect, palette.hover_highlight());
for (auto& grabbable : m_grabbables) {
for (size_t i = 0; i < knurl_count; ++i) {
auto& rect = grabbable.paint_rect;
int primary = rect.center().primary_offset_for_orientation(m_orientation) - 1;
int secondary = rect.center().secondary_offset_for_orientation(m_orientation) - (total_knurling_width / 2) + (i * (knurl_width + knurl_spacing));
if (m_orientation == Gfx::Orientation::Vertical)
paint_knurl(secondary, primary);
else
paint_knurl(primary, secondary);
}
}
}
void Splitter::resize_event(ResizeEvent& event)