1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

Playground: Show placeholders for unregistered widgets

With this, Playground can be used to interactively edit e.g.
DisplaySettingsWindow.gml.
This commit is contained in:
Nico Weber 2021-01-11 14:01:15 -05:00 committed by Andreas Kling
parent 1b2364846f
commit 009c753a12
3 changed files with 56 additions and 11 deletions

View file

@ -40,11 +40,43 @@
#include <LibGUI/Menu.h>
#include <LibGUI/MenuBar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/Window.h>
#include <string.h>
namespace {
class UnregisteredWidget final : public GUI::Widget {
C_OBJECT(UnregisteredWidget);
private:
UnregisteredWidget(const String& class_name);
virtual void paint_event(GUI::PaintEvent& event) override;
String m_text;
};
UnregisteredWidget::UnregisteredWidget(const String& class_name)
{
StringBuilder builder;
builder.append(class_name);
builder.append("\nnot registered");
m_text = builder.to_string();
}
void UnregisteredWidget::paint_event(GUI::PaintEvent& event)
{
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.fill_rect(event.rect(), Gfx::Color::DarkRed);
painter.draw_text(rect(), m_text, Gfx::TextAlignment::Center, Color::White);
}
}
class GMLAutocompleteProvider final : public virtual GUI::AutocompleteProvider {
public:
GMLAutocompleteProvider() { }
@ -292,7 +324,9 @@ int main(int argc, char** argv)
editor.on_change = [&] {
preview.remove_all_children();
preview.load_from_gml(editor.text());
preview.load_from_gml(editor.text(), [](const String& class_name) -> RefPtr<GUI::Widget> {
return UnregisteredWidget::construct(class_name);
});
};
auto menubar = GUI::MenuBar::construct();