mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +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
1 changed files with 5 additions and 2 deletions
|
@ -82,6 +82,9 @@ void MessageBox::build()
|
|||
auto& widget = set_main_widget<Widget>();
|
||||
|
||||
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;
|
||||
|
||||
widget.set_layout<VerticalBoxLayout>();
|
||||
|
@ -105,7 +108,7 @@ void MessageBox::build()
|
|||
}
|
||||
|
||||
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)
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue