mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +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
|
@ -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"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue