Minesweeper: Replace Label with Image component to show flag and timer

This commit is contained in:
Hüseyin ASLITÜRK 2020-06-13 12:33:25 +03:00 committed by Andreas Kling
parent 0a2dc1f5c0
commit d0411f3756
Notes: sideshowbarker 2024-07-19 05:34:35 +09:00

View file

@ -31,6 +31,7 @@
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h> #include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h> #include <LibGUI/Button.h>
#include <LibGUI/Image.h>
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/Menu.h> #include <LibGUI/Menu.h>
#include <LibGUI/MenuBar.h> #include <LibGUI/MenuBar.h>
@ -65,15 +66,19 @@ int main(int argc, char** argv)
container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
container.set_preferred_size(0, 36); container.set_preferred_size(0, 36);
container.set_layout<GUI::HorizontalBoxLayout>(); container.set_layout<GUI::HorizontalBoxLayout>();
auto& flag_icon_label = container.add<GUI::Label>();
flag_icon_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/flag.png")); auto& flag_image = container.add<GUI::Image>();
flag_image.load_from_file("/res/icons/minesweeper/flag.png");
auto& flag_label = container.add<GUI::Label>(); auto& flag_label = container.add<GUI::Label>();
auto& face_button = container.add<GUI::Button>(); auto& face_button = container.add<GUI::Button>();
face_button.set_button_style(Gfx::ButtonStyle::CoolBar); face_button.set_button_style(Gfx::ButtonStyle::CoolBar);
face_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); face_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
face_button.set_preferred_size(36, 0); face_button.set_preferred_size(36, 0);
auto& time_icon_label = container.add<GUI::Label>();
time_icon_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/minesweeper/timer.png")); auto& time_image = container.add<GUI::Image>();
time_image.load_from_file("/res/icons/minesweeper/timer.png");
auto& time_label = container.add<GUI::Label>(); auto& time_label = container.add<GUI::Label>();
auto& field = widget.add<Field>(flag_label, time_label, face_button, [&](auto size) { auto& field = widget.add<Field>(flag_label, time_label, face_button, [&](auto size) {
size.set_height(size.height() + container.preferred_size().height()); size.set_height(size.height() + container.preferred_size().height());