mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
LibGUI: Relayout Breadcrumbbar on font change
This commit is contained in:
parent
dd607fc619
commit
be3a9048be
2 changed files with 33 additions and 15 deletions
|
@ -100,21 +100,14 @@ void Breadcrumbbar::append_segment(DeprecatedString text, Gfx::Bitmap const* ico
|
||||||
on_segment_drag_enter(index, event);
|
on_segment_drag_enter(index, event);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto button_text_width = button.font().width(text);
|
m_segments.append(Segment {
|
||||||
auto icon_width = icon ? icon->width() : 0;
|
.icon = icon,
|
||||||
auto icon_padding = icon ? 4 : 0;
|
.text = move(text),
|
||||||
|
.data = move(data),
|
||||||
int const max_button_width = 100;
|
.width = 0,
|
||||||
|
.shrunken_width = 0,
|
||||||
auto button_width = min(button_text_width + icon_width + icon_padding + 16, max_button_width);
|
.button = button.make_weak_ptr<GUI::Button>(),
|
||||||
auto shrunken_width = icon_width + icon_padding + (icon ? 4 : 16);
|
});
|
||||||
|
|
||||||
button.set_max_size(static_cast<int>(ceilf(button_width)), 16 + 8);
|
|
||||||
button.set_min_size(shrunken_width, 16 + 8);
|
|
||||||
|
|
||||||
Segment segment { icon, text, data, static_cast<int>(ceilf(button_width)), shrunken_width, button.make_weak_ptr<GUI::Button>() };
|
|
||||||
|
|
||||||
m_segments.append(move(segment));
|
|
||||||
relayout();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +163,30 @@ void Breadcrumbbar::resize_event(ResizeEvent&)
|
||||||
relayout();
|
relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Breadcrumbbar::did_change_font()
|
||||||
|
{
|
||||||
|
Widget::did_change_font();
|
||||||
|
relayout();
|
||||||
|
}
|
||||||
|
|
||||||
void Breadcrumbbar::relayout()
|
void Breadcrumbbar::relayout()
|
||||||
{
|
{
|
||||||
|
for (auto& segment : m_segments) {
|
||||||
|
VERIFY(segment.button);
|
||||||
|
auto& button = *segment.button;
|
||||||
|
auto button_text_width = button.font().width(segment.text);
|
||||||
|
auto icon_width = button.icon() ? button.icon()->width() : 0;
|
||||||
|
auto icon_padding = button.icon() ? 4 : 0;
|
||||||
|
|
||||||
|
int const max_button_width = 100;
|
||||||
|
|
||||||
|
segment.width = static_cast<int>(ceilf(min(button_text_width + icon_width + icon_padding + 16, max_button_width)));
|
||||||
|
segment.shrunken_width = icon_width + icon_padding + (button.icon() ? 4 : 16);
|
||||||
|
|
||||||
|
button.set_max_size(segment.width, 16 + 8);
|
||||||
|
button.set_min_size(segment.shrunken_width, 16 + 8);
|
||||||
|
}
|
||||||
|
|
||||||
auto remaining_width = 0;
|
auto remaining_width = 0;
|
||||||
|
|
||||||
for (auto& segment : m_segments)
|
for (auto& segment : m_segments)
|
||||||
|
|
|
@ -35,6 +35,9 @@ public:
|
||||||
Function<void(size_t index, DragEvent&)> on_segment_drag_enter;
|
Function<void(size_t index, DragEvent&)> on_segment_drag_enter;
|
||||||
Function<void(MouseEvent& event)> on_doubleclick;
|
Function<void(MouseEvent& event)> on_doubleclick;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void did_change_font() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Breadcrumbbar();
|
Breadcrumbbar();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue