mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +00:00
Userspace: Use Core::Object::add() when building interfaces
This commit is contained in:
parent
7ec758773c
commit
3d20da9ee4
87 changed files with 403 additions and 438 deletions
|
@ -28,10 +28,10 @@
|
|||
#include <AK/HashTable.h>
|
||||
#include <AK/Queue.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -72,8 +72,7 @@ public:
|
|||
virtual void mousedown_event(GUI::MouseEvent& event) override
|
||||
{
|
||||
if (event.button() == GUI::MouseButton::Right || event.button() == GUI::MouseButton::Left) {
|
||||
if (event.buttons() == (GUI::MouseButton::Right | GUI::MouseButton::Left) ||
|
||||
m_square.field->is_single_chording()) {
|
||||
if (event.buttons() == (GUI::MouseButton::Right | GUI::MouseButton::Left) || m_square.field->is_single_chording()) {
|
||||
m_chord = true;
|
||||
m_square.field->set_chord_preview(m_square, true);
|
||||
}
|
||||
|
@ -120,15 +119,14 @@ public:
|
|||
bool m_chord { false };
|
||||
};
|
||||
|
||||
Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, GUI::Widget* parent, Function<void(Gfx::Size)> on_size_changed)
|
||||
: GUI::Frame(parent)
|
||||
, m_face_button(face_button)
|
||||
Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, Function<void(Gfx::Size)> on_size_changed)
|
||||
: m_face_button(face_button)
|
||||
, m_flag_label(flag_label)
|
||||
, m_time_label(time_label)
|
||||
, m_on_size_changed(move(on_size_changed))
|
||||
{
|
||||
srand(time(nullptr));
|
||||
m_timer = Core::Timer::construct();
|
||||
m_timer = add<Core::Timer>();
|
||||
m_timer->on_timeout = [this] {
|
||||
++m_time_elapsed;
|
||||
m_time_label.set_text(String::format("%u.%u", m_time_elapsed / 10, m_time_elapsed % 10));
|
||||
|
@ -511,7 +509,8 @@ void Field::set_field_size(int rows, int columns, int mine_count)
|
|||
m_on_size_changed(preferred_size());
|
||||
}
|
||||
|
||||
void Field::set_single_chording(bool enabled) {
|
||||
void Field::set_single_chording(bool enabled)
|
||||
{
|
||||
auto config = Core::ConfigFile::get_for_app("Minesweeper");
|
||||
m_single_chording = enabled;
|
||||
config->write_bool_entry("Minesweeper", "SingleChording", m_single_chording);
|
||||
|
|
|
@ -60,7 +60,7 @@ class Field final : public GUI::Frame {
|
|||
friend class Square;
|
||||
friend class SquareLabel;
|
||||
public:
|
||||
Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, GUI::Widget* parent, Function<void(Gfx::Size)> on_size_changed);
|
||||
Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, Function<void(Gfx::Size)> on_size_changed);
|
||||
virtual ~Field() override;
|
||||
|
||||
int rows() const { return m_rows; }
|
||||
|
|
|
@ -62,22 +62,22 @@ int main(int argc, char** argv)
|
|||
widget->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
widget->layout()->set_spacing(0);
|
||||
|
||||
auto container = GUI::Widget::construct(widget.ptr());
|
||||
auto container = widget->add<GUI::Widget>();
|
||||
container->set_fill_with_background_color(true);
|
||||
container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
container->set_preferred_size(0, 36);
|
||||
container->set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
auto flag_icon_label = GUI::Label::construct(container);
|
||||
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_label = GUI::Label::construct(container);
|
||||
auto face_button = GUI::Button::construct(container);
|
||||
auto flag_label = container->add<GUI::Label>();
|
||||
auto face_button = container->add<GUI::Button>();
|
||||
face_button->set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
face_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
face_button->set_preferred_size(36, 0);
|
||||
auto time_icon_label = GUI::Label::construct(container);
|
||||
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_label = GUI::Label::construct(container);
|
||||
auto field = Field::construct(*flag_label, *time_label, *face_button, widget, [&](auto size) {
|
||||
auto time_label = container->add<GUI::Label>();
|
||||
auto field = widget->add<Field>(*flag_label, *time_label, *face_button, [&](auto size) {
|
||||
size.set_height(size.height() + container->preferred_size().height());
|
||||
window->resize(size);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue