diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-05-05 12:52:17 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-05 21:38:45 +0200 |
commit | b2576b7e457496d27d9a37ffe7cbd9e2c98abab9 (patch) | |
tree | afcda2b69a93e0e7ecb15428cd6a5129bde49389 /Userland | |
parent | 59193dd6b3c5c065790f03a8e1154af2b45139ab (diff) | |
download | serenity-b2576b7e457496d27d9a37ffe7cbd9e2c98abab9.zip |
Solitaire: Add a GUI::Statusbar to the Solitaire window
This will display the score (instead of updating the window title) and
any hovered action text.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Games/Solitaire/Solitaire.gml | 4 | ||||
-rw-r--r-- | Userland/Games/Solitaire/main.cpp | 22 |
2 files changed, 22 insertions, 4 deletions
diff --git a/Userland/Games/Solitaire/Solitaire.gml b/Userland/Games/Solitaire/Solitaire.gml index d72f90c547..bd9ace9971 100644 --- a/Userland/Games/Solitaire/Solitaire.gml +++ b/Userland/Games/Solitaire/Solitaire.gml @@ -9,4 +9,8 @@ fill_with_background_color: true background_color: "green" } + + @GUI::Statusbar { + name: "statusbar" + } } diff --git a/Userland/Games/Solitaire/main.cpp b/Userland/Games/Solitaire/main.cpp index d2c0935d1e..b6c0610537 100644 --- a/Userland/Games/Solitaire/main.cpp +++ b/Userland/Games/Solitaire/main.cpp @@ -11,6 +11,7 @@ #include <LibGUI/Icon.h> #include <LibGUI/Menu.h> #include <LibGUI/Menubar.h> +#include <LibGUI/Statusbar.h> #include <LibGUI/Window.h> #include <stdio.h> #include <unistd.h> @@ -36,9 +37,7 @@ int main(int argc, char** argv) } auto window = GUI::Window::construct(); - - window->set_resizable(false); - window->resize(Solitaire::Game::width, Solitaire::Game::height); + window->set_title("Solitaire"); auto& widget = window->set_main_widget<GUI::Widget>(); widget.load_from_gml(solitaire_gml); @@ -46,8 +45,21 @@ int main(int argc, char** argv) auto& game = *widget.find_descendant_of_type_named<Solitaire::Game>("game"); game.set_focus(true); + auto& statusbar = *widget.find_descendant_of_type_named<GUI::Statusbar>("statusbar"); + + app->on_action_enter = [&](GUI::Action& action) { + auto text = action.status_tip(); + if (text.is_empty()) + text = Gfx::parse_ampersand_string(action.text()); + statusbar.set_override_text(move(text)); + }; + + app->on_action_leave = [&](GUI::Action&) { + statusbar.set_override_text({}); + }; + game.on_score_update = [&](uint32_t score) { - window->set_title(String::formatted("Score: {} - Solitaire", score)); + statusbar.set_text(String::formatted("Score: {}", score)); }; auto menubar = GUI::Menubar::construct(); @@ -62,6 +74,8 @@ int main(int argc, char** argv) auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Solitaire", app_icon, window)); + window->set_resizable(false); + window->resize(Solitaire::Game::width, Solitaire::Game::height + statusbar.max_height()); window->set_menubar(move(menubar)); window->set_icon(app_icon.bitmap_for_size(16)); window->show(); |