mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +00:00
VisualBuilder: Use real GWidgets instead of pretend VBWidgets.
That first design was the wrong idea. Instead, have VBWidget instantiate a GWidget of the appropriate type and parent it to the VBForm. We then use a new "greedy hit-testing" mechanism in GWidget to prevent any mouse events from reaching the VBForm's children. To paint the grabbers above the child widgets, I added a slightly hackish but kind of neat second_paint_event() that is called after a widget has painted all of his children. :^)
This commit is contained in:
parent
af070324db
commit
c6ffb3e2b8
12 changed files with 94 additions and 87 deletions
|
@ -115,6 +115,7 @@ void GWidget::handle_paint_event(GPaintEvent& event)
|
|||
child->event(local_event);
|
||||
}
|
||||
}
|
||||
second_paint_event(event);
|
||||
}
|
||||
|
||||
void GWidget::set_layout(OwnPtr<GLayout>&& layout)
|
||||
|
@ -207,6 +208,10 @@ void GWidget::paint_event(GPaintEvent&)
|
|||
{
|
||||
}
|
||||
|
||||
void GWidget::second_paint_event(GPaintEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void GWidget::show_event(GShowEvent&)
|
||||
{
|
||||
}
|
||||
|
@ -282,6 +287,8 @@ Rect GWidget::screen_relative_rect() const
|
|||
|
||||
GWidget::HitTestResult GWidget::hit_test(int x, int y)
|
||||
{
|
||||
if (is_greedy_for_hits())
|
||||
return { this, x, y };
|
||||
for (int i = children().size() - 1; i >= 0; --i) {
|
||||
if (!children()[i]->is_widget())
|
||||
continue;
|
||||
|
|
|
@ -56,6 +56,9 @@ public:
|
|||
virtual void leave_event(CEvent&);
|
||||
virtual void child_event(CChildEvent&) override;
|
||||
|
||||
// This is called after children have been painted.
|
||||
virtual void second_paint_event(GPaintEvent&);
|
||||
|
||||
Rect relative_rect() const { return m_relative_rect; }
|
||||
Point relative_position() const { return m_relative_rect.location(); }
|
||||
|
||||
|
@ -147,6 +150,9 @@ public:
|
|||
|
||||
bool spans_entire_window_horizontally() const;
|
||||
|
||||
bool is_greedy_for_hits() const { return m_greedy_for_hits; }
|
||||
void set_greedy_for_hits(bool b) { m_greedy_for_hits = b; }
|
||||
|
||||
private:
|
||||
virtual bool is_widget() const final { return true; }
|
||||
|
||||
|
@ -173,6 +179,7 @@ private:
|
|||
|
||||
bool m_fill_with_background_color { false };
|
||||
bool m_visible { true };
|
||||
bool m_greedy_for_hits { false };
|
||||
|
||||
CElapsedTimer m_click_clock;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue