mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 12:55:08 +00:00
VisualBuilder: Make it possible to insert widgets from the toolbox.
This commit is contained in:
parent
c71ece77fa
commit
75c76f6692
3 changed files with 41 additions and 6 deletions
|
@ -2,10 +2,17 @@
|
||||||
#include "VBWidget.h"
|
#include "VBWidget.h"
|
||||||
#include <LibGUI/GPainter.h>
|
#include <LibGUI/GPainter.h>
|
||||||
|
|
||||||
|
static VBForm* s_current;
|
||||||
|
VBForm* VBForm::current()
|
||||||
|
{
|
||||||
|
return s_current;
|
||||||
|
}
|
||||||
|
|
||||||
VBForm::VBForm(const String& name, GWidget* parent)
|
VBForm::VBForm(const String& name, GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
{
|
{
|
||||||
|
s_current = this;
|
||||||
set_fill_with_background_color(true);
|
set_fill_with_background_color(true);
|
||||||
set_background_color(Color::LightGray);
|
set_background_color(Color::LightGray);
|
||||||
set_greedy_for_hits(true);
|
set_greedy_for_hits(true);
|
||||||
|
@ -23,6 +30,14 @@ VBForm::VBForm(const String& name, GWidget* parent)
|
||||||
m_widgets.append(move(button1));
|
m_widgets.append(move(button1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VBForm::insert_widget(WidgetType type)
|
||||||
|
{
|
||||||
|
auto widget = VBWidget::create(type, *this);
|
||||||
|
widget->set_rect({ m_next_insertion_position, { m_grid_size * 10 + 1, m_grid_size * 5 + 1 } });
|
||||||
|
m_next_insertion_position.move_by(m_grid_size, m_grid_size);
|
||||||
|
m_widgets.append(move(widget));
|
||||||
|
}
|
||||||
|
|
||||||
VBForm::~VBForm()
|
VBForm::~VBForm()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ public:
|
||||||
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
||||||
virtual ~VBForm() override;
|
virtual ~VBForm() override;
|
||||||
|
|
||||||
|
static VBForm* current();
|
||||||
|
|
||||||
String name() const { return m_name; }
|
String name() const { return m_name; }
|
||||||
void set_name(const String& name) { m_name = name; }
|
void set_name(const String& name) { m_name = name; }
|
||||||
|
|
||||||
|
@ -18,6 +20,8 @@ public:
|
||||||
void set_should_snap_to_grip(bool snap) { m_should_snap_to_grid = snap; }
|
void set_should_snap_to_grip(bool snap) { m_should_snap_to_grid = snap; }
|
||||||
bool should_snap_to_grid() const { return m_should_snap_to_grid; }
|
bool should_snap_to_grid() const { return m_should_snap_to_grid; }
|
||||||
|
|
||||||
|
void insert_widget(WidgetType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void second_paint_event(GPaintEvent&) override;
|
virtual void second_paint_event(GPaintEvent&) override;
|
||||||
|
@ -35,5 +39,6 @@ private:
|
||||||
WeakPtr<VBWidget> m_selected_widget;
|
WeakPtr<VBWidget> m_selected_widget;
|
||||||
Point m_transform_event_origin;
|
Point m_transform_event_origin;
|
||||||
Rect m_transform_widget_origin_rect;
|
Rect m_transform_widget_origin_rect;
|
||||||
|
Point m_next_insertion_position;
|
||||||
Direction m_resize_direction { Direction::None };
|
Direction m_resize_direction { Direction::None };
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,14 +2,9 @@
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
#include <LibGUI/GApplication.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GStatusBar.h>
|
|
||||||
#include <LibGUI/GToolBar.h>
|
|
||||||
#include <LibGUI/GMenuBar.h>
|
#include <LibGUI/GMenuBar.h>
|
||||||
#include <LibGUI/GTextEditor.h>
|
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
#include <LibGUI/GFontDatabase.h>
|
#include <LibGUI/GButton.h>
|
||||||
#include <LibCore/CFile.h>
|
|
||||||
#include <AK/StringBuilder.h>
|
|
||||||
#include "VBForm.h"
|
#include "VBForm.h"
|
||||||
#include "VBWidget.h"
|
#include "VBWidget.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -68,6 +63,26 @@ GWindow* make_toolbox_window()
|
||||||
|
|
||||||
auto* widget = new GWidget;
|
auto* widget = new GWidget;
|
||||||
widget->set_fill_with_background_color(true);
|
widget->set_fill_with_background_color(true);
|
||||||
|
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
window->set_main_widget(widget);
|
window->set_main_widget(widget);
|
||||||
|
|
||||||
|
auto* button_button = new GButton(widget);
|
||||||
|
button_button->set_caption("Button");
|
||||||
|
button_button->on_click = [] (GButton&) {
|
||||||
|
if (auto* form = VBForm::current())
|
||||||
|
form->insert_widget(WidgetType::GButton);
|
||||||
|
};
|
||||||
|
auto* spinbox_button = new GButton(widget);
|
||||||
|
spinbox_button->set_caption("SpinBox");
|
||||||
|
spinbox_button->on_click = [] (GButton&) {
|
||||||
|
if (auto* form = VBForm::current())
|
||||||
|
form->insert_widget(WidgetType::GSpinBox);
|
||||||
|
};
|
||||||
|
auto* editor_button = new GButton(widget);
|
||||||
|
editor_button->set_caption("TextEditor");
|
||||||
|
editor_button->on_click = [] (GButton&) {
|
||||||
|
if (auto* form = VBForm::current())
|
||||||
|
form->insert_widget(WidgetType::GTextEditor);
|
||||||
|
};
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue