summaryrefslogtreecommitdiff
path: root/DevTools/VisualBuilder
diff options
context:
space:
mode:
Diffstat (limited to 'DevTools/VisualBuilder')
-rw-r--r--DevTools/VisualBuilder/VBForm.cpp44
-rw-r--r--DevTools/VisualBuilder/VBPropertiesWindow.cpp2
-rw-r--r--DevTools/VisualBuilder/VBWidget.cpp13
-rw-r--r--DevTools/VisualBuilder/VBWidgetPropertyModel.cpp25
-rw-r--r--DevTools/VisualBuilder/VBWidgetRegistry.cpp42
-rw-r--r--DevTools/VisualBuilder/main.cpp54
6 files changed, 99 insertions, 81 deletions
diff --git a/DevTools/VisualBuilder/VBForm.cpp b/DevTools/VisualBuilder/VBForm.cpp
index aac6e8f122..9472b1b631 100644
--- a/DevTools/VisualBuilder/VBForm.cpp
+++ b/DevTools/VisualBuilder/VBForm.cpp
@@ -1,11 +1,11 @@
#include "VBForm.h"
-#include "VBWidget.h"
#include "VBProperty.h"
-#include <LibGUI/GPainter.h>
-#include <LibGUI/GMenu.h>
+#include "VBWidget.h"
+#include <LibCore/CFile.h>
#include <LibGUI/GAction.h>
+#include <LibGUI/GMenu.h>
#include <LibGUI/GMessageBox.h>
-#include <LibCore/CFile.h>
+#include <LibGUI/GPainter.h>
static VBForm* s_current;
VBForm* VBForm::current()
@@ -39,15 +39,15 @@ VBForm::VBForm(const String& name, GWidget* parent)
m_widgets.append(move(groupbox1));
m_context_menu = make<GMenu>("Context menu");
- m_context_menu->add_action(GAction::create("Move to front", [this] (auto&) {
+ m_context_menu->add_action(GAction::create("Move to front", [this](auto&) {
if (auto* widget = single_selected_widget())
widget->gwidget()->move_to_front();
}));
- m_context_menu->add_action(GAction::create("Move to back", [this] (auto&) {
+ m_context_menu->add_action(GAction::create("Move to back", [this](auto&) {
if (auto* widget = single_selected_widget())
widget->gwidget()->move_to_back();
}));
- m_context_menu->add_action(GAction::create("Delete", [this] (auto&) {
+ m_context_menu->add_action(GAction::create("Delete", [this](auto&) {
delete_selected_widgets();
}));
}
@@ -88,7 +88,7 @@ void VBForm::second_paint_event(GPaintEvent& event)
for (auto& widget : m_widgets) {
if (widget->is_selected()) {
- for_each_direction([&] (Direction direction) {
+ for_each_direction([&](Direction direction) {
painter.fill_rect(widget->grabber_rect(direction), Color::Black);
});
}
@@ -112,7 +112,7 @@ VBWidget* VBForm::widget_at(const Point& position)
void VBForm::grabber_mousedown_event(GMouseEvent& event, Direction grabber)
{
m_transform_event_origin = event.position();
- for_each_selected_widget([] (auto& widget) { widget.capture_transform_origin_rect(); });
+ for_each_selected_widget([](auto& widget) { widget.capture_transform_origin_rect(); });
m_resize_direction = grabber;
}
@@ -146,19 +146,19 @@ void VBForm::keydown_event(GKeyEvent& event)
switch (event.key()) {
case KeyCode::Key_Up:
update();
- for_each_selected_widget([this] (auto& widget) { widget.gwidget()->move_by(0, -m_grid_size); });
+ for_each_selected_widget([this](auto& widget) { widget.gwidget()->move_by(0, -m_grid_size); });
break;
case KeyCode::Key_Down:
update();
- for_each_selected_widget([this] (auto& widget) { widget.gwidget()->move_by(0, m_grid_size); });
+ for_each_selected_widget([this](auto& widget) { widget.gwidget()->move_by(0, m_grid_size); });
break;
case KeyCode::Key_Left:
update();
- for_each_selected_widget([this] (auto& widget) { widget.gwidget()->move_by(-m_grid_size, 0); });
+ for_each_selected_widget([this](auto& widget) { widget.gwidget()->move_by(-m_grid_size, 0); });
break;
case KeyCode::Key_Right:
update();
- for_each_selected_widget([this] (auto& widget) { widget.gwidget()->move_by(m_grid_size, 0); });
+ for_each_selected_widget([this](auto& widget) { widget.gwidget()->move_by(m_grid_size, 0); });
break;
}
return;
@@ -197,7 +197,7 @@ void VBForm::mousedown_event(GMouseEvent& event)
{
if (m_resize_direction == Direction::None) {
bool hit_grabber = false;
- for_each_selected_widget([&] (auto& widget) {
+ for_each_selected_widget([&](auto& widget) {
auto grabber = widget.grabber_at(event.position());
if (grabber != Direction::None) {
hit_grabber = true;
@@ -220,7 +220,7 @@ void VBForm::mousedown_event(GMouseEvent& event)
add_to_selection(*widget);
else if (!m_selected_widgets.contains(widget))
set_single_selected_widget(widget);
- for_each_selected_widget([] (auto& widget) { widget.capture_transform_origin_rect(); });
+ for_each_selected_widget([](auto& widget) { widget.capture_transform_origin_rect(); });
on_widget_selected(single_selected_widget());
}
}
@@ -231,7 +231,7 @@ void VBForm::mousemove_event(GMouseEvent& event)
if (m_resize_direction == Direction::None) {
update();
auto delta = event.position() - m_transform_event_origin;
- for_each_selected_widget([&] (auto& widget) {
+ for_each_selected_widget([&](auto& widget) {
auto new_rect = widget.transform_origin_rect().translated(delta);
new_rect.set_x(new_rect.x() - (new_rect.x() % m_grid_size));
new_rect.set_y(new_rect.y() - (new_rect.y() % m_grid_size));
@@ -287,7 +287,7 @@ void VBForm::mousemove_event(GMouseEvent& event)
}
update();
- for_each_selected_widget([&] (auto& widget) {
+ for_each_selected_widget([&](auto& widget) {
auto new_rect = widget.transform_origin_rect();
Size minimum_size { 5, 5 };
new_rect.set_x(new_rect.x() + change_x);
@@ -316,7 +316,7 @@ void VBForm::write_to_file(const String& path)
int i = 0;
for (auto& widget : m_widgets) {
file.printf("[Widget %d]\n", i++);
- widget->for_each_property([&] (auto& property) {
+ widget->for_each_property([&](auto& property) {
file.printf("%s=%s\n", property.name().characters(), property.value().to_string().characters());
});
file.printf("\n");
@@ -331,7 +331,7 @@ void VBForm::dump()
int i = 0;
for (auto& widget : m_widgets) {
dbgprintf("[Widget %d]\n", i++);
- widget->for_each_property([] (auto& property) {
+ widget->for_each_property([](auto& property) {
dbgprintf("%s=%s\n", property.name().characters(), property.value().to_string().characters());
});
dbgprintf("\n");
@@ -341,7 +341,7 @@ void VBForm::dump()
void VBForm::mouseup_event(GMouseEvent& event)
{
if (event.button() == GMouseButton::Left) {
- m_transform_event_origin = { };
+ m_transform_event_origin = {};
m_resize_direction = Direction::None;
}
}
@@ -349,11 +349,11 @@ void VBForm::mouseup_event(GMouseEvent& event)
void VBForm::delete_selected_widgets()
{
Vector<VBWidget*> to_delete;
- for_each_selected_widget([&] (auto& widget) {
+ for_each_selected_widget([&](auto& widget) {
to_delete.append(&widget);
});
for (auto& widget : to_delete)
- m_widgets.remove_first_matching([&widget] (auto& entry) { return entry == widget; } );
+ m_widgets.remove_first_matching([&widget](auto& entry) { return entry == widget; });
on_widget_selected(single_selected_widget());
}
diff --git a/DevTools/VisualBuilder/VBPropertiesWindow.cpp b/DevTools/VisualBuilder/VBPropertiesWindow.cpp
index 29733fb3a9..146389a19e 100644
--- a/DevTools/VisualBuilder/VBPropertiesWindow.cpp
+++ b/DevTools/VisualBuilder/VBPropertiesWindow.cpp
@@ -1,8 +1,8 @@
#include "VBPropertiesWindow.h"
-#include <LibGUI/GWidget.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GTableView.h>
#include <LibGUI/GTextBox.h>
+#include <LibGUI/GWidget.h>
VBPropertiesWindow::VBPropertiesWindow()
{
diff --git a/DevTools/VisualBuilder/VBWidget.cpp b/DevTools/VisualBuilder/VBWidget.cpp
index 49ab472c3a..886b05fbd1 100644
--- a/DevTools/VisualBuilder/VBWidget.cpp
+++ b/DevTools/VisualBuilder/VBWidget.cpp
@@ -1,6 +1,6 @@
+#include "VBWidget.h"
#include "VBForm.h"
#include "VBProperty.h"
-#include "VBWidget.h"
#include "VBWidgetPropertyModel.h"
#include "VBWidgetRegistry.h"
#include <LibGUI/GButton.h>
@@ -79,7 +79,7 @@ Rect VBWidget::grabber_rect(Direction direction) const
Direction VBWidget::grabber_at(const Point& position) const
{
Direction found_grabber = Direction::None;
- for_each_direction([&] (Direction direction) {
+ for_each_direction([&](Direction direction) {
if (grabber_rect(direction).contains(position))
found_grabber = direction;
});
@@ -100,11 +100,10 @@ void VBWidget::add_property(const String& name, Function<GVariant(const GWidget&
prop.m_setter = move(setter);
}
-#define VB_ADD_PROPERTY(gclass, name, getter, setter, variant_type) \
- add_property(name, \
- [] (auto& widget) -> GVariant { return ((const gclass&)widget).getter(); }, \
- [] (auto& widget, auto& value) { ((gclass&)widget).setter(value.to_ ## variant_type()); } \
- )
+#define VB_ADD_PROPERTY(gclass, name, getter, setter, variant_type) \
+ add_property(name, \
+ [](auto& widget) -> GVariant { return ((const gclass&)widget).getter(); }, \
+ [](auto& widget, auto& value) { ((gclass&)widget).setter(value.to_##variant_type()); })
void VBWidget::setup_properties()
{
diff --git a/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp b/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp
index 0a4935c660..5bee6870cb 100644
--- a/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp
+++ b/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp
@@ -1,6 +1,6 @@
#include "VBWidgetPropertyModel.h"
-#include "VBWidget.h"
#include "VBProperty.h"
+#include "VBWidget.h"
#include <SharedGraphics/Font.h>
VBWidgetPropertyModel::VBWidgetPropertyModel(VBWidget& widget)
@@ -20,9 +20,12 @@ int VBWidgetPropertyModel::row_count(const GModelIndex&) const
String VBWidgetPropertyModel::column_name(int column) const
{
switch (column) {
- case Column::Name: return "Name";
- case Column::Value: return "Value";
- default: ASSERT_NOT_REACHED();
+ case Column::Name:
+ return "Name";
+ case Column::Value:
+ return "Value";
+ default:
+ ASSERT_NOT_REACHED();
}
}
@@ -39,20 +42,24 @@ GVariant VBWidgetPropertyModel::data(const GModelIndex& index, Role role) const
if (role == Role::Display) {
auto& property = *m_widget.m_properties[index.row()];
switch (index.column()) {
- case Column::Name: return property.name();
- case Column::Value: return property.value();
+ case Column::Name:
+ return property.name();
+ case Column::Value:
+ return property.value();
}
ASSERT_NOT_REACHED();
}
if (role == Role::ForegroundColor) {
auto& property = *m_widget.m_properties[index.row()];
switch (index.column()) {
- case Column::Name: return Color::Black;
- case Column::Value: return property.is_readonly() ? Color(Color::MidGray) : Color(Color::Black);
+ case Column::Name:
+ return Color::Black;
+ case Column::Value:
+ return property.is_readonly() ? Color(Color::MidGray) : Color(Color::Black);
}
ASSERT_NOT_REACHED();
}
- return { };
+ return {};
}
void VBWidgetPropertyModel::set_data(const GModelIndex& index, const GVariant& value)
diff --git a/DevTools/VisualBuilder/VBWidgetRegistry.cpp b/DevTools/VisualBuilder/VBWidgetRegistry.cpp
index 19b6f3ec58..6303974854 100644
--- a/DevTools/VisualBuilder/VBWidgetRegistry.cpp
+++ b/DevTools/VisualBuilder/VBWidgetRegistry.cpp
@@ -1,5 +1,5 @@
-#include "VBProperty.h"
#include "VBWidgetRegistry.h"
+#include "VBProperty.h"
#include <LibGUI/GButton.h>
#include <LibGUI/GCheckBox.h>
#include <LibGUI/GGroupBox.h>
@@ -14,18 +14,30 @@
static String to_class_name(VBWidgetType type)
{
switch (type) {
- case VBWidgetType::GWidget: return "GWidget";
- case VBWidgetType::GButton: return "GButton";
- case VBWidgetType::GLabel: return "GLabel";
- case VBWidgetType::GSpinBox: return "GSpinBox";
- case VBWidgetType::GTextEditor: return "GTextEditor";
- case VBWidgetType::GProgressBar: return "GProgressBar";
- case VBWidgetType::GCheckBox: return "GCheckBox";
- case VBWidgetType::GRadioButton: return "GRadioButton";
- case VBWidgetType::GScrollBar: return "GScrollBar";
- case VBWidgetType::GGroupBox: return "GGroupBox";
- case VBWidgetType::GSlider: return "GSlider";
- default: ASSERT_NOT_REACHED();
+ case VBWidgetType::GWidget:
+ return "GWidget";
+ case VBWidgetType::GButton:
+ return "GButton";
+ case VBWidgetType::GLabel:
+ return "GLabel";
+ case VBWidgetType::GSpinBox:
+ return "GSpinBox";
+ case VBWidgetType::GTextEditor:
+ return "GTextEditor";
+ case VBWidgetType::GProgressBar:
+ return "GProgressBar";
+ case VBWidgetType::GCheckBox:
+ return "GCheckBox";
+ case VBWidgetType::GRadioButton:
+ return "GRadioButton";
+ case VBWidgetType::GScrollBar:
+ return "GScrollBar";
+ case VBWidgetType::GGroupBox:
+ return "GGroupBox";
+ case VBWidgetType::GSlider:
+ return "GSlider";
+ default:
+ ASSERT_NOT_REACHED();
}
}
@@ -89,12 +101,12 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent)
GWidget* VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, Vector<OwnPtr<VBProperty>>& properties)
{
auto* gwidget = ::build_gwidget(type, parent);
- auto add_readonly_property = [&] (const String& name, const GVariant& value) {
+ auto add_readonly_property = [&](const String& name, const GVariant& value) {
auto property = make<VBProperty>(widget, name, value);
property->set_readonly(true);
properties.append(move(property));
};
- auto add_property = [&] (const String& name, Function<GVariant(const GWidget&)>&& getter, Function<void(GWidget&, const GVariant&)>&& setter) {
+ auto add_property = [&](const String& name, Function<GVariant(const GWidget&)>&& getter, Function<void(GWidget&, const GVariant&)>&& setter) {
auto property = make<VBProperty>(widget, name, move(getter), move(setter));
properties.append(move(property));
};
diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp
index d69b42a269..9401ba3413 100644
--- a/DevTools/VisualBuilder/main.cpp
+++ b/DevTools/VisualBuilder/main.cpp
@@ -1,19 +1,19 @@
-#include <LibGUI/GWindow.h>
-#include <LibGUI/GWidget.h>
-#include <LibGUI/GBoxLayout.h>
-#include <LibGUI/GApplication.h>
-#include <LibGUI/GMenuBar.h>
-#include <LibGUI/GAction.h>
-#include <LibGUI/GButton.h>
-#include <LibGUI/GTableView.h>
#include "VBForm.h"
+#include "VBPropertiesWindow.h"
#include "VBWidget.h"
#include "VBWidgetPropertyModel.h"
-#include "VBPropertiesWindow.h"
-#include <unistd.h>
-#include <stdio.h>
-#include <signal.h>
+#include <LibGUI/GAction.h>
+#include <LibGUI/GApplication.h>
+#include <LibGUI/GBoxLayout.h>
+#include <LibGUI/GButton.h>
+#include <LibGUI/GMenuBar.h>
+#include <LibGUI/GTableView.h>
+#include <LibGUI/GWidget.h>
+#include <LibGUI/GWindow.h>
#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
static GWindow* make_toolbox_window();
@@ -24,23 +24,23 @@ int main(int argc, char** argv)
auto* propbox = new VBPropertiesWindow;
auto* form1 = new VBForm("Form1");
- form1->on_widget_selected = [propbox] (VBWidget* widget) {
+ form1->on_widget_selected = [propbox](VBWidget* widget) {
propbox->table_view().set_model(widget ? &widget->property_model() : nullptr);
};
auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("Visual Builder");
- app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [] (const GAction&) {
+ app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [](const GAction&) {
GApplication::the().quit(0);
return;
}));
menubar->add_menu(move(app_menu));
auto file_menu = make<GMenu>("File");
- file_menu->add_action(GAction::create("Dump Form", [&] (auto&) {
+ file_menu->add_action(GAction::create("Dump Form", [&](auto&) {
form1->dump();
}));
- file_menu->add_action(GAction::create("Save Form...", { Mod_Ctrl, Key_S }, [form1] (auto&) {
+ file_menu->add_action(GAction::create("Save Form...", { Mod_Ctrl, Key_S }, [form1](auto&) {
form1->write_to_file("/tmp/form.frm");
}));
menubar->add_menu(move(file_menu));
@@ -49,7 +49,7 @@ int main(int argc, char** argv)
menubar->add_menu(move(edit_menu));
auto help_menu = make<GMenu>("Help");
- help_menu->add_action(GAction::create("About", [] (const GAction&) {
+ help_menu->add_action(GAction::create("About", [](const GAction&) {
dbgprintf("FIXME: Implement Help/About\n");
}));
menubar->add_menu(move(help_menu));
@@ -87,7 +87,7 @@ GWindow* make_toolbox_window()
label_button->set_button_style(ButtonStyle::CoolBar);
label_button->set_tooltip("GLabel");
label_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/label.png"));
- label_button->on_click = [] (GButton&) {
+ label_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GLabel);
};
@@ -96,7 +96,7 @@ GWindow* make_toolbox_window()
button_button->set_button_style(ButtonStyle::CoolBar);
button_button->set_tooltip("GButton");
button_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/button.png"));
- button_button->on_click = [] (GButton&) {
+ button_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GButton);
};
@@ -104,7 +104,7 @@ GWindow* make_toolbox_window()
spinbox_button->set_button_style(ButtonStyle::CoolBar);
spinbox_button->set_tooltip("GSpinBox");
spinbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/spinbox.png"));
- spinbox_button->on_click = [] (GButton&) {
+ spinbox_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GSpinBox);
};
@@ -112,7 +112,7 @@ GWindow* make_toolbox_window()
editor_button->set_button_style(ButtonStyle::CoolBar);
editor_button->set_tooltip("GTextEditor");
editor_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/textbox.png"));
- editor_button->on_click = [] (GButton&) {
+ editor_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GTextEditor);
};
@@ -120,7 +120,7 @@ GWindow* make_toolbox_window()
progress_bar_button->set_button_style(ButtonStyle::CoolBar);
progress_bar_button->set_tooltip("GProgressBar");
progress_bar_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/progressbar.png"));
- progress_bar_button->on_click = [] (GButton&) {
+ progress_bar_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GProgressBar);
};
@@ -128,7 +128,7 @@ GWindow* make_toolbox_window()
slider_button->set_button_style(ButtonStyle::CoolBar);
slider_button->set_tooltip("GSlider");
slider_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/slider.png"));
- slider_button->on_click = [] (GButton&) {
+ slider_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GSlider);
};
@@ -136,7 +136,7 @@ GWindow* make_toolbox_window()
checkbox_button->set_button_style(ButtonStyle::CoolBar);
checkbox_button->set_tooltip("GCheckBox");
checkbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/checkbox.png"));
- checkbox_button->on_click = [] (GButton&) {
+ checkbox_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GCheckBox);
};
@@ -144,7 +144,7 @@ GWindow* make_toolbox_window()
radiobutton_button->set_button_style(ButtonStyle::CoolBar);
radiobutton_button->set_tooltip("GRadioButton");
radiobutton_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/filled-radio-circle.png"));
- radiobutton_button->on_click = [] (GButton&) {
+ radiobutton_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GRadioButton);
};
@@ -152,7 +152,7 @@ GWindow* make_toolbox_window()
scrollbar_button->set_button_style(ButtonStyle::CoolBar);
scrollbar_button->set_tooltip("GScrollBar");
scrollbar_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/scrollbar.png"));
- scrollbar_button->on_click = [] (GButton&) {
+ scrollbar_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GScrollBar);
};
@@ -160,7 +160,7 @@ GWindow* make_toolbox_window()
groupbox_button->set_button_style(ButtonStyle::CoolBar);
groupbox_button->set_tooltip("GGroupBox");
groupbox_button->set_icon(GraphicsBitmap::load_from_file("/res/icons/vbwidgets/groupbox.png"));
- groupbox_button->on_click = [] (GButton&) {
+ groupbox_button->on_click = [](GButton&) {
if (auto* form = VBForm::current())
form->insert_widget(VBWidgetType::GGroupBox);
};