1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:57:34 +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:
Andreas Kling 2019-04-11 03:34:37 +02:00
parent af070324db
commit c6ffb3e2b8
12 changed files with 94 additions and 87 deletions

View file

@ -6,6 +6,7 @@
#include <AK/Weakable.h>
class GPainter;
class GWidget;
class VBForm;
enum class Direction { None, Left, UpLeft, Up, UpRight, Right, DownRight, Down, DownLeft };
@ -22,27 +23,35 @@ inline void for_each_direction(Callback callback)
callback(Direction::DownLeft);
}
enum class WidgetType {
None,
GWidget,
GButton,
GLabel,
GSpinBox,
GTextEditor,
};
class VBWidget : public Retainable<VBWidget>, public Weakable<VBWidget> {
public:
static Retained<VBWidget> create(VBForm& form) { return adopt(*new VBWidget(form)); }
virtual ~VBWidget();
static Retained<VBWidget> create(WidgetType type, VBForm& form) { return adopt(*new VBWidget(type, form)); }
~VBWidget();
bool is_selected() const;
Rect rect() const { return m_rect; }
void set_rect(const Rect& rect) { m_rect = rect; }
Rect rect() const;
void set_rect(const Rect&);
Rect grabber_rect(Direction) const;
Direction grabber_at(const Point&) const;
virtual void paint(GPainter&);
virtual const char* gwidget_name() const { return "GWidget"; }
GWidget* gwidget() { return m_gwidget; }
protected:
explicit VBWidget(VBForm&);
VBWidget(WidgetType, VBForm&);
private:
WidgetType m_type { WidgetType::None };
VBForm& m_form;
Rect m_rect;
GWidget* m_gwidget { nullptr };
};