mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:57:35 +00:00
LibGUI: Rewrite layout system in terms of min and max sizes
This patch removes size policies and preferred sizes, and replaces them with min-size and max-size for each widget. Box layout now works in 3 passes: 1) Set all items (widgets/spacers) to their min-size 2) Distribute remaining space evenly, respecting max-size 3) Place widgets one after the other, adding spacing in between I've also added convenience helpers for setting a fixed size (which is the same as setting min-size and max-size to the same value.) This significantly reduces the verbosity of widget layout and makes GML a bit more pleasant to write, too. :^)
This commit is contained in:
parent
b2bba5ce5c
commit
7dc5a3ead8
83 changed files with 444 additions and 957 deletions
|
@ -51,8 +51,7 @@ BookmarksBarWidget::BookmarksBarWidget(const String& bookmarks_file, bool enable
|
|||
set_layout<GUI::HorizontalBoxLayout>();
|
||||
layout()->set_spacing(0);
|
||||
|
||||
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
set_preferred_size(0, 20);
|
||||
set_fixed_height(20);
|
||||
|
||||
if (!enabled)
|
||||
set_visible(false);
|
||||
|
@ -60,8 +59,7 @@ BookmarksBarWidget::BookmarksBarWidget(const String& bookmarks_file, bool enable
|
|||
m_additional = GUI::Button::construct();
|
||||
m_additional->set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
m_additional->set_text(">");
|
||||
m_additional->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_additional->set_preferred_size(14, 20);
|
||||
m_additional->set_fixed_size(14, 20);
|
||||
m_additional->set_focus_policy(GUI::FocusPolicy::TabFocus);
|
||||
m_additional->on_click = [this](auto) {
|
||||
if (m_additional_menu) {
|
||||
|
@ -134,9 +132,8 @@ void BookmarksBarWidget::model_did_update(unsigned)
|
|||
|
||||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
button.set_text(title);
|
||||
button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
|
||||
button.set_preferred_size(font().width(title) + 32, 20);
|
||||
button.set_fixed_size(font().width(title) + 32, 20);
|
||||
button.set_relative_rect(rect);
|
||||
button.set_focus_policy(GUI::FocusPolicy::TabFocus);
|
||||
button.set_tooltip(url);
|
||||
|
|
|
@ -62,8 +62,7 @@ ConsoleWidget::ConsoleWidget()
|
|||
|
||||
auto& bottom_container = add<GUI::Widget>();
|
||||
bottom_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
bottom_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
bottom_container.set_preferred_size(0, 22);
|
||||
bottom_container.set_fixed_height(22);
|
||||
|
||||
m_input = bottom_container.add<GUI::TextBox>();
|
||||
m_input->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
|
||||
|
@ -112,8 +111,7 @@ ConsoleWidget::ConsoleWidget()
|
|||
set_focus_proxy(m_input);
|
||||
|
||||
auto& clear_button = bottom_container.add<GUI::Button>();
|
||||
clear_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
clear_button.set_preferred_size(22, 22);
|
||||
clear_button.set_fixed_size(22, 22);
|
||||
clear_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/delete.png"));
|
||||
clear_button.set_tooltip("Clear the console output");
|
||||
clear_button.on_click = [this](auto) {
|
||||
|
|
|
@ -70,8 +70,7 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
layout.set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto& animation_container = add<GUI::Widget>();
|
||||
animation_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
animation_container.set_preferred_size(0, 32);
|
||||
animation_container.set_fixed_height(32);
|
||||
auto& animation_layout = animation_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto& browser_image = animation_container.add<GUI::ImageWidget>();
|
||||
|
@ -80,29 +79,24 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
|
||||
auto& source_label = add<GUI::Label>(String::formatted("From: {}", url));
|
||||
source_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
source_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
source_label.set_preferred_size(0, 16);
|
||||
source_label.set_fixed_height(16);
|
||||
|
||||
m_progress_bar = add<GUI::ProgressBar>();
|
||||
m_progress_bar->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_progress_bar->set_preferred_size(0, 20);
|
||||
m_progress_bar->set_fixed_height(20);
|
||||
|
||||
m_progress_label = add<GUI::Label>();
|
||||
m_progress_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
m_progress_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_progress_label->set_preferred_size(0, 16);
|
||||
m_progress_label->set_fixed_height(16);
|
||||
|
||||
auto& destination_label = add<GUI::Label>(String::formatted("To: {}", m_destination_path));
|
||||
destination_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
destination_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
destination_label.set_preferred_size(0, 16);
|
||||
destination_label.set_fixed_height(16);
|
||||
|
||||
auto& button_container = add<GUI::Widget>();
|
||||
auto& button_container_layout = button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_container_layout.add_spacer();
|
||||
m_cancel_button = button_container.add<GUI::Button>("Cancel");
|
||||
m_cancel_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size(100, 22);
|
||||
m_cancel_button->set_fixed_size(100, 22);
|
||||
m_cancel_button->on_click = [this](auto) {
|
||||
bool success = m_download->stop();
|
||||
ASSERT(success);
|
||||
|
@ -111,8 +105,7 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
|
||||
m_close_button = button_container.add<GUI::Button>("OK");
|
||||
m_close_button->set_enabled(false);
|
||||
m_close_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_close_button->set_preferred_size(100, 22);
|
||||
m_close_button->set_fixed_size(100, 22);
|
||||
m_close_button->on_click = [this](auto) {
|
||||
window()->close();
|
||||
};
|
||||
|
|
|
@ -112,8 +112,7 @@ Tab::Tab(Type type)
|
|||
toolbar.add_action(*m_reload_action);
|
||||
|
||||
m_location_box = toolbar.add<GUI::TextBox>();
|
||||
m_location_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_location_box->set_preferred_size(0, 22);
|
||||
m_location_box->set_fixed_height(22);
|
||||
m_location_box->set_placeholder("Address");
|
||||
|
||||
m_location_box->on_return_pressed = [this] {
|
||||
|
@ -130,8 +129,7 @@ Tab::Tab(Type type)
|
|||
m_bookmark_button = toolbar.add<GUI::Button>();
|
||||
m_bookmark_button->set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
m_bookmark_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/bookmark-contour.png"));
|
||||
m_bookmark_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
m_bookmark_button->set_preferred_size(22, 22);
|
||||
m_bookmark_button->set_fixed_size(22, 22);
|
||||
|
||||
m_bookmark_button->on_click = [this](auto) {
|
||||
auto url = this->url().to_string();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue