summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Applications/VisualBuilder/VBForm.cpp24
-rw-r--r--Applications/VisualBuilder/VBForm.h2
-rw-r--r--Applications/VisualBuilder/VBWidget.cpp2
3 files changed, 18 insertions, 10 deletions
diff --git a/Applications/VisualBuilder/VBForm.cpp b/Applications/VisualBuilder/VBForm.cpp
index bedcf849a9..8cc53728b0 100644
--- a/Applications/VisualBuilder/VBForm.cpp
+++ b/Applications/VisualBuilder/VBForm.cpp
@@ -36,9 +36,15 @@ VBForm::VBForm(const String& name, GWidget* parent)
m_widgets.append(move(groupbox1));
auto context_menu = make<GMenu>("Context menu");
- context_menu->add_action(GAction::create("Item 1", [] (auto&) { dbgprintf("Item 1 activated!\n"); }));
- context_menu->add_action(GAction::create("Item 2", [] (auto&) { dbgprintf("Item 2 activated!\n"); }));
- set_context_menu(move(context_menu));
+ context_menu->add_action(GAction::create("Move to front", [this] (auto&) {
+ if (m_selected_widget)
+ m_selected_widget->gwidget()->move_to_front();
+ }));
+ context_menu->add_action(GAction::create("Move to back", [this] (auto&) {
+ if (m_selected_widget)
+ m_selected_widget->gwidget()->move_to_back();
+ }));
+ set_context_menu(move(context_menu), GWidget::ContextMenuMode::PassthroughMouseEvent);
}
void VBForm::insert_widget(VBWidgetType type)
@@ -86,12 +92,10 @@ bool VBForm::is_selected(const VBWidget& widget) const
VBWidget* VBForm::widget_at(const Point& position)
{
- for (int i = m_widgets.size() - 1; i >= 0; --i) {
- auto& widget = *m_widgets[i];
- if (widget.rect().contains(position))
- return &widget;
- }
- return nullptr;
+ auto* gwidget = child_at(position);
+ if (!gwidget)
+ return nullptr;
+ return m_gwidget_map.get(gwidget);
}
void VBForm::grabber_mousedown_event(GMouseEvent& event, VBWidget& widget, Direction grabber)
@@ -118,7 +122,7 @@ void VBForm::mousedown_event(GMouseEvent& event)
}
return;
}
- if (event.button() == GMouseButton::Left) {
+ if (event.button() == GMouseButton::Left || event.button() == GMouseButton::Right) {
m_selected_widget = widget->make_weak_ptr();
m_transform_event_origin = event.position();
m_transform_widget_origin_rect = widget->rect();
diff --git a/Applications/VisualBuilder/VBForm.h b/Applications/VisualBuilder/VBForm.h
index 10d858157d..d9cc55df0e 100644
--- a/Applications/VisualBuilder/VBForm.h
+++ b/Applications/VisualBuilder/VBForm.h
@@ -5,6 +5,7 @@
#include "VBWidget.h"
class VBForm : public GWidget {
+ friend class VBWidget;
public:
explicit VBForm(const String& name, GWidget* parent = nullptr);
virtual ~VBForm() override;
@@ -38,6 +39,7 @@ private:
int m_grid_size { 5 };
bool m_should_snap_to_grid { true };
Vector<Retained<VBWidget>> m_widgets;
+ HashMap<GWidget*, VBWidget*> m_gwidget_map;
WeakPtr<VBWidget> m_selected_widget;
Point m_transform_event_origin;
Rect m_transform_widget_origin_rect;
diff --git a/Applications/VisualBuilder/VBWidget.cpp b/Applications/VisualBuilder/VBWidget.cpp
index e77ba3b2bd..af473b6d09 100644
--- a/Applications/VisualBuilder/VBWidget.cpp
+++ b/Applications/VisualBuilder/VBWidget.cpp
@@ -18,10 +18,12 @@ VBWidget::VBWidget(VBWidgetType type, VBForm& form)
, m_property_model(VBWidgetPropertyModel::create(*this))
{
m_gwidget = VBWidgetRegistry::build_gwidget(type, &form, m_properties);
+ m_form.m_gwidget_map.set(m_gwidget, this);
}
VBWidget::~VBWidget()
{
+ m_form.m_gwidget_map.remove(m_gwidget);
}
Rect VBWidget::rect() const