mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +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
|
@ -39,17 +39,16 @@ int main(int argc, char** argv)
|
|||
window->set_rect(100, 100, 240, 160);
|
||||
window->set_title("Hello World!");
|
||||
|
||||
auto main_widget = GUI::Widget::construct();
|
||||
window->set_main_widget(main_widget);
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
main_widget->set_background_color(Color::White);
|
||||
main_widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
main_widget->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
main_widget.set_background_color(Color::White);
|
||||
auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
layout.set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto label = main_widget->add<GUI::Label>();
|
||||
auto label = main_widget.add<GUI::Label>();
|
||||
label->set_text("Hello\nWorld!");
|
||||
|
||||
auto button = main_widget->add<GUI::Button>();
|
||||
auto button = main_widget.add<GUI::Button>();
|
||||
button->set_text("Good-bye");
|
||||
button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button->set_preferred_size(0, 20);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue