mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibGUI: Handle multiple lines of text in MessageBox
The total height of text is calculated from the glyph height, the number of lines, and a padding modifier.
This commit is contained in:
parent
cc45ccbd9b
commit
ccd19d464e
Notes:
sideshowbarker
2024-07-18 08:32:17 +09:00
Author: https://github.com/timmot Commit: https://github.com/SerenityOS/serenity/commit/ccd19d464ee Pull-request: https://github.com/SerenityOS/serenity/pull/8529 Reviewed-by: https://github.com/luk1337
|
@ -82,6 +82,9 @@ void MessageBox::build()
|
||||||
auto& widget = set_main_widget<Widget>();
|
auto& widget = set_main_widget<Widget>();
|
||||||
|
|
||||||
int text_width = widget.font().width(m_text);
|
int text_width = widget.font().width(m_text);
|
||||||
|
auto number_of_lines = m_text.split('\n').size();
|
||||||
|
int padded_text_height = widget.font().glyph_height() * 1.6;
|
||||||
|
int total_text_height = number_of_lines * padded_text_height;
|
||||||
int icon_width = 0;
|
int icon_width = 0;
|
||||||
|
|
||||||
widget.set_layout<VerticalBoxLayout>();
|
widget.set_layout<VerticalBoxLayout>();
|
||||||
|
@ -105,7 +108,7 @@ void MessageBox::build()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& label = message_container.add<Label>(m_text);
|
auto& label = message_container.add<Label>(m_text);
|
||||||
label.set_fixed_height(16);
|
label.set_fixed_height(total_text_height);
|
||||||
if (m_type != Type::None)
|
if (m_type != Type::None)
|
||||||
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||||
|
|
||||||
|
@ -141,7 +144,7 @@ void MessageBox::build()
|
||||||
int width = (button_count * button_width) + ((button_count - 1) * button_container.layout()->spacing()) + 32;
|
int width = (button_count * button_width) + ((button_count - 1) * button_container.layout()->spacing()) + 32;
|
||||||
width = max(width, text_width + icon_width + 56);
|
width = max(width, text_width + icon_width + 56);
|
||||||
|
|
||||||
set_rect(x(), y(), width, 96);
|
set_rect(x(), y(), width, 80 + label.max_height());
|
||||||
set_resizable(false);
|
set_resizable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue