diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-30 01:23:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-30 01:36:41 +0100 |
commit | 7dc5a3ead86627d11b1bf8d243750e5e3390c067 (patch) | |
tree | bfcab42f5b00c5b368ac9ee4a288d7c0d9c4bd01 /DevTools | |
parent | b2bba5ce5c06d40e2fbcfff4cf1412532f93ae6b (diff) | |
download | serenity-7dc5a3ead86627d11b1bf8d243750e5e3390c067.zip |
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. :^)
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/HackStudio/Debugger/DisassemblyWidget.cpp | 4 | ||||
-rw-r--r-- | DevTools/HackStudio/EditorWrapper.cpp | 9 | ||||
-rw-r--r-- | DevTools/HackStudio/FindInFilesWidget.cpp | 7 | ||||
-rw-r--r-- | DevTools/HackStudio/Git/GitWidget.cpp | 12 | ||||
-rw-r--r-- | DevTools/HackStudio/HackStudioWidget.cpp | 22 | ||||
-rw-r--r-- | DevTools/HackStudio/Locator.cpp | 3 | ||||
-rw-r--r-- | DevTools/Inspector/main.cpp | 3 | ||||
-rw-r--r-- | DevTools/Profiler/ProfileTimelineWidget.cpp | 3 | ||||
-rw-r--r-- | DevTools/Profiler/main.cpp | 3 |
9 files changed, 23 insertions, 43 deletions
diff --git a/DevTools/HackStudio/Debugger/DisassemblyWidget.cpp b/DevTools/HackStudio/Debugger/DisassemblyWidget.cpp index 893d8dac82..9602d90392 100644 --- a/DevTools/HackStudio/Debugger/DisassemblyWidget.cpp +++ b/DevTools/HackStudio/Debugger/DisassemblyWidget.cpp @@ -48,11 +48,9 @@ DisassemblyWidget::DisassemblyWidget() m_top_container = add<GUI::Widget>(); m_top_container->set_layout<GUI::HorizontalBoxLayout>(); - m_top_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_top_container->set_preferred_size(0, 20); + m_top_container->set_fixed_height(20); m_function_name_label = m_top_container->add<GUI::Label>(""); - m_function_name_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); m_disassembly_view = add<GUI::TableView>(); diff --git a/DevTools/HackStudio/EditorWrapper.cpp b/DevTools/HackStudio/EditorWrapper.cpp index e2f51cfbc5..c21396f251 100644 --- a/DevTools/HackStudio/EditorWrapper.cpp +++ b/DevTools/HackStudio/EditorWrapper.cpp @@ -40,21 +40,18 @@ EditorWrapper::EditorWrapper() set_layout<GUI::VerticalBoxLayout>(); auto& label_wrapper = add<GUI::Widget>(); - label_wrapper.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - label_wrapper.set_preferred_size(0, 14); + label_wrapper.set_fixed_height(14); label_wrapper.set_fill_with_background_color(true); label_wrapper.set_layout<GUI::HorizontalBoxLayout>(); label_wrapper.layout()->set_margins({ 2, 0, 2, 0 }); m_filename_label = label_wrapper.add<GUI::Label>("(Untitled)"); m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); - m_filename_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_filename_label->set_preferred_size(0, 14); + m_filename_label->set_fixed_height(14); m_cursor_label = label_wrapper.add<GUI::Label>("(Cursor)"); m_cursor_label->set_text_alignment(Gfx::TextAlignment::CenterRight); - m_cursor_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_cursor_label->set_preferred_size(0, 14); + m_cursor_label->set_fixed_height(14); m_editor = add<Editor>(); m_editor->set_ruler_visible(true); diff --git a/DevTools/HackStudio/FindInFilesWidget.cpp b/DevTools/HackStudio/FindInFilesWidget.cpp index 8491379013..7c823ed42b 100644 --- a/DevTools/HackStudio/FindInFilesWidget.cpp +++ b/DevTools/HackStudio/FindInFilesWidget.cpp @@ -138,15 +138,12 @@ FindInFilesWidget::FindInFilesWidget() auto& top_container = add<Widget>(); top_container.set_layout<GUI::HorizontalBoxLayout>(); - top_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - top_container.set_preferred_size(0, 20); + top_container.set_fixed_height(20); m_textbox = top_container.add<GUI::TextBox>(); - m_textbox->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); m_button = top_container.add<GUI::Button>("Find in files"); - m_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - m_button->set_preferred_size(100, 0); + m_button->set_fixed_width(100); m_result_view = add<GUI::TableView>(); diff --git a/DevTools/HackStudio/Git/GitWidget.cpp b/DevTools/HackStudio/Git/GitWidget.cpp index 265eb6f98c..95ef6928ec 100644 --- a/DevTools/HackStudio/Git/GitWidget.cpp +++ b/DevTools/HackStudio/Git/GitWidget.cpp @@ -54,16 +54,14 @@ GitWidget::GitWidget(const LexicalPath& repo_root) auto& refresh_button = unstaged_header.add<GUI::Button>(); refresh_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png")); - refresh_button.set_preferred_size({ 16, 16 }); - refresh_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + refresh_button.set_fixed_size(16, 16); refresh_button.set_tooltip("refresh"); refresh_button.on_click = [this](int) { refresh(); }; auto& unstaged_label = unstaged_header.add<GUI::Label>(); unstaged_label.set_text("Unstaged"); - unstaged_header.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - unstaged_header.set_preferred_size(0, 20); + unstaged_header.set_fixed_height(20); m_unstaged_files = unstaged.add<GitFilesView>( [this](const auto& file) { stage_file(file); }, Gfx::Bitmap::load_from_file("/res/icons/16x16/plus.png").release_nonnull()); @@ -80,16 +78,14 @@ GitWidget::GitWidget(const LexicalPath& repo_root) auto& commit_button = staged_header.add<GUI::Button>(); commit_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/commit.png")); - commit_button.set_preferred_size({ 16, 16 }); - commit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + commit_button.set_fixed_size(16, 16); commit_button.set_tooltip("commit"); commit_button.on_click = [this](int) { commit(); }; auto& staged_label = staged_header.add<GUI::Label>(); staged_label.set_text("Staged"); - staged_header.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - staged_header.set_preferred_size(0, 20); + staged_header.set_fixed_height(20); m_staged_files = staged.add<GitFilesView>( [this](const auto& file) { unstage_file(file); }, Gfx::Bitmap::load_from_file("/res/icons/16x16/minus.png").release_nonnull()); diff --git a/DevTools/HackStudio/HackStudioWidget.cpp b/DevTools/HackStudio/HackStudioWidget.cpp index e373664110..588c3ee80b 100644 --- a/DevTools/HackStudio/HackStudioWidget.cpp +++ b/DevTools/HackStudio/HackStudioWidget.cpp @@ -100,8 +100,7 @@ HackStudioWidget::HackStudioWidget(const String& path_to_project) auto& outer_splitter = add<GUI::HorizontalSplitter>(); auto& left_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>(); - left_hand_splitter.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - left_hand_splitter.set_preferred_size(150, 0); + left_hand_splitter.set_fixed_width(150); create_project_tree_view(left_hand_splitter); m_project_tree_view_context_menu = create_project_tree_view_context_menu(); @@ -494,8 +493,8 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_terminal_action() void HackStudioWidget::reveal_action_tab(GUI::Widget& widget) { - if (m_action_tab_widget->preferred_size().height() < 200) - m_action_tab_widget->set_preferred_size(0, 200); + if (m_action_tab_widget->min_height() < 200) + m_action_tab_widget->set_fixed_height(200); m_action_tab_widget->set_active_widget(&widget); } @@ -617,7 +616,7 @@ void HackStudioWidget::run(TerminalWrapper& wrapper) void HackStudioWidget::hide_action_tabs() { - m_action_tab_widget->set_preferred_size(0, 24); + m_action_tab_widget->set_fixed_height(24); }; Project& HackStudioWidget::project() @@ -673,7 +672,7 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent) m_form_inner_container = parent.add<GUI::Widget>(); m_form_inner_container->set_layout<GUI::HorizontalBoxLayout>(); auto& form_widgets_toolbar = m_form_inner_container->add<GUI::ToolBar>(Orientation::Vertical, 26); - form_widgets_toolbar.set_preferred_size(38, 0); + form_widgets_toolbar.set_fixed_width(38); GUI::ActionGroup tool_actions; tool_actions.set_exclusive(true); @@ -710,8 +709,7 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent) m_form_editor_widget = form_editor_inner_splitter.add<FormEditorWidget>(); auto& form_editing_pane_container = form_editor_inner_splitter.add<GUI::VerticalSplitter>(); - form_editing_pane_container.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - form_editing_pane_container.set_preferred_size(190, 0); + form_editing_pane_container.set_fixed_width(190); form_editing_pane_container.set_layout<GUI::VerticalBoxLayout>(); auto add_properties_pane = [&](auto& text, auto& pane_widget) { @@ -721,8 +719,7 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent) label.set_fill_with_background_color(true); label.set_text_alignment(Gfx::TextAlignment::CenterLeft); label.set_font(Gfx::Font::default_bold_font()); - label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - label.set_preferred_size(0, 16); + label.set_fixed_height(16); wrapper.add_child(pane_widget); }; @@ -803,14 +800,13 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent) { m_action_tab_widget = parent.add<GUI::TabWidget>(); - m_action_tab_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_action_tab_widget->set_preferred_size(0, 24); + m_action_tab_widget->set_fixed_height(24); m_action_tab_widget->on_change = [this](auto&) { on_action_tab_change(); static bool first_time = true; if (!first_time) - m_action_tab_widget->set_preferred_size(0, 200); + m_action_tab_widget->set_fixed_height(200); first_time = false; }; diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp index f207df2985..50c16fde1e 100644 --- a/DevTools/HackStudio/Locator.cpp +++ b/DevTools/HackStudio/Locator.cpp @@ -69,8 +69,7 @@ private: Locator::Locator() { set_layout<GUI::VerticalBoxLayout>(); - set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - set_preferred_size(0, 20); + set_fixed_height(20); m_textbox = add<GUI::TextBox>(); m_textbox->on_change = [this] { update_suggestions(); diff --git a/DevTools/Inspector/main.cpp b/DevTools/Inspector/main.cpp index 0591313f80..2e30792068 100644 --- a/DevTools/Inspector/main.cpp +++ b/DevTools/Inspector/main.cpp @@ -128,8 +128,7 @@ int main(int argc, char** argv) auto& tree_view = splitter.add<GUI::TreeView>(); tree_view.set_model(remote_process.object_graph_model()); tree_view.set_activates_on_selection(true); - tree_view.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - tree_view.set_preferred_size(286, 0); + tree_view.set_fixed_width(286); auto& properties_tree_view = splitter.add<GUI::TreeView>(); properties_tree_view.set_editable(true); diff --git a/DevTools/Profiler/ProfileTimelineWidget.cpp b/DevTools/Profiler/ProfileTimelineWidget.cpp index 025af2c5f9..bbaf38973f 100644 --- a/DevTools/Profiler/ProfileTimelineWidget.cpp +++ b/DevTools/Profiler/ProfileTimelineWidget.cpp @@ -33,8 +33,7 @@ ProfileTimelineWidget::ProfileTimelineWidget(Profile& profile) { set_background_color(Color::White); set_fill_with_background_color(true); - set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - set_preferred_size(0, 80); + set_fixed_height(80); } ProfileTimelineWidget::~ProfileTimelineWidget() diff --git a/DevTools/Profiler/main.cpp b/DevTools/Profiler/main.cpp index 38f3ebc3ee..fb157979e8 100644 --- a/DevTools/Profiler/main.cpp +++ b/DevTools/Profiler/main.cpp @@ -176,8 +176,7 @@ static bool prompt_to_stop_profiling(pid_t pid, const String& process_name) }); auto& stop_button = widget.add<GUI::Button>("Stop"); - stop_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); - stop_button.set_preferred_size(140, 22); + stop_button.set_fixed_size(140, 22); stop_button.on_click = [&](auto) { GUI::Application::the()->quit(); }; |