summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2023-04-16 16:01:34 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-18 10:05:21 +0200
commit9c2bcffe83ae92c8c710e7ed34dd4ee82710a76a (patch)
tree84031896efb17f0fcade5257ac5fc435d6b3be7d /Userland
parent7304556ff2a6cff6f606a83f3f85061ba2f0a5ad (diff)
downloadserenity-9c2bcffe83ae92c8c710e7ed34dd4ee82710a76a.zip
LibGUI: Improve calculated_min_size() for single-line TextEditor
TextBox now shrinks to fit the current font based on preferred line height, maintaining its historical minimum size of 40x22
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/TextBox.cpp4
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp5
2 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGUI/TextBox.cpp b/Userland/Libraries/LibGUI/TextBox.cpp
index 3ed50ff81f..139671cffc 100644
--- a/Userland/Libraries/LibGUI/TextBox.cpp
+++ b/Userland/Libraries/LibGUI/TextBox.cpp
@@ -22,8 +22,8 @@ namespace GUI {
TextBox::TextBox()
: TextEditor(TextEditor::SingleLine)
{
- set_min_size({ 40, 22 });
- set_preferred_size({ SpecialDimension::OpportunisticGrow, 22 });
+ set_min_size({ SpecialDimension::Shrink });
+ set_preferred_size({ SpecialDimension::OpportunisticGrow, SpecialDimension::Shrink });
}
void TextBox::keydown_event(GUI::KeyEvent& event)
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 29df2c4c68..0981534a44 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -893,8 +893,11 @@ Optional<UISize> TextEditor::calculated_min_size() const
{
if (is_multi_line())
return AbstractScrollableWidget::calculated_min_size();
+ auto constexpr cursor_padding = 4;
auto m = content_margins();
- return UISize { m.left() + m.right(), m.top() + m.bottom() };
+ auto width = max(40, m.horizontal_total());
+ auto height = max(22, line_height() + m.vertical_total() + cursor_padding);
+ return UISize { width, height };
}
void TextEditor::select_all()