diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-17 21:00:11 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-17 22:17:28 +0200 |
commit | 9acdf9bb0a75b3ecba1cdadd784df09f40276c07 (patch) | |
tree | b9c874d729c21270f57fa959a596d7c52ae3f708 /DevTools/VisualBuilder/VBWidget.cpp | |
parent | ce44d9a32f4ad714d87e8680bad149b2807b9fae (diff) | |
download | serenity-9acdf9bb0a75b3ecba1cdadd784df09f40276c07.zip |
VisualBuilder: Support nested widgets
This patch makes it possible to put widgets inside one another. The way
you do this right now is by having a (single) widget selected when you
insert a new widget. The new widget then becomes a child of the
selected widget. (In the future we'll make it possible to drag widgets
into each other, and things like that.)
I've also changed the grabber coordinates to be window-relative instead
of parent-relative in order to simplify things for myself. Maybe that's
not the ideal design and we can revisit that.
Diffstat (limited to 'DevTools/VisualBuilder/VBWidget.cpp')
-rw-r--r-- | DevTools/VisualBuilder/VBWidget.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/DevTools/VisualBuilder/VBWidget.cpp b/DevTools/VisualBuilder/VBWidget.cpp index a3de2ac241..2450d7e5a7 100644 --- a/DevTools/VisualBuilder/VBWidget.cpp +++ b/DevTools/VisualBuilder/VBWidget.cpp @@ -15,12 +15,13 @@ #include <LibGUI/GSpinBox.h> #include <LibGUI/GTextEditor.h> -VBWidget::VBWidget(VBWidgetType type, VBForm& form) +VBWidget::VBWidget(VBWidgetType type, VBForm& form, VBWidget* parent) : m_type(type) , m_form(form) , m_property_model(VBWidgetPropertyModel::create(*this)) { - m_gwidget = VBWidgetRegistry::build_gwidget(*this, type, &form, m_properties); + auto* widget_parent = parent ? parent->gwidget() : &form; + m_gwidget = VBWidgetRegistry::build_gwidget(*this, type, widget_parent, m_properties); m_form.m_gwidget_map.set(m_gwidget, this); setup_properties(); } @@ -34,14 +35,17 @@ VBWidget::~VBWidget() Rect VBWidget::rect() const { - return m_gwidget->relative_rect(); + return m_gwidget->window_relative_rect(); } void VBWidget::set_rect(const Rect& rect) { - if (rect == m_gwidget->relative_rect()) + if (rect == m_gwidget->window_relative_rect()) return; - m_gwidget->set_relative_rect(rect); + auto new_window_relative_rect = rect; + if (m_gwidget->parent()) + new_window_relative_rect.move_by(-m_gwidget->parent_widget()->window_relative_rect().location()); + m_gwidget->set_relative_rect(new_window_relative_rect); synchronize_properties(); } |