mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
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. :^)
This commit is contained in:
parent
af070324db
commit
c6ffb3e2b8
12 changed files with 94 additions and 87 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue