summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorFrHun <28605587+frhun@users.noreply.github.com>2023-02-10 01:08:13 +0100
committerSam Atkins <atkinssj@gmail.com>2023-02-17 16:25:57 +0000
commit6d79d932f955707138e920e7af98bfe3dbe0e2b4 (patch)
treed2d2dcc71278a07650bbaa917faa3a8cd9db1655 /Userland/Libraries/LibGUI
parentcaf6dd56809bb305ae1ebffbcc39990c8c8b864c (diff)
downloadserenity-6d79d932f955707138e920e7af98bfe3dbe0e2b4.zip
LibGUI: Implement calculated sizes for Slider
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/Slider.cpp16
-rw-r--r--Userland/Libraries/LibGUI/Slider.h3
2 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Slider.cpp b/Userland/Libraries/LibGUI/Slider.cpp
index 8c22b48b12..350225cfa8 100644
--- a/Userland/Libraries/LibGUI/Slider.cpp
+++ b/Userland/Libraries/LibGUI/Slider.cpp
@@ -24,6 +24,8 @@ Slider::Slider(Orientation orientation)
{ KnobSizeMode::Fixed, "Fixed" },
{ KnobSizeMode::Proportional, "Proportional" });
REGISTER_BOOL_PROPERTY("jump_to_cursor", jump_to_cursor, set_jump_to_cursor);
+
+ set_preferred_size(SpecialDimension::Fit);
}
void Slider::paint_event(PaintEvent& event)
@@ -199,4 +201,18 @@ void Slider::set_knob_hovered(bool hovered)
update(knob_rect());
}
+Optional<UISize> Slider::calculated_min_size() const
+{
+ if (orientation() == Gfx::Orientation::Vertical)
+ return { { knob_secondary_size(), knob_fixed_primary_size() * 2 + track_margin() * 2 } };
+ return { { knob_fixed_primary_size() * 2 + track_margin() * 2, knob_secondary_size() } };
+}
+
+Optional<UISize> Slider::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/Slider.h b/Userland/Libraries/LibGUI/Slider.h
index a2f3cfd800..4b7bf837dd 100644
--- a/Userland/Libraries/LibGUI/Slider.h
+++ b/Userland/Libraries/LibGUI/Slider.h
@@ -46,6 +46,9 @@ public:
protected:
explicit Slider(Orientation = Orientation::Vertical);
+ virtual Optional<UISize> calculated_min_size() const override;
+ virtual Optional<UISize> calculated_preferred_size() const override;
+
virtual void paint_event(PaintEvent&) override;
void start_drag(Gfx::IntPoint);
virtual void mousedown_event(MouseEvent&) override;