Skip to content

Commit

Permalink
HackStudio: Add placeholder code to test widget factory construction
Browse files Browse the repository at this point in the history
We now use the magical widget registry to factory-construct widgets and
place them into the form.

This will need all kinds of work, but it's nice that the mechanism is
working as intended.
  • Loading branch information
awesomekling committed Nov 10, 2019
1 parent 2da058c commit f92e0f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions DevTools/HackStudio/FormEditorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class FormEditorWidget final : public GScrollableWidget {
public:
virtual ~FormEditorWidget() override;

FormWidget& form_widget() { return *m_form_widget; }
const FormWidget& form_widget() const { return *m_form_widget; }

private:
virtual void paint_event(GPaintEvent&) override;

Expand Down
6 changes: 4 additions & 2 deletions DevTools/HackStudio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "EditorWrapper.h"
#include "FindInFilesWidget.h"
#include "FormEditorWidget.h"
#include "FormWidget.h"
#include "Locator.h"
#include "Project.h"
#include "TerminalWrapper.h"
Expand Down Expand Up @@ -132,8 +133,9 @@ int main(int argc, char** argv)

GWidgetClassRegistration::for_each([&](const GWidgetClassRegistration& reg) {
auto icon_path = String::format("/res/icons/widgets/%s.png", reg.class_name().characters());
auto action = GAction::create(reg.class_name(), GraphicsBitmap::load_from_file(icon_path), [&](auto&) {

auto action = GAction::create(reg.class_name(), GraphicsBitmap::load_from_file(icon_path), [&reg](auto&) {
auto widget = reg.construct(&g_form_editor_widget->form_widget());
widget->set_relative_rect(30, 30, 30, 30);
});
form_widgets_toolbar->add_action(move(action));
});
Expand Down

0 comments on commit f92e0f7

Please sign in to comment.