1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

LibGUI: Implement calculated_min_size() for SpinBox

This commit is contained in:
thankyouverycool 2023-04-16 16:04:13 -04:00 committed by Andreas Kling
parent b66a76f73b
commit 33ccbc9415
2 changed files with 12 additions and 2 deletions

View file

@ -16,8 +16,8 @@ namespace GUI {
SpinBox::SpinBox()
{
set_min_size({ 40, 22 });
set_preferred_size({ SpecialDimension::OpportunisticGrow, 22 });
set_min_size({ SpecialDimension::Shrink });
set_preferred_size({ SpecialDimension::OpportunisticGrow, SpecialDimension::Shrink });
m_editor = add<TextBox>();
m_editor->set_text("0"sv);
m_editor->on_change = [this, weak_this = make_weak_ptr()] {
@ -127,4 +127,13 @@ void SpinBox::resize_event(ResizeEvent& event)
m_editor->set_relative_rect(0, 0, width(), height());
}
Optional<UISize> SpinBox::calculated_min_size() const
{
auto constexpr button_width = 15;
auto width = m_editor->effective_min_size().width().as_int() + button_width;
auto height = m_editor->effective_min_size().height().as_int();
return UISize { width, height };
}
}