1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:17:44 +00:00

LibGUI: Convert custom widgets and subclasses to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-21 20:04:00 +02:00
parent 15a66dc8ab
commit defafd72bc
30 changed files with 57 additions and 47 deletions

View file

@ -4,6 +4,7 @@
#include <LibGUI/GBoxLayout.h>
class ColorWidget : public GFrame {
C_OBJECT(ColorWidget)
public:
explicit ColorWidget(Color color, PaletteWidget& palette_widget, GWidget* parent)
: GFrame(parent)
@ -95,7 +96,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
bottom_color_container->layout()->set_spacing(1);
auto add_color_widget = [&](GWidget* container, Color color) {
auto* color_widget = new ColorWidget(color, *this, container);
auto color_widget = ColorWidget::construct(color, *this, container);
color_widget->set_fill_with_background_color(true);
color_widget->set_background_color(color);
};

View file

@ -10,6 +10,7 @@
#include <LibDraw/PNGLoader.h>
class ToolButton final : public GButton {
C_OBJECT(ToolButton)
public:
ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool)
: GButton(parent)
@ -47,7 +48,7 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
layout()->set_margins({ 4, 4, 4, 4 });
auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) {
auto* button = new ToolButton(name, this, move(tool));
auto button = ToolButton::construct(name, this, move(tool));
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
button->set_preferred_size(0, 32);
button->set_checkable(true);
@ -55,7 +56,7 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
button->set_icon(load_png(String::format("/res/icons/paintbrush/%s.png", String(icon_name).characters())));
button->on_checked = [button](auto checked) {
button->on_checked = [button = button.ptr()](auto checked) {
if (checked)
PaintableWidget::the().set_tool(&button->tool());
else

View file

@ -30,8 +30,8 @@ int main(int argc, char** argv)
vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
vertical_container->layout()->set_spacing(0);
auto* paintable_widget = new PaintableWidget(vertical_container);
new PaletteWidget(*paintable_widget, vertical_container);
auto paintable_widget = PaintableWidget::construct(vertical_container);
PaletteWidget::construct(*paintable_widget, vertical_container);
window->show();