mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
HackStudio: Start fleshing out the GUI for a GUI designer :^)
I'll be reconstructing parts of the VisualBuilder application here and then we can retire VisualBuilder entirely once all the functionality is available in HackStudio.
This commit is contained in:
parent
bce510bf6f
commit
d016d5e365
Notes:
sideshowbarker
2024-07-19 11:19:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d016d5e365c
9 changed files with 136 additions and 9 deletions
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
TEST_CASE(load_form)
|
TEST_CASE(load_form)
|
||||||
{
|
{
|
||||||
FILE* fp = fopen("../../Base/home/anon/test.frm", "r");
|
FILE* fp = fopen("../../Base/home/anon/little/test.frm", "r");
|
||||||
ASSERT(fp);
|
ASSERT(fp);
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
main.cpp
|
main.cpp
|
||||||
Makefile
|
Makefile
|
||||||
little.files
|
little.files
|
||||||
|
test.frm
|
||||||
|
|
28
DevTools/HackStudio/FormEditorWidget.cpp
Normal file
28
DevTools/HackStudio/FormEditorWidget.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "FormEditorWidget.h"
|
||||||
|
#include "FormWidget.h"
|
||||||
|
#include <LibGUI/GPainter.h>
|
||||||
|
|
||||||
|
FormEditorWidget::FormEditorWidget(GWidget* parent)
|
||||||
|
: GScrollableWidget(parent)
|
||||||
|
{
|
||||||
|
set_fill_with_background_color(true);
|
||||||
|
set_background_color(Color::White);
|
||||||
|
|
||||||
|
set_frame_shape(FrameShape::Container);
|
||||||
|
set_frame_shadow(FrameShadow::Sunken);
|
||||||
|
set_frame_thickness(2);
|
||||||
|
|
||||||
|
m_form_widget = FormWidget::construct(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormEditorWidget::~FormEditorWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormEditorWidget::paint_event(GPaintEvent& event)
|
||||||
|
{
|
||||||
|
GFrame::paint_event(event);
|
||||||
|
|
||||||
|
GPainter painter(*this);
|
||||||
|
painter.add_clip_rect(event.rect());
|
||||||
|
}
|
18
DevTools/HackStudio/FormEditorWidget.h
Normal file
18
DevTools/HackStudio/FormEditorWidget.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/GScrollableWidget.h>
|
||||||
|
|
||||||
|
class FormWidget;
|
||||||
|
|
||||||
|
class FormEditorWidget final : public GScrollableWidget {
|
||||||
|
C_OBJECT(FormEditorWidget)
|
||||||
|
public:
|
||||||
|
virtual ~FormEditorWidget() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
|
|
||||||
|
explicit FormEditorWidget(GWidget* parent);
|
||||||
|
|
||||||
|
RefPtr<FormWidget> m_form_widget;
|
||||||
|
};
|
27
DevTools/HackStudio/FormWidget.cpp
Normal file
27
DevTools/HackStudio/FormWidget.cpp
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#include "FormWidget.h"
|
||||||
|
#include "FormEditorWidget.h"
|
||||||
|
#include <LibGUI/GPainter.h>
|
||||||
|
|
||||||
|
FormWidget::FormWidget(FormEditorWidget& parent)
|
||||||
|
: GWidget(&parent)
|
||||||
|
{
|
||||||
|
set_fill_with_background_color(true);
|
||||||
|
set_background_color(Color::WarmGray);
|
||||||
|
set_relative_rect(20, 20, 400, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormWidget::~FormWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormWidget::paint_event(GPaintEvent& event)
|
||||||
|
{
|
||||||
|
GPainter painter(*this);
|
||||||
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
|
for (int y = 0; y < height(); y += m_grid_size) {
|
||||||
|
for (int x = 0; x < width(); x += m_grid_size) {
|
||||||
|
painter.set_pixel({ x, y }, Color::from_rgb(0x404040));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
DevTools/HackStudio/FormWidget.h
Normal file
22
DevTools/HackStudio/FormWidget.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/GWidget.h>
|
||||||
|
|
||||||
|
class FormEditorWidget;
|
||||||
|
|
||||||
|
class FormWidget final : public GWidget {
|
||||||
|
C_OBJECT(FormWidget)
|
||||||
|
public:
|
||||||
|
virtual ~FormWidget() override;
|
||||||
|
|
||||||
|
FormEditorWidget& editor();
|
||||||
|
const FormEditorWidget& editor() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
|
|
||||||
|
explicit FormWidget(FormEditorWidget& parent);
|
||||||
|
|
||||||
|
// FIXME: This should be an app-wide preference instead.
|
||||||
|
int m_grid_size { 5 };
|
||||||
|
};
|
|
@ -6,6 +6,8 @@ OBJS = \
|
||||||
TerminalWrapper.o \
|
TerminalWrapper.o \
|
||||||
FindInFilesWidget.o \
|
FindInFilesWidget.o \
|
||||||
ProcessStateWidget.o \
|
ProcessStateWidget.o \
|
||||||
|
FormEditorWidget.o \
|
||||||
|
FormWidget.o \
|
||||||
CppLexer.o \
|
CppLexer.o \
|
||||||
Editor.o \
|
Editor.o \
|
||||||
EditorWrapper.o \
|
EditorWrapper.o \
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "Editor.h"
|
#include "Editor.h"
|
||||||
#include "EditorWrapper.h"
|
#include "EditorWrapper.h"
|
||||||
#include "FindInFilesWidget.h"
|
#include "FindInFilesWidget.h"
|
||||||
|
#include "FormEditorWidget.h"
|
||||||
#include "Locator.h"
|
#include "Locator.h"
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "TerminalWrapper.h"
|
#include "TerminalWrapper.h"
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
#include <LibGUI/GMenuBar.h>
|
#include <LibGUI/GMenuBar.h>
|
||||||
#include <LibGUI/GMessageBox.h>
|
#include <LibGUI/GMessageBox.h>
|
||||||
#include <LibGUI/GSplitter.h>
|
#include <LibGUI/GSplitter.h>
|
||||||
|
#include <LibGUI/GStackWidget.h>
|
||||||
#include <LibGUI/GTabWidget.h>
|
#include <LibGUI/GTabWidget.h>
|
||||||
#include <LibGUI/GTextBox.h>
|
#include <LibGUI/GTextBox.h>
|
||||||
#include <LibGUI/GTextEditor.h>
|
#include <LibGUI/GTextEditor.h>
|
||||||
|
@ -35,6 +37,9 @@ String g_currently_open_file;
|
||||||
OwnPtr<Project> g_project;
|
OwnPtr<Project> g_project;
|
||||||
RefPtr<GWindow> g_window;
|
RefPtr<GWindow> g_window;
|
||||||
RefPtr<GListView> g_project_list_view;
|
RefPtr<GListView> g_project_list_view;
|
||||||
|
RefPtr<GStackWidget> g_right_hand_stack;
|
||||||
|
RefPtr<GSplitter> g_inner_splitter;
|
||||||
|
RefPtr<FormEditorWidget> g_form_editor_widget;
|
||||||
|
|
||||||
static RefPtr<GTabWidget> s_action_tab_widget;
|
static RefPtr<GTabWidget> s_action_tab_widget;
|
||||||
|
|
||||||
|
@ -51,6 +56,20 @@ void add_new_editor(GWidget& parent)
|
||||||
wrapper->editor().set_focus(true);
|
wrapper->editor().set_focus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class EditMode {
|
||||||
|
Text,
|
||||||
|
Form,
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_edit_mode(EditMode mode)
|
||||||
|
{
|
||||||
|
if (mode == EditMode::Text) {
|
||||||
|
g_right_hand_stack->set_active_widget(g_inner_splitter);
|
||||||
|
} else if (mode == EditMode::Form) {
|
||||||
|
g_right_hand_stack->set_active_widget(g_form_editor_widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EditorWrapper& current_editor_wrapper()
|
EditorWrapper& current_editor_wrapper()
|
||||||
{
|
{
|
||||||
ASSERT(g_current_editor_wrapper);
|
ASSERT(g_current_editor_wrapper);
|
||||||
|
@ -98,9 +117,13 @@ int main(int argc, char** argv)
|
||||||
g_project_list_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
g_project_list_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
g_project_list_view->set_preferred_size(140, 0);
|
g_project_list_view->set_preferred_size(140, 0);
|
||||||
|
|
||||||
auto inner_splitter = GSplitter::construct(Orientation::Vertical, outer_splitter);
|
g_right_hand_stack = GStackWidget::construct(outer_splitter);
|
||||||
inner_splitter->layout()->set_margins({ 0, 3, 0, 0 });
|
|
||||||
add_new_editor(inner_splitter);
|
g_form_editor_widget = FormEditorWidget::construct(g_right_hand_stack);
|
||||||
|
|
||||||
|
g_inner_splitter = GSplitter::construct(Orientation::Vertical, g_right_hand_stack);
|
||||||
|
g_inner_splitter->layout()->set_margins({ 0, 3, 0, 0 });
|
||||||
|
add_new_editor(*g_inner_splitter);
|
||||||
|
|
||||||
auto new_action = GAction::create("Add new file to project...", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GAction&) {
|
auto new_action = GAction::create("Add new file to project...", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GAction&) {
|
||||||
auto input_box = GInputBox::construct("Enter name of new file:", "Add new file to project", g_window);
|
auto input_box = GInputBox::construct("Enter name of new file:", "Add new file to project", g_window);
|
||||||
|
@ -136,7 +159,7 @@ int main(int argc, char** argv)
|
||||||
if (g_all_editor_wrappers.size() <= 1)
|
if (g_all_editor_wrappers.size() <= 1)
|
||||||
return;
|
return;
|
||||||
Vector<EditorWrapper*> wrappers;
|
Vector<EditorWrapper*> wrappers;
|
||||||
inner_splitter->for_each_child_of_type<EditorWrapper>([&](auto& child) {
|
g_inner_splitter->for_each_child_of_type<EditorWrapper>([&](auto& child) {
|
||||||
wrappers.append(&child);
|
wrappers.append(&child);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
@ -154,7 +177,7 @@ int main(int argc, char** argv)
|
||||||
if (g_all_editor_wrappers.size() <= 1)
|
if (g_all_editor_wrappers.size() <= 1)
|
||||||
return;
|
return;
|
||||||
Vector<EditorWrapper*> wrappers;
|
Vector<EditorWrapper*> wrappers;
|
||||||
inner_splitter->for_each_child_of_type<EditorWrapper>([&](auto& child) {
|
g_inner_splitter->for_each_child_of_type<EditorWrapper>([&](auto& child) {
|
||||||
wrappers.append(&child);
|
wrappers.append(&child);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
@ -173,7 +196,7 @@ int main(int argc, char** argv)
|
||||||
return;
|
return;
|
||||||
auto wrapper = g_current_editor_wrapper;
|
auto wrapper = g_current_editor_wrapper;
|
||||||
switch_to_next_editor->activate();
|
switch_to_next_editor->activate();
|
||||||
inner_splitter->remove_child(*wrapper);
|
g_inner_splitter->remove_child(*wrapper);
|
||||||
g_all_editor_wrappers.remove_first_matching([&](auto& entry) { return entry == wrapper.ptr(); });
|
g_all_editor_wrappers.remove_first_matching([&](auto& entry) { return entry == wrapper.ptr(); });
|
||||||
update_actions();
|
update_actions();
|
||||||
});
|
});
|
||||||
|
@ -202,7 +225,7 @@ int main(int argc, char** argv)
|
||||||
open_file(filename);
|
open_file(filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
s_action_tab_widget = GTabWidget::construct(inner_splitter);
|
s_action_tab_widget = GTabWidget::construct(g_inner_splitter);
|
||||||
|
|
||||||
s_action_tab_widget->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
s_action_tab_widget->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
s_action_tab_widget->set_preferred_size(0, 24);
|
s_action_tab_widget->set_preferred_size(0, 24);
|
||||||
|
@ -222,7 +245,7 @@ int main(int argc, char** argv)
|
||||||
});
|
});
|
||||||
|
|
||||||
auto add_editor_action = GAction::create("Add new editor", { Mod_Ctrl | Mod_Alt, Key_E }, [&](auto&) {
|
auto add_editor_action = GAction::create("Add new editor", { Mod_Ctrl | Mod_Alt, Key_E }, [&](auto&) {
|
||||||
add_new_editor(inner_splitter);
|
add_new_editor(*g_inner_splitter);
|
||||||
update_actions();
|
update_actions();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -379,6 +402,12 @@ void open_file(const String& filename)
|
||||||
current_editor().on_change = nullptr;
|
current_editor().on_change = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filename.ends_with(".frm")) {
|
||||||
|
set_edit_mode(EditMode::Form);
|
||||||
|
} else {
|
||||||
|
set_edit_mode(EditMode::Text);
|
||||||
|
}
|
||||||
|
|
||||||
g_currently_open_file = filename;
|
g_currently_open_file = filename;
|
||||||
g_window->set_title(String::format("%s - HackStudio", g_currently_open_file.characters()));
|
g_window->set_title(String::format("%s - HackStudio", g_currently_open_file.characters()));
|
||||||
g_project_list_view->update();
|
g_project_list_view->update();
|
||||||
|
|
Loading…
Reference in a new issue