1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 10:14:57 +00:00

LibGUI: Put all classes in the GUI namespace and remove the leading G

This took me a moment. Welcome to the new world of GUI::Widget! :^)
This commit is contained in:
Andreas Kling 2020-02-02 15:07:41 +01:00
parent 2d39da5405
commit c5bd9d4ed1
337 changed files with 5400 additions and 4816 deletions

View file

@ -30,14 +30,16 @@
#include <LibGUI/GMessageBox.h>
#include <stdio.h>
int GMessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
namespace GUI {
int MessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
{
auto box = GMessageBox::construct(text, title, type, input_type, parent);
auto box = MessageBox::construct(text, title, type, input_type, parent);
return box->exec();
}
GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
: GDialog(parent)
MessageBox::MessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, Core::Object* parent)
: Dialog(parent)
, m_text(text)
, m_type(type)
, m_input_type(input_type)
@ -46,11 +48,11 @@ GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type t
build();
}
GMessageBox::~GMessageBox()
MessageBox::~MessageBox()
{
}
RefPtr<GraphicsBitmap> GMessageBox::icon() const
RefPtr<GraphicsBitmap> MessageBox::icon() const
{
switch (m_type) {
case Type::Information:
@ -64,75 +66,77 @@ RefPtr<GraphicsBitmap> GMessageBox::icon() const
}
}
bool GMessageBox::should_include_ok_button() const
bool MessageBox::should_include_ok_button() const
{
return m_input_type == InputType::OK || m_input_type == InputType::OKCancel;
}
bool GMessageBox::should_include_cancel_button() const
bool MessageBox::should_include_cancel_button() const
{
return m_input_type == InputType::OKCancel;
}
void GMessageBox::build()
void MessageBox::build()
{
auto widget = GWidget::construct();
auto widget = Widget::construct();
set_main_widget(widget);
int text_width = widget->font().width(m_text);
int icon_width = 0;
widget->set_layout(make<GVBoxLayout>());
widget->set_layout(make<VBoxLayout>());
widget->set_fill_with_background_color(true);
widget->layout()->set_margins({ 0, 15, 0, 15 });
widget->layout()->set_spacing(15);
RefPtr<GWidget> message_container = widget;
RefPtr<Widget> message_container = widget;
if (m_type != Type::None) {
message_container = GWidget::construct(widget.ptr());
message_container->set_layout(make<GHBoxLayout>());
message_container = Widget::construct(widget.ptr());
message_container->set_layout(make<HBoxLayout>());
message_container->layout()->set_margins({ 8, 0, 8, 0 });
message_container->layout()->set_spacing(8);
auto icon_label = GLabel::construct(message_container);
auto icon_label = Label::construct(message_container);
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
icon_label->set_preferred_size(32, 32);
icon_label->set_icon(icon());
icon_width = icon_label->icon()->width();
}
auto label = GLabel::construct(m_text, message_container);
auto label = Label::construct(m_text, message_container);
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
label->set_preferred_size(text_width, 16);
auto button_container = GWidget::construct(widget.ptr());
button_container->set_layout(make<GHBoxLayout>());
auto button_container = Widget::construct(widget.ptr());
button_container->set_layout(make<HBoxLayout>());
button_container->layout()->set_spacing(5);
button_container->layout()->set_margins({ 15, 0, 15, 0 });
if (should_include_ok_button()) {
auto ok_button = GButton::construct(button_container);
auto ok_button = Button::construct(button_container);
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
ok_button->set_preferred_size(0, 20);
ok_button->set_text("OK");
ok_button->on_click = [this](auto&) {
dbgprintf("GMessageBox: OK button clicked\n");
done(GDialog::ExecOK);
done(Dialog::ExecOK);
};
}
if (should_include_cancel_button()) {
auto cancel_button = GButton::construct(button_container);
auto cancel_button = Button::construct(button_container);
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
cancel_button->set_preferred_size(0, 20);
cancel_button->set_text("Cancel");
cancel_button->on_click = [this](auto&) {
dbgprintf("GMessageBox: Cancel button clicked\n");
done(GDialog::ExecCancel);
done(Dialog::ExecCancel);
};
}
set_rect(x(), y(), text_width + icon_width + 80, 100);
set_resizable(false);
}
}