Skip to content

Commit

Permalink
[Slider] Support drawing as a bar or handle
Browse files Browse the repository at this point in the history
Add an option to allow drawing as either a bar or a handle.

close #79
  • Loading branch information
idbrii authored and coding-jackalope committed Aug 4, 2021
1 parent 5cf8e5b commit c41d311
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Internal/UI/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,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
Expand All @@ -881,7 +881,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
Expand Down Expand Up @@ -1360,7 +1365,7 @@ function Input.Begin(Id, Options)

if Options.UseSlider then
if not IsEditing then
DrawSlider(Instance)
DrawSlider(Instance, Options.DrawSliderAsHandle)
end
end

Expand Down
7 changes: 7 additions & 0 deletions SlabTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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 =
Expand Down Expand Up @@ -567,6 +568,12 @@ local function DrawInput()
DrawInput_Basic_Numbers_Slider = Slab.GetInputNumber()
end

Slab.NewLine()
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()

Expand Down

0 comments on commit c41d311

Please sign in to comment.