mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:47:44 +00:00
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:
parent
7d0b59cb05
commit
3bf2f7a329
1 changed files with 19 additions and 1 deletions
|
@ -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.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -26,8 +26,10 @@
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
@ -88,6 +90,22 @@ private:
|
||||||
}
|
}
|
||||||
return builder.to_string();
|
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)
|
void Toolbar::add_action(Action& action)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue