mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
GWidget: Add set_preferred_size(width, height) overload.
It was annoying to always write set_preferred_size({ width, height }). :^)
This commit is contained in:
parent
5b440a72f9
commit
aa2224a2f0
26 changed files with 61 additions and 60 deletions
|
@ -65,16 +65,16 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
|||
upper_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
upper_container->layout()->set_spacing(4);
|
||||
upper_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
upper_container->set_preferred_size({ 0, 26 });
|
||||
upper_container->set_preferred_size(0, 26);
|
||||
|
||||
auto* toolbar = new GToolBar(upper_container);
|
||||
toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
toolbar->set_preferred_size({ 60, 0 });
|
||||
toolbar->set_preferred_size(60, 0);
|
||||
toolbar->set_has_frame(false);
|
||||
|
||||
auto* location_textbox = new GTextBox(upper_container);
|
||||
location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
location_textbox->set_preferred_size({ 0, 20 });
|
||||
location_textbox->set_preferred_size(0, 20);
|
||||
|
||||
m_view = new GTableView(vertical_container);
|
||||
m_view->set_model(GSortingProxyModel::create(*m_model));
|
||||
|
@ -116,16 +116,16 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
|||
lower_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
lower_container->layout()->set_spacing(4);
|
||||
lower_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
lower_container->set_preferred_size({ 0, 60 });
|
||||
lower_container->set_preferred_size(0, 60);
|
||||
|
||||
auto* filename_container = new GWidget(lower_container);
|
||||
filename_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
filename_container->set_preferred_size({ 0, 20 });
|
||||
filename_container->set_preferred_size(0, 20);
|
||||
filename_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
auto* filename_label = new GLabel("File name:", filename_container);
|
||||
filename_label->set_text_alignment(TextAlignment::CenterLeft);
|
||||
filename_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
filename_label->set_preferred_size({ 60, 0 });
|
||||
filename_label->set_preferred_size(60, 0);
|
||||
auto* filename_textbox = new GTextBox(filename_container);
|
||||
if (m_mode == Mode::Save) {
|
||||
filename_textbox->set_text("Untitled.txt"); //TODO: replace .txt with a preferred extension
|
||||
|
@ -152,14 +152,14 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
|||
|
||||
auto* button_container = new GWidget(lower_container);
|
||||
button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button_container->set_preferred_size({ 0, 20 });
|
||||
button_container->set_preferred_size(0, 20);
|
||||
button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
button_container->layout()->set_spacing(4);
|
||||
button_container->layout()->add_spacer();
|
||||
|
||||
auto* cancel_button = new GButton(button_container);
|
||||
cancel_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
cancel_button->set_preferred_size({ 80, 0 });
|
||||
cancel_button->set_preferred_size(80, 0);
|
||||
cancel_button->set_text("Cancel");
|
||||
cancel_button->on_click = [this](auto&) {
|
||||
done(ExecCancel);
|
||||
|
@ -167,7 +167,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
|||
|
||||
auto* ok_button = new GButton(button_container);
|
||||
ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
ok_button->set_preferred_size({ 80, 0 });
|
||||
ok_button->set_preferred_size(80, 0);
|
||||
ok_button->set_text(ok_button_name(m_mode));
|
||||
ok_button->on_click = [this, filename_textbox](auto&) {
|
||||
FileSystemPath path(String::format("%s/%s", m_model->path().characters(), filename_textbox->text().characters()));
|
||||
|
@ -184,7 +184,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
|||
|
||||
auto* preview_container = new GFrame(horizontal_container);
|
||||
preview_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
preview_container->set_preferred_size({ 180, 0 });
|
||||
preview_container->set_preferred_size(180, 0);
|
||||
preview_container->set_frame_shape(FrameShape::Container);
|
||||
preview_container->set_frame_shadow(FrameShadow::Sunken);
|
||||
preview_container->set_frame_thickness(2);
|
||||
|
@ -194,16 +194,16 @@ GFilePicker::GFilePicker(Mode mode, const StringView& path, CObject* parent)
|
|||
m_preview_image_label = new GLabel(preview_container);
|
||||
m_preview_image_label->set_should_stretch_icon(true);
|
||||
m_preview_image_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
m_preview_image_label->set_preferred_size({ 160, 160 });
|
||||
m_preview_image_label->set_preferred_size(160, 160);
|
||||
|
||||
m_preview_name_label = new GLabel(preview_container);
|
||||
m_preview_name_label->set_font(Font::default_bold_font());
|
||||
m_preview_name_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_preview_name_label->set_preferred_size({ 0, m_preview_name_label->font().glyph_height() });
|
||||
m_preview_name_label->set_preferred_size(0, m_preview_name_label->font().glyph_height());
|
||||
|
||||
m_preview_geometry_label = new GLabel(preview_container);
|
||||
m_preview_geometry_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_preview_geometry_label->set_preferred_size({ 0, m_preview_name_label->font().glyph_height() });
|
||||
m_preview_geometry_label->set_preferred_size(0, m_preview_name_label->font().glyph_height());
|
||||
}
|
||||
|
||||
GFilePicker::~GFilePicker()
|
||||
|
|
|
@ -36,15 +36,15 @@ void GInputBox::build()
|
|||
|
||||
auto* label = new GLabel(m_prompt, widget);
|
||||
label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
label->set_preferred_size({ text_width, 16 });
|
||||
label->set_preferred_size(text_width, 16);
|
||||
|
||||
m_text_editor = new GTextEditor(GTextEditor::SingleLine, widget);
|
||||
m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_text_editor->set_preferred_size({ 0, 19 });
|
||||
m_text_editor->set_preferred_size(0, 19);
|
||||
|
||||
auto* button_container_outer = new GWidget(widget);
|
||||
button_container_outer->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button_container_outer->set_preferred_size({ 0, 20 });
|
||||
button_container_outer->set_preferred_size(0, 20);
|
||||
button_container_outer->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
|
||||
auto* button_container_inner = new GWidget(button_container_outer);
|
||||
|
@ -53,7 +53,7 @@ void GInputBox::build()
|
|||
|
||||
m_cancel_button = new GButton(button_container_inner);
|
||||
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size({ 0, 20 });
|
||||
m_cancel_button->set_preferred_size(0, 20);
|
||||
m_cancel_button->set_text("Cancel");
|
||||
m_cancel_button->on_click = [this](auto&) {
|
||||
dbgprintf("GInputBox: Cancel button clicked\n");
|
||||
|
@ -62,7 +62,7 @@ void GInputBox::build()
|
|||
|
||||
m_ok_button = new GButton(button_container_inner);
|
||||
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_ok_button->set_preferred_size({ 0, 20 });
|
||||
m_ok_button->set_preferred_size(0, 20);
|
||||
m_ok_button->set_text("OK");
|
||||
m_ok_button->on_click = [this](auto&) {
|
||||
dbgprintf("GInputBox: OK button clicked\n");
|
||||
|
|
|
@ -65,5 +65,5 @@ void GLabel::paint_event(GPaintEvent& event)
|
|||
void GLabel::size_to_fit()
|
||||
{
|
||||
set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||
set_preferred_size({ font().width(m_text), 0 });
|
||||
set_preferred_size(font().width(m_text), 0);
|
||||
}
|
||||
|
|
|
@ -71,14 +71,14 @@ void GMessageBox::build()
|
|||
|
||||
auto* icon_label = new GLabel(message_container);
|
||||
icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
icon_label->set_preferred_size({ 32, 32 });
|
||||
icon_label->set_preferred_size(32, 32);
|
||||
icon_label->set_icon(icon());
|
||||
icon_width = icon_label->icon()->width();
|
||||
}
|
||||
|
||||
auto* label = new GLabel(m_text, message_container);
|
||||
label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
label->set_preferred_size({ text_width, 16 });
|
||||
label->set_preferred_size(text_width, 16);
|
||||
|
||||
auto* button_container = new GWidget(widget);
|
||||
button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
|
@ -88,7 +88,7 @@ void GMessageBox::build()
|
|||
if (should_include_ok_button()) {
|
||||
auto* ok_button = new GButton(button_container);
|
||||
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
ok_button->set_preferred_size({ 0, 20 });
|
||||
ok_button->set_preferred_size(0, 20);
|
||||
ok_button->set_text("OK");
|
||||
ok_button->on_click = [this](auto&) {
|
||||
dbgprintf("GMessageBox: OK button clicked\n");
|
||||
|
@ -99,7 +99,7 @@ void GMessageBox::build()
|
|||
if (should_include_cancel_button()) {
|
||||
auto* cancel_button = new GButton(button_container);
|
||||
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
cancel_button->set_preferred_size({ 0, 20 });
|
||||
cancel_button->set_preferred_size(0, 20);
|
||||
cancel_button->set_text("Cancel");
|
||||
cancel_button->on_click = [this](auto&) {
|
||||
dbgprintf("GMessageBox: Cancel button clicked\n");
|
||||
|
|
|
@ -8,7 +8,7 @@ GResizeCorner::GResizeCorner(GWidget* parent)
|
|||
: GWidget(parent)
|
||||
{
|
||||
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
set_preferred_size({ 16, 16 });
|
||||
set_preferred_size(16, 16);
|
||||
m_bitmap = GraphicsBitmap::load_from_file("/res/icons/resize-corner.png");
|
||||
ASSERT(m_bitmap);
|
||||
}
|
||||
|
|
|
@ -71,9 +71,9 @@ GScrollBar::GScrollBar(Orientation orientation, GWidget* parent)
|
|||
s_right_arrow_bitmap = &CharacterBitmap::create_from_ascii(s_right_arrow_bitmap_data, 9, 9).leak_ref();
|
||||
|
||||
if (m_orientation == Orientation::Vertical) {
|
||||
set_preferred_size({ 15, 0 });
|
||||
set_preferred_size(15, 0);
|
||||
} else {
|
||||
set_preferred_size({ 0, 15 });
|
||||
set_preferred_size(0, 15);
|
||||
}
|
||||
|
||||
m_automatic_scrolling_timer.set_interval(100);
|
||||
|
|
|
@ -9,7 +9,7 @@ GStatusBar::GStatusBar(GWidget* parent)
|
|||
: GWidget(parent)
|
||||
{
|
||||
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
set_preferred_size({ 0, 20 });
|
||||
set_preferred_size(0, 20);
|
||||
set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
layout()->set_margins({ 2, 2, 2, 2 });
|
||||
layout()->set_spacing(2);
|
||||
|
|
|
@ -8,7 +8,7 @@ GToolBar::GToolBar(GWidget* parent)
|
|||
: GWidget(parent)
|
||||
{
|
||||
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
set_preferred_size({ 0, 28 });
|
||||
set_preferred_size(0, 28);
|
||||
set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
layout()->set_spacing(0);
|
||||
layout()->set_margins({ 2, 2, 2, 2 });
|
||||
|
@ -39,7 +39,7 @@ void GToolBar::add_action(GAction& action)
|
|||
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
ASSERT(button->size_policy(Orientation::Horizontal) == SizePolicy::Fixed);
|
||||
ASSERT(button->size_policy(Orientation::Vertical) == SizePolicy::Fixed);
|
||||
button->set_preferred_size({ 24, 24 });
|
||||
button->set_preferred_size(24, 24);
|
||||
|
||||
m_items.append(move(item));
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
{
|
||||
set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
set_background_color(Color::White);
|
||||
set_preferred_size({ 8, 22 });
|
||||
set_preferred_size(8, 22);
|
||||
}
|
||||
virtual ~SeparatorWidget() override {}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
|
||||
Size preferred_size() const { return m_preferred_size; }
|
||||
void set_preferred_size(const Size&);
|
||||
void set_preferred_size(int width, int height) { set_preferred_size({ width, height }); }
|
||||
|
||||
bool has_tooltip() const { return !m_tooltip.is_empty(); }
|
||||
String tooltip() const { return m_tooltip; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue