mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibGUI: Make BreadcrumbBar report drop events
Dropping something on a breadcrumb segment button will now fire the BreadcrumbBar::on_drop hook. Fixes #4792.
This commit is contained in:
parent
c762a0c4d6
commit
6159630fa0
Notes:
sideshowbarker
2024-07-19 00:02:54 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6159630fa00
2 changed files with 17 additions and 6 deletions
|
@ -33,17 +33,23 @@ REGISTER_WIDGET(GUI, BreadcrumbBar)
|
|||
|
||||
namespace GUI {
|
||||
|
||||
// FIXME: Move this somewhere else
|
||||
class UnuncheckableButton : public GUI::Button {
|
||||
C_OBJECT(UnuncheckableButton);
|
||||
class BreadcrumbButton : public GUI::Button {
|
||||
C_OBJECT(BreadcrumbButton);
|
||||
|
||||
public:
|
||||
virtual ~UnuncheckableButton() override { }
|
||||
virtual ~BreadcrumbButton() override { }
|
||||
|
||||
virtual bool is_uncheckable() const override { return false; }
|
||||
virtual void drop_event(DropEvent& event) override
|
||||
{
|
||||
if (on_drop)
|
||||
on_drop(event);
|
||||
}
|
||||
|
||||
Function<void(DropEvent&)> on_drop;
|
||||
|
||||
private:
|
||||
UnuncheckableButton() { }
|
||||
BreadcrumbButton() { }
|
||||
};
|
||||
|
||||
BreadcrumbBar::BreadcrumbBar()
|
||||
|
@ -64,7 +70,7 @@ void BreadcrumbBar::clear_segments()
|
|||
|
||||
void BreadcrumbBar::append_segment(const String& text, const Gfx::Bitmap* icon, const String& data)
|
||||
{
|
||||
auto& button = add<UnuncheckableButton>();
|
||||
auto& button = add<BreadcrumbButton>();
|
||||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
button.set_text(text);
|
||||
button.set_icon(icon);
|
||||
|
@ -75,6 +81,10 @@ void BreadcrumbBar::append_segment(const String& text, const Gfx::Bitmap* icon,
|
|||
if (on_segment_click)
|
||||
on_segment_click(index);
|
||||
};
|
||||
button.on_drop = [this, index = m_segments.size()](auto& drop_event) {
|
||||
if (on_drop)
|
||||
on_drop(index, drop_event);
|
||||
};
|
||||
|
||||
auto button_text_width = button.font().width(text);
|
||||
auto icon_width = icon ? icon->width() : 0;
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
Optional<size_t> selected_segment() const { return m_selected_segment; }
|
||||
|
||||
Function<void(size_t index)> on_segment_click;
|
||||
Function<void(size_t index, DropEvent&)> on_drop;
|
||||
|
||||
private:
|
||||
BreadcrumbBar();
|
||||
|
|
Loading…
Reference in a new issue