From 7a24a60e729156ca94e3d66f202861a9977d878c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 26 May 2021 22:01:31 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibGUI/Splitter.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Userland/Libraries/LibGUI/Splitter.cpp b/Userland/Libraries/LibGUI/Splitter.cpp index 492ef80a5b..b19712096b 100644 --- a/Userland/Libraries/LibGUI/Splitter.cpp +++ b/Userland/Libraries/LibGUI/Splitter.cpp @@ -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)