summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorFrHun <28605587+frhun@users.noreply.github.com>2023-02-10 01:07:37 +0100
committerSam Atkins <atkinssj@gmail.com>2023-02-17 16:25:57 +0000
commitcaf6dd56809bb305ae1ebffbcc39990c8c8b864c (patch)
tree528c27b232385d74e74ecd255a8f17762f9e7a69 /Userland/Libraries
parentb6d45f9c1feca10d80da65a1c14ba7488691f44e (diff)
downloadserenity-caf6dd56809bb305ae1ebffbcc39990c8c8b864c.zip
LibGUI: Implement calculated sizes for ValueSlider
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/ValueSlider.cpp25
-rw-r--r--Userland/Libraries/LibGUI/ValueSlider.h4
2 files changed, 27 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/ValueSlider.cpp b/Userland/Libraries/LibGUI/ValueSlider.cpp
index ac8cde7eec..e7e7de95e2 100644
--- a/Userland/Libraries/LibGUI/ValueSlider.cpp
+++ b/Userland/Libraries/LibGUI/ValueSlider.cpp
@@ -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 } };
+}
+
}
diff --git a/Userland/Libraries/LibGUI/ValueSlider.h b/Userland/Libraries/LibGUI/ValueSlider.h
index 191da5a343..96db34c374 100644
--- a/Userland/Libraries/LibGUI/ValueSlider.h
+++ b/Userland/Libraries/LibGUI/ValueSlider.h
@@ -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 };