From a265d40d6e2300cb008f73c627ed43fda1fa17eb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 25 Aug 2020 21:24:45 +0200 Subject: LibGUI: Allow widgets to clip their child widgets This patch adds Widget::children_clip_rect() which can be overridden to tighten clipping of a widget's children. The default implementation simply returns Widget::rect(). --- Libraries/LibGUI/Widget.cpp | 8 +++++++- Libraries/LibGUI/Widget.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Libraries/LibGUI') diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 2719acd92d..52ae9e82e5 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -229,11 +229,12 @@ void Widget::handle_paint_event(PaintEvent& event) painter.fill_rect(event.rect(), palette().color(background_role())); } paint_event(event); + auto children_clip_rect = this->children_clip_rect(); for_each_child_widget([&](auto& child) { if (!child.is_visible()) return IterationDecision::Continue; if (child.relative_rect().intersects(event.rect())) { - PaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position())); + PaintEvent local_event(event.rect().intersected(children_clip_rect).intersected(child.relative_rect()).translated(-child.relative_position())); child.dispatch_event(local_event, this); } return IterationDecision::Continue; @@ -872,4 +873,9 @@ void Widget::show_tooltip() Application::the()->show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2), this); } +Gfx::IntRect Widget::children_clip_rect() const +{ + return rect(); +} + } diff --git a/Libraries/LibGUI/Widget.h b/Libraries/LibGUI/Widget.h index 712c7e789d..c158cea697 100644 --- a/Libraries/LibGUI/Widget.h +++ b/Libraries/LibGUI/Widget.h @@ -274,6 +274,8 @@ public: void set_accepts_emoji_input(bool b) { m_accepts_emoji_input = b; } bool accepts_emoji_input() const { return m_accepts_emoji_input; } + virtual Gfx::IntRect children_clip_rect() const; + protected: Widget(); -- cgit v1.2.3