mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
Minesweeper: Simplify resizing game window
Instead of propagating field size changes to main and manually calculating window size, use auto shrink to automatically resize the window after changes to the board.
This commit is contained in:
parent
76d17e6a8e
commit
5bb9af8297
3 changed files with 7 additions and 17 deletions
|
@ -47,20 +47,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_resizable(false);
|
||||
window->set_title("Minesweeper");
|
||||
window->resize(139, 177);
|
||||
window->set_auto_shrink(true);
|
||||
|
||||
auto widget = TRY(window->set_main_widget<GUI::Widget>());
|
||||
TRY(widget->load_from_gml(minesweeper_window_gml));
|
||||
|
||||
auto& separator = *widget->find_descendant_of_type_named<GUI::HorizontalSeparator>("separator");
|
||||
auto& container = *widget->find_descendant_of_type_named<GUI::Widget>("container");
|
||||
auto& flag_label = *widget->find_descendant_of_type_named<GUI::Label>("flag_label");
|
||||
auto& time_label = *widget->find_descendant_of_type_named<GUI::Label>("time_label");
|
||||
auto& face_button = *widget->find_descendant_of_type_named<GUI::Button>("face_button");
|
||||
auto field = TRY(Field::create(flag_label, time_label, face_button, [&](auto size) {
|
||||
size.set_height(size.height() + separator.height() + container.height());
|
||||
window->resize(size);
|
||||
}));
|
||||
auto field = TRY(Field::create(flag_label, time_label, face_button));
|
||||
TRY(widget->try_add_child(field));
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue