mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:48:11 +00:00
LibCore+LibGUI: Allow inserting a CObject/GWidget before another
When adding a widget to a parent, you don't always want to append it to the set of existing children, but instead insert it before one of them. This patch makes that possible by adding CObject::insert_child_before() which also produces a ChildAdded event with an additional before_child pointer. This pointer is then used by GWidget to make sure that any layout present maintains the correct order. (Without doing that, newly added children would still be appended into the layout order, despite having a different widget sibling order.)
This commit is contained in:
parent
0f81eaf8a2
commit
d3558b6137
7 changed files with 36 additions and 4 deletions
|
@ -27,8 +27,12 @@ GWidget::~GWidget()
|
|||
void GWidget::child_event(CChildEvent& event)
|
||||
{
|
||||
if (event.type() == GEvent::ChildAdded) {
|
||||
if (event.child() && is<GWidget>(*event.child()) && layout())
|
||||
layout()->add_widget(to<GWidget>(*event.child()));
|
||||
if (event.child() && is<GWidget>(*event.child()) && layout()) {
|
||||
if (event.insertion_before_child() && event.insertion_before_child()->is_widget())
|
||||
layout()->insert_widget_before(to<GWidget>(*event.child()), to<GWidget>(*event.insertion_before_child()));
|
||||
else
|
||||
layout()->add_widget(to<GWidget>(*event.child()));
|
||||
}
|
||||
}
|
||||
if (event.type() == GEvent::ChildRemoved) {
|
||||
if (layout()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue