ThemeEditor: Convert the widget-preview layout to GML

This has the nice bonus of fixing the appearance of the status bar. :^)
This commit is contained in:
Sam Atkins 2022-05-10 14:43:36 +01:00 committed by Andreas Kling
parent 4edc33b4a6
commit 48122e29c3
3 changed files with 33 additions and 32 deletions

View file

@ -9,6 +9,7 @@ compile_gml(ColorProperty.gml ColorPropertyGML.h color_property_gml)
compile_gml(FlagProperty.gml FlagPropertyGML.h flag_property_gml)
compile_gml(MetricProperty.gml MetricPropertyGML.h metric_property_gml)
compile_gml(PathProperty.gml PathPropertyGML.h path_property_gml)
compile_gml(Previews/WindowPreview.gml WindowPreviewGML.h window_preview_gml)
set(SOURCES
main.cpp
@ -20,6 +21,7 @@ set(SOURCES
MetricPropertyGML.h
PathPropertyGML.h
ThemeEditorGML.h
WindowPreviewGML.h
)
serenity_app(ThemeEditor ICON app-theme-editor)

View file

@ -10,19 +10,13 @@
#include "PreviewWidget.h"
#include <AK/LexicalPath.h>
#include <AK/StringView.h>
#include <Applications/ThemeEditor/WindowPreviewGML.h>
#include <LibCore/MimeData.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
#include <LibGUI/RadioButton.h>
#include <LibGUI/Statusbar.h>
#include <LibGUI/TextEditor.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/WindowTheme.h>
#include <WindowServer/Compositor.h>
namespace ThemeEditor {
@ -46,37 +40,13 @@ public:
private:
MiniWidgetGallery()
{
m_button = add<GUI::Button>();
m_button->set_text("Button");
m_checkbox = add<GUI::CheckBox>();
m_checkbox->set_text("Check box");
m_radio = add<GUI::RadioButton>();
m_radio->set_text("Radio button");
m_statusbar = add<GUI::Statusbar>();
m_statusbar->set_text("Status bar");
m_editor = add<GUI::TextEditor>();
m_editor->set_text("Text editor\nwith multiple\nlines.");
load_from_gml(window_preview_gml);
for_each_child_widget([](auto& child) {
child.set_focus_policy(GUI::FocusPolicy::NoFocus);
return IterationDecision::Continue;
});
}
virtual void resize_event(GUI::ResizeEvent&) override
{
m_editor->set_relative_rect(10, 70, 200, 125);
m_button->set_relative_rect(10, 10, 200, 20);
m_checkbox->set_relative_rect(10, 30, 200, 20);
m_radio->set_relative_rect(10, 50, 200, 20);
m_statusbar->set_relative_rect(0, height() - 16, width(), 16);
}
RefPtr<GUI::TextEditor> m_editor;
RefPtr<GUI::Button> m_button;
RefPtr<GUI::CheckBox> m_checkbox;
RefPtr<GUI::RadioButton> m_radio;
RefPtr<GUI::Statusbar> m_statusbar;
};
PreviewWidget::PreviewWidget(Gfx::Palette const& initial_preview_palette)

View file

@ -0,0 +1,29 @@
@GUI::Frame {
layout: @GUI::VerticalBoxLayout {}
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
margins: [8, 100, 8, 8]
}
@GUI::Button {
text: "Button"
}
@GUI::CheckBox {
text: "Check box"
}
@GUI::RadioButton {
text: "Radio button"
}
@GUI::TextEditor {
text: "Text editor\nwith multiple\nlines."
}
}
@GUI::Statusbar {
text: "Status bar"
}
}