1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

LibCore+LibGUI: Make CObject child events synchronous.

...and then make GWidget layout invalidation lazy. This way we coalesce
multiple invalidations into a single relayout and we don't have to worry
about child widgets not being fully constructed.
This commit is contained in:
Andreas Kling 2019-04-18 22:57:24 +02:00
parent 0e6b273620
commit 9e6b0ccc0e
4 changed files with 22 additions and 13 deletions

View file

@ -11,7 +11,7 @@
#include <unistd.h>
GWidget::GWidget(GWidget* parent)
: CObject(parent)
: CObject(parent, true)
{
set_font(nullptr);
m_background_color = Color::LightGray;
@ -143,7 +143,7 @@ void GWidget::do_layout()
void GWidget::notify_layout_changed(Badge<GLayout>)
{
do_layout();
invalidate_layout();
}
void GWidget::handle_resize_event(GResizeEvent& event)
@ -395,13 +395,19 @@ void GWidget::set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_
void GWidget::invalidate_layout()
{
auto* w = window();
if (!w)
if (m_layout_dirty)
return;
if (!w->main_widget())
return;
do_layout();
w->main_widget()->do_layout();
m_layout_dirty = true;
deferred_invoke([this] (auto&) {
m_layout_dirty = false;
auto* w = window();
if (!w)
return;
if (!w->main_widget())
return;
do_layout();
w->main_widget()->do_layout();
});
}
void GWidget::set_visible(bool visible)