LibGUI: Implement calculated sizes for ValueSlider
This commit is contained in:
parent
b6d45f9c1f
commit
caf6dd5680
Notes:
sideshowbarker
2024-07-17 08:35:21 +09:00
Author: https://github.com/frhun Commit: https://github.com/SerenityOS/serenity/commit/caf6dd5680 Pull-request: https://github.com/SerenityOS/serenity/pull/17407 Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 27 additions and 2 deletions
|
@ -24,7 +24,7 @@ ValueSlider::ValueSlider(Gfx::Orientation orientation, String suffix)
|
|||
// FIXME: Implement vertical mode
|
||||
VERIFY(orientation == Orientation::Horizontal);
|
||||
|
||||
set_fixed_height(20);
|
||||
set_preferred_size(SpecialDimension::Fit);
|
||||
|
||||
m_textbox = add<GUI::TextBox>();
|
||||
m_textbox->set_relative_rect({ 0, 0, 34, 20 });
|
||||
|
@ -119,9 +119,14 @@ Gfx::IntRect ValueSlider::bar_rect() const
|
|||
return bar_rect;
|
||||
}
|
||||
|
||||
int ValueSlider::knob_length() const
|
||||
{
|
||||
return m_knob_style == KnobStyle::Wide ? 13 : 7;
|
||||
}
|
||||
|
||||
Gfx::IntRect ValueSlider::knob_rect() const
|
||||
{
|
||||
int knob_thickness = m_knob_style == KnobStyle::Wide ? 13 : 7;
|
||||
int knob_thickness = knob_length();
|
||||
|
||||
Gfx::IntRect knob_rect = bar_rect();
|
||||
knob_rect.set_width(knob_thickness);
|
||||
|
@ -202,4 +207,20 @@ void ValueSlider::mouseup_event(MouseEvent& event)
|
|||
m_dragging = false;
|
||||
}
|
||||
|
||||
Optional<UISize> ValueSlider::calculated_min_size() const
|
||||
{
|
||||
auto content_min_size = m_textbox->effective_min_size();
|
||||
|
||||
if (orientation() == Gfx::Orientation::Vertical)
|
||||
return { { content_min_size.width(), content_min_size.height().as_int() + knob_length() } };
|
||||
return { { content_min_size.width().as_int() + knob_length(), content_min_size.height() } };
|
||||
}
|
||||
|
||||
Optional<UISize> ValueSlider::calculated_preferred_size() const
|
||||
{
|
||||
if (orientation() == Gfx::Orientation::Vertical)
|
||||
return { { SpecialDimension::Shrink, SpecialDimension::OpportunisticGrow } };
|
||||
return { { SpecialDimension::OpportunisticGrow, SpecialDimension::Shrink } };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,10 @@ private:
|
|||
int value_at(Gfx::IntPoint position) const;
|
||||
Gfx::IntRect bar_rect() const;
|
||||
Gfx::IntRect knob_rect() const;
|
||||
int knob_length() const;
|
||||
|
||||
virtual Optional<UISize> calculated_min_size() const override;
|
||||
virtual Optional<UISize> calculated_preferred_size() const override;
|
||||
|
||||
String m_suffix {};
|
||||
Orientation m_orientation { Orientation::Horizontal };
|
||||
|
|
Loading…
Add table
Reference in a new issue