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:
Andreas Kling 2021-01-08 18:53:37 +01:00
parent c762a0c4d6
commit 6159630fa0
Notes: sideshowbarker 2024-07-19 00:02:54 +09:00
2 changed files with 17 additions and 6 deletions

View file

@ -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;

View file

@ -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();