From 3853c787a8dec17acd088d608d1a96c25a406c40 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Wed, 10 Mar 2021 23:03:40 -0800 Subject: [PATCH] [Slider] Support drawing as a bar or handle Add an option to allow drawing as either a bar or a handle. --- Internal/UI/Input.lua | 11 ++++++++--- SlabTest.lua | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Internal/UI/Input.lua b/Internal/UI/Input.lua index e57231a..1586716 100644 --- a/Internal/UI/Input.lua +++ b/Internal/UI/Input.lua @@ -869,7 +869,7 @@ local function UpdateDrag(Instance, Step) end end -local function DrawSlider(Instance) +local function DrawSlider(Instance, DrawSliderAsHandle) if Instance ~= nil and Instance.NumbersOnly then local Value = tonumber(Instance.Text) if Value ~= nil then @@ -880,7 +880,12 @@ local function DrawSlider(Instance) local MinX, MinY = Cursor.GetPosition() local MaxX, MaxY = MinX + Instance.W - SliderSize, MinY + Instance.H local X = (MaxX - MinX) * Ratio + MinX - DrawCommands.Rectangle('fill', X, MinY + 1.0, SliderSize, Instance.H - 2.0, Style.InputSliderColor) + if DrawSliderAsHandle then + DrawCommands.Rectangle('fill', X, MinY + 1.0, SliderSize, Instance.H - 2.0, Style.InputSliderColor) + else + local Padding = 2 + DrawCommands.Rectangle('fill', MinX+Padding, MinY+Padding, Padding + (Instance.W - Padding * 3) * Ratio, Instance.H - (Padding * 2), Style.InputSliderColor) + end end end end @@ -1356,7 +1361,7 @@ function Input.Begin(Id, Options) if Options.UseSlider then if not IsEditing then - DrawSlider(Instance) + DrawSlider(Instance, Options.DrawSliderAsHandle) end end diff --git a/SlabTest.lua b/SlabTest.lua index 9b9bb75..de844b9 100644 --- a/SlabTest.lua +++ b/SlabTest.lua @@ -398,6 +398,7 @@ local DrawInput_Basic_Numbers_Clamped_Max = 1.0 local DrawInput_Basic_Numbers_Clamped_Step = 0.01 local DrawInput_Basic_Numbers_NoDrag = 50 local DrawInput_Basic_Numbers_Slider = 50 +local DrawInput_Basic_Numbers_Slider_Handle = 50 local DrawInput_Basic_Numbers_Slider_Min = 0 local DrawInput_Basic_Numbers_Slider_Max = 100 local DrawInput_MultiLine = @@ -555,6 +556,11 @@ local function DrawInput() DrawInput_Basic_Numbers_Slider = Slab.GetInputNumber() end + Slab.Text("Sliders can also be drawn with a handle") + if Slab.InputNumberSlider('DrawInput_Basic_Numbers_Slider_Handle', DrawInput_Basic_Numbers_Slider_Handle, DrawInput_Basic_Numbers_Slider_Min, DrawInput_Basic_Numbers_Slider_Max, {DrawSliderAsHandle = true}) then + DrawInput_Basic_Numbers_Slider_Handle = Slab.GetInputNumber() + end + Slab.NewLine() Slab.Separator()