diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-08 18:53:37 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-08 19:51:44 +0100 |
commit | 6159630fa001e8dcb4b4a54fd3a98d80c0148ecd (patch) | |
tree | 0c1cbb593c66b5a6529fa859edfd1673f93b4b30 | |
parent | c762a0c4d68bfc7de9dc4dea9afdad6870bd4d58 (diff) | |
download | serenity-6159630fa001e8dcb4b4a54fd3a98d80c0148ecd.zip |
LibGUI: Make BreadcrumbBar report drop events
Dropping something on a breadcrumb segment button will now fire the
BreadcrumbBar::on_drop hook.
Fixes #4792.
-rw-r--r-- | Libraries/LibGUI/BreadcrumbBar.cpp | 22 | ||||
-rw-r--r-- | Libraries/LibGUI/BreadcrumbBar.h | 1 |
2 files changed, 17 insertions, 6 deletions
diff --git a/Libraries/LibGUI/BreadcrumbBar.cpp b/Libraries/LibGUI/BreadcrumbBar.cpp index 3670ad59ce..bf9c54f2e4 100644 --- a/Libraries/LibGUI/BreadcrumbBar.cpp +++ b/Libraries/LibGUI/BreadcrumbBar.cpp @@ -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; diff --git a/Libraries/LibGUI/BreadcrumbBar.h b/Libraries/LibGUI/BreadcrumbBar.h index b6c0d46319..4ec6556c91 100644 --- a/Libraries/LibGUI/BreadcrumbBar.h +++ b/Libraries/LibGUI/BreadcrumbBar.h @@ -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(); |