mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 07:35:08 +00:00
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.
This commit is contained in:
parent
ce44d9a32f
commit
9acdf9bb0a
3 changed files with 23 additions and 13 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue