summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/MessageBox.cpp
diff options
context:
space:
mode:
authorTimothy <timmot@users.noreply.github.com>2021-07-08 01:36:34 +1000
committerAndreas Kling <kling@serenityos.org>2021-07-22 22:38:25 +0200
commitccd19d464eed2b5915f91c3d6e3e368fb08638c0 (patch)
treefac7f3e2912611753cefde9d9f401435483864a0 /Userland/Libraries/LibGUI/MessageBox.cpp
parentcc45ccbd9bec179c7897d4178e1b1f0af04b5ce9 (diff)
downloadserenity-ccd19d464eed2b5915f91c3d6e3e368fb08638c0.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGUI/MessageBox.cpp')
-rw-r--r--Userland/Libraries/LibGUI/MessageBox.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/MessageBox.cpp b/Userland/Libraries/LibGUI/MessageBox.cpp
index 2b0a59a5e0..c57c96d251 100644
--- a/Userland/Libraries/LibGUI/MessageBox.cpp
+++ b/Userland/Libraries/LibGUI/MessageBox.cpp
@@ -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);
}