mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +00:00
LibGUI: Some more convenience functions for constructing widgets
This patch adds two new API's: - WidgetType& GUI::Window::set_main_widget<WidgetType>(); This creates a new main widget for a window, assigns it, and returns it to you as a WidgetType&. - LayoutType& GUI::Widget::set_layout<LayoutType>(); Same basic idea, creates a new layout, assigns it, and returns it to you as a LayoutType&.
This commit is contained in:
parent
0cafbbf09c
commit
03e0ddce52
10 changed files with 66 additions and 60 deletions
|
@ -63,21 +63,20 @@ int main(int argc, char** argv)
|
|||
window->set_resizable(false);
|
||||
window->set_rect(window_rect);
|
||||
|
||||
auto outer_widget = GUI::Widget::construct();
|
||||
window->set_main_widget(outer_widget);
|
||||
outer_widget->set_fill_with_background_color(true);
|
||||
outer_widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
outer_widget->layout()->set_margins({ 8, 8, 8, 8 });
|
||||
auto& outer_widget = window->set_main_widget<GUI::Widget>();
|
||||
outer_widget.set_fill_with_background_color(true);
|
||||
outer_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
outer_widget.layout()->set_margins({ 8, 8, 8, 8 });
|
||||
|
||||
auto inner_widget = outer_widget->add<GUI::Widget>();
|
||||
inner_widget->set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
auto inner_widget = outer_widget.add<GUI::Widget>();
|
||||
inner_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
inner_widget->layout()->set_spacing(8);
|
||||
|
||||
auto left_outer_container = inner_widget->add<GUI::Widget>();
|
||||
left_outer_container->set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
left_outer_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto left_inner_container = left_outer_container->add<GUI::Widget>();
|
||||
left_inner_container->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
left_inner_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
left_inner_container->layout()->set_spacing(8);
|
||||
left_inner_container->set_preferred_size(0, 50);
|
||||
left_inner_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
|
@ -106,7 +105,7 @@ int main(int argc, char** argv)
|
|||
git_info_label->set_preferred_size(0, 11);
|
||||
|
||||
auto right_container = inner_widget->add<GUI::Widget>();
|
||||
right_container->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
right_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
auto icon_label = right_container->add<GUI::Label>();
|
||||
icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/buggie.png"));
|
||||
|
@ -114,7 +113,7 @@ int main(int argc, char** argv)
|
|||
icon_label->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
icon_label->set_preferred_size(icon_label->icon()->size());
|
||||
|
||||
auto quit_button = outer_widget->add<GUI::Button>();
|
||||
auto quit_button = outer_widget.add<GUI::Button>();
|
||||
quit_button->set_text("Okay");
|
||||
quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
quit_button->set_preferred_size(100, 20);
|
||||
|
|
|
@ -75,13 +75,13 @@ int main(int argc, char** argv)
|
|||
auto window = GUI::Window::construct();
|
||||
window->set_rect(100, 100, 640, 480);
|
||||
|
||||
auto widget = GUI::Widget::construct();
|
||||
widget->set_fill_with_background_color(true);
|
||||
widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
widget->layout()->set_spacing(0);
|
||||
auto& widget = window->set_main_widget<GUI::Widget>();
|
||||
widget.set_fill_with_background_color(true);
|
||||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = widget->add<GUI::ToolBar>();
|
||||
auto html_widget = widget->add<HtmlView>();
|
||||
auto toolbar = widget.add<GUI::ToolBar>();
|
||||
auto html_widget = widget.add<HtmlView>();
|
||||
|
||||
History<URL> history;
|
||||
|
||||
|
@ -151,7 +151,7 @@ int main(int argc, char** argv)
|
|||
location_box->set_focus(true);
|
||||
});
|
||||
|
||||
auto statusbar = widget->add<GUI::StatusBar>();
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
html_widget->on_link_hover = [&](auto& href) {
|
||||
statusbar->set_text(href);
|
||||
|
@ -200,8 +200,7 @@ int main(int argc, char** argv)
|
|||
dom_inspector_window = GUI::Window::construct();
|
||||
dom_inspector_window->set_rect(100, 100, 300, 500);
|
||||
dom_inspector_window->set_title("DOM inspector");
|
||||
auto dom_inspector_widget = InspectorWidget::construct();
|
||||
dom_inspector_window->set_main_widget(dom_inspector_widget);
|
||||
dom_inspector_window->set_main_widget<InspectorWidget>();
|
||||
}
|
||||
auto* inspector_widget = static_cast<InspectorWidget*>(dom_inspector_window->main_widget());
|
||||
inspector_widget->set_document(html_widget->document());
|
||||
|
@ -244,7 +243,6 @@ int main(int argc, char** argv)
|
|||
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
|
||||
|
||||
window->set_title("Browser");
|
||||
window->set_main_widget(widget);
|
||||
window->show();
|
||||
|
||||
URL url_to_load = home_url;
|
||||
|
|
|
@ -60,8 +60,7 @@ int main(int argc, char** argv)
|
|||
window->set_resizable(false);
|
||||
window->set_rect({ 300, 200, 254, 213 });
|
||||
|
||||
auto calc_widget = CalculatorWidget::construct();
|
||||
window->set_main_widget(calc_widget);
|
||||
window->set_main_widget<CalculatorWidget>();
|
||||
|
||||
window->show();
|
||||
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calculator.png"));
|
||||
|
|
|
@ -57,22 +57,21 @@ int main(int argc, char** argv)
|
|||
window->set_rect(100, 100, 800, 500);
|
||||
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-chanviewer.png"));
|
||||
|
||||
auto widget = GUI::Widget::construct();
|
||||
window->set_main_widget(widget);
|
||||
widget->set_fill_with_background_color(true);
|
||||
widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
auto& widget = window->set_main_widget<GUI::Widget>();
|
||||
widget.set_fill_with_background_color(true);
|
||||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
auto board_combo = widget->add<GUI::ComboBox>();
|
||||
auto board_combo = widget.add<GUI::ComboBox>();
|
||||
board_combo->set_only_allow_values_from_model(true);
|
||||
board_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
board_combo->set_preferred_size(0, 20);
|
||||
board_combo->set_model(BoardListModel::create());
|
||||
|
||||
auto catalog_view = widget->add<GUI::TableView>();
|
||||
auto catalog_view = widget.add<GUI::TableView>();
|
||||
catalog_view->set_model(ThreadCatalogModel::create());
|
||||
auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view->model());
|
||||
|
||||
auto statusbar = widget->add<GUI::StatusBar>();
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
board_combo->on_change = [&] (auto&, const GUI::ModelIndex& index) {
|
||||
auto selected_board = board_combo->model()->data(index, GUI::Model::Role::Custom);
|
||||
|
|
|
@ -43,16 +43,15 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
auto file_path = FileSystemPath(path);
|
||||
ASSERT(file_path.is_valid());
|
||||
|
||||
auto main_widget = GUI::Widget::construct();
|
||||
main_widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
main_widget->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||
main_widget.set_layout(make<GUI::VerticalBoxLayout>());
|
||||
main_widget.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
|
||||
set_main_widget(main_widget);
|
||||
set_rect({ 0, 0, 360, 420 });
|
||||
set_resizable(false);
|
||||
|
||||
auto tab_widget = main_widget->add<GUI::TabWidget>();
|
||||
auto tab_widget = main_widget.add<GUI::TabWidget>();
|
||||
|
||||
auto general_tab = tab_widget->add_tab<GUI::Widget>("General");
|
||||
general_tab->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
|
@ -131,8 +130,8 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
|
||||
general_tab->layout()->add_spacer();
|
||||
|
||||
auto button_widget = main_widget->add<GUI::Widget>();
|
||||
button_widget->set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
auto button_widget = main_widget.add<GUI::Widget>();
|
||||
button_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button_widget->set_preferred_size(0, 24);
|
||||
button_widget->layout()->set_spacing(5);
|
||||
|
|
|
@ -92,12 +92,12 @@ int main(int argc, char** argv)
|
|||
auto heigth = config->read_num_entry("Window", "Heigth", 480);
|
||||
window->set_rect({ left, top, width, heigth });
|
||||
|
||||
auto widget = GUI::Widget::construct();
|
||||
widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
widget->layout()->set_spacing(0);
|
||||
auto& widget = window->set_main_widget<GUI::Widget>();
|
||||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto main_toolbar = widget->add<GUI::ToolBar>();
|
||||
auto location_toolbar = widget->add<GUI::ToolBar>();
|
||||
auto main_toolbar = widget.add<GUI::ToolBar>();
|
||||
auto location_toolbar = widget.add<GUI::ToolBar>();
|
||||
location_toolbar->layout()->set_margins({ 6, 3, 6, 3 });
|
||||
location_toolbar->set_preferred_size(0, 25);
|
||||
|
||||
|
@ -106,7 +106,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto location_textbox = location_toolbar->add<GUI::TextBox>();
|
||||
|
||||
auto splitter = widget->add<GUI::HorizontalSplitter>();
|
||||
auto splitter = widget.add<GUI::HorizontalSplitter>();
|
||||
auto tree_view = splitter->add<GUI::TreeView>();
|
||||
auto directories_model = GUI::FileSystemModel::create("/", GUI::FileSystemModel::Mode::DirectoriesOnly);
|
||||
tree_view->set_model(directories_model);
|
||||
|
@ -122,7 +122,7 @@ int main(int argc, char** argv)
|
|||
tree_view->set_preferred_size(150, 0);
|
||||
auto directory_view = splitter->add<DirectoryView>();
|
||||
|
||||
auto statusbar = widget->add<GUI::StatusBar>();
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
auto progressbar = statusbar->add<GUI::ProgressBar>();
|
||||
progressbar->set_caption("Generating thumbnails: ");
|
||||
|
@ -641,7 +641,6 @@ int main(int argc, char** argv)
|
|||
directory_view->open(initial_location);
|
||||
directory_view->set_focus(true);
|
||||
|
||||
window->set_main_widget(widget);
|
||||
window->show();
|
||||
|
||||
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-folder.png"));
|
||||
|
|
|
@ -78,13 +78,13 @@ int main(int argc, char* argv[])
|
|||
window->set_title("Help");
|
||||
window->set_rect(300, 200, 570, 500);
|
||||
|
||||
auto widget = GUI::Widget::construct();
|
||||
widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
widget->layout()->set_spacing(0);
|
||||
auto& widget = window->set_main_widget<GUI::Widget>();
|
||||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = widget->add<GUI::ToolBar>();
|
||||
auto toolbar = widget.add<GUI::ToolBar>();
|
||||
|
||||
auto splitter = widget->add<GUI::HorizontalSplitter>();
|
||||
auto splitter = widget.add<GUI::HorizontalSplitter>();
|
||||
|
||||
auto model = ManualModel::create();
|
||||
|
||||
|
@ -195,7 +195,6 @@ int main(int argc, char* argv[])
|
|||
|
||||
app.set_menubar(move(menubar));
|
||||
|
||||
window->set_main_widget(widget);
|
||||
window->set_focused_widget(tree_view);
|
||||
window->show();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue