mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +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
2 changed files with 17 additions and 6 deletions
|
@ -33,17 +33,23 @@ REGISTER_WIDGET(GUI, BreadcrumbBar)
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
// FIXME: Move this somewhere else
|
class BreadcrumbButton : public GUI::Button {
|
||||||
class UnuncheckableButton : public GUI::Button {
|
C_OBJECT(BreadcrumbButton);
|
||||||
C_OBJECT(UnuncheckableButton);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~UnuncheckableButton() override { }
|
virtual ~BreadcrumbButton() override { }
|
||||||
|
|
||||||
virtual bool is_uncheckable() const override { return false; }
|
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:
|
private:
|
||||||
UnuncheckableButton() { }
|
BreadcrumbButton() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
BreadcrumbBar::BreadcrumbBar()
|
BreadcrumbBar::BreadcrumbBar()
|
||||||
|
@ -64,7 +70,7 @@ void BreadcrumbBar::clear_segments()
|
||||||
|
|
||||||
void BreadcrumbBar::append_segment(const String& text, const Gfx::Bitmap* icon, const String& data)
|
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_button_style(Gfx::ButtonStyle::CoolBar);
|
||||||
button.set_text(text);
|
button.set_text(text);
|
||||||
button.set_icon(icon);
|
button.set_icon(icon);
|
||||||
|
@ -75,6 +81,10 @@ void BreadcrumbBar::append_segment(const String& text, const Gfx::Bitmap* icon,
|
||||||
if (on_segment_click)
|
if (on_segment_click)
|
||||||
on_segment_click(index);
|
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 button_text_width = button.font().width(text);
|
||||||
auto icon_width = icon ? icon->width() : 0;
|
auto icon_width = icon ? icon->width() : 0;
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
Optional<size_t> selected_segment() const { return m_selected_segment; }
|
Optional<size_t> selected_segment() const { return m_selected_segment; }
|
||||||
|
|
||||||
Function<void(size_t index)> on_segment_click;
|
Function<void(size_t index)> on_segment_click;
|
||||||
|
Function<void(size_t index, DropEvent&)> on_drop;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BreadcrumbBar();
|
BreadcrumbBar();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue