mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
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
This commit is contained in:
parent
7304556ff2
commit
9c2bcffe83
Notes:
sideshowbarker
2024-07-16 21:18:08 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/9c2bcffe83 Pull-request: https://github.com/SerenityOS/serenity/pull/18405
2 changed files with 6 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue