LibGUI: Make GUI::Toolbar buttons generate ActionEnter and ActionLeave

Now you'll get the same event whether you hover an action in a menu
or in a toolbar. :^)
This commit is contained in:
Andreas Kling 2021-04-17 18:22:07 +02:00
parent 7d0b59cb05
commit 3bf2f7a329
Notes: sideshowbarker 2024-07-18 19:30:00 +09:00

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -26,8 +26,10 @@
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/EventLoop.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/Painter.h>
@ -88,6 +90,22 @@ private:
}
return builder.to_string();
}
virtual void enter_event(Core::Event& event) override
{
auto* app = Application::the();
if (app && action())
Core::EventLoop::current().post_event(*app, make<ActionEvent>(ActionEvent::Type::ActionEnter, *action()));
return Button::enter_event(event);
}
virtual void leave_event(Core::Event& event) override
{
auto* app = Application::the();
if (app && action())
Core::EventLoop::current().post_event(*app, make<ActionEvent>(ActionEvent::Type::ActionLeave, *action()));
return Button::leave_event(event);
}
};
void Toolbar::add_action(Action& action)