Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Slider] Support drawing as a bar or handle #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Internal/UI/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions SlabTest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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()

Expand Down