summaryrefslogtreecommitdiff
path: root/Applications/VisualBuilder/VBForm.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-11 03:34:37 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-11 03:34:37 +0200
commitc6ffb3e2b87d1a1564cc3e1c4ab840f3ea8c9ec3 (patch)
treeac489b0a31bfff81bb08a43437480944c490f737 /Applications/VisualBuilder/VBForm.cpp
parentaf070324db996f661be80c7bf1f5263991121ee0 (diff)
downloadserenity-c6ffb3e2b87d1a1564cc3e1c4ab840f3ea8c9ec3.zip
VisualBuilder: Use real GWidgets instead of pretend VBWidgets.
That first design was the wrong idea. Instead, have VBWidget instantiate a GWidget of the appropriate type and parent it to the VBForm. We then use a new "greedy hit-testing" mechanism in GWidget to prevent any mouse events from reaching the VBForm's children. To paint the grabbers above the child widgets, I added a slightly hackish but kind of neat second_paint_event() that is called after a widget has painted all of his children. :^)
Diffstat (limited to 'Applications/VisualBuilder/VBForm.cpp')
-rw-r--r--Applications/VisualBuilder/VBForm.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/Applications/VisualBuilder/VBForm.cpp b/Applications/VisualBuilder/VBForm.cpp
index f07e22f278..a0f6e3946f 100644
--- a/Applications/VisualBuilder/VBForm.cpp
+++ b/Applications/VisualBuilder/VBForm.cpp
@@ -1,23 +1,24 @@
#include "VBForm.h"
#include "VBWidget.h"
-#include "VBWidgetFactory.h"
#include <LibGUI/GPainter.h>
VBForm::VBForm(const String& name, GWidget* parent)
: GWidget(parent)
+ , m_name(name)
{
set_fill_with_background_color(true);
set_background_color(Color::LightGray);
+ set_greedy_for_hits(true);
- auto box1 = VBWidget::create(*this);
- box1->set_rect({ 10, 10, 61, 41 });
+ auto box1 = VBWidget::create(WidgetType::GSpinBox, *this);
+ box1->set_rect({ 10, 10, 61, 21 });
m_widgets.append(move(box1));
- auto box2 = VBWidget::create(*this);
+ auto box2 = VBWidget::create(WidgetType::GTextEditor, *this);
box2->set_rect({ 100, 100, 161, 141 });
m_widgets.append(move(box2));
- auto button1 = VBWidgetFactory::create("GButton", *this);
+ auto button1 = VBWidget::create(WidgetType::GButton, *this);
button1->set_rect({ 200, 50, 101, 21 });
m_widgets.append(move(button1));
}
@@ -36,9 +37,14 @@ void VBForm::paint_event(GPaintEvent& event)
painter.set_pixel({ x, y }, Color::Black);
}
}
+}
+
+void VBForm::second_paint_event(GPaintEvent& event)
+{
+ GPainter painter(*this);
+ painter.add_clip_rect(event.rect());
for (auto& widget : m_widgets) {
- widget->paint(painter);
if (widget->is_selected()) {
for_each_direction([&] (Direction direction) {
painter.fill_rect(widget->grabber_rect(direction), Color::Black);