mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
LibGUI: Introduce widget content margins + improve splitters
A GUI::Widget can now set an optional content margin (4x0 by default.) Pixels in the content margin will be ignored for hit testing purposes. Use this to allow frame-like widgets (like GUI::Frame!) to ignore any mouse events in the frame area, and instead let those go to parent. This allows GUI::Splitter to react "sooner" to mouse events that were previously swallowed by the child widgets instead of ending up in the splitter. The net effect is that 2 more pixels on each side of a splitter handle are now interactive and usable for splitting! :^)
This commit is contained in:
parent
9badcff1ba
commit
42f0b2522b
6 changed files with 57 additions and 17 deletions
|
@ -472,7 +472,7 @@ Widget* Widget::child_at(const Gfx::Point& point) const
|
|||
auto& child = Core::to<Widget>(children()[i]);
|
||||
if (!child.is_visible())
|
||||
continue;
|
||||
if (child.relative_rect().contains(point))
|
||||
if (child.content_rect().contains(point))
|
||||
return const_cast<Widget*>(&child);
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -811,4 +811,21 @@ void Widget::did_end_inspection()
|
|||
update();
|
||||
}
|
||||
|
||||
void Widget::set_content_margins(const Margins& margins)
|
||||
{
|
||||
if (m_content_margins == margins)
|
||||
return;
|
||||
m_content_margins = margins;
|
||||
invalidate_layout();
|
||||
}
|
||||
|
||||
Gfx::Rect Widget::content_rect() const
|
||||
{
|
||||
auto rect = relative_rect();
|
||||
rect.move_by(m_content_margins.left(), m_content_margins.top());
|
||||
rect.set_width(rect.width() - (m_content_margins.left() + m_content_margins.right()));
|
||||
rect.set_height(rect.height() - (m_content_margins.top() + m_content_margins.bottom()));
|
||||
return rect;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue