Horisontal slider reacting on scroll

Добавил реагирование горизонтальных слайдеров на скроллинг
This commit is contained in:
Smok1e 2021-07-10 01:27:20 +03:00
parent 50023e375d
commit 898ea448d0

View File

@ -1,4 +1,3 @@
local keyboard = require("Keyboard") local keyboard = require("Keyboard")
local filesystem = require("Filesystem") local filesystem = require("Filesystem")
local event = require("Event") local event = require("Event")
@ -1396,7 +1395,7 @@ local function sliderDraw(object)
return object return object
end end
local function sliderEventHandler(workspace, object, e1, e2, e3, ...) local function sliderEventHandler(workspace, object, e1, e2, e3, e4, e5, ...)
if e1 == "touch" or e1 == "drag" then if e1 == "touch" or e1 == "drag" then
local clickPosition = e3 - object.x local clickPosition = e3 - object.x
@ -1411,7 +1410,19 @@ local function sliderEventHandler(workspace, object, e1, e2, e3, ...)
workspace:draw() workspace:draw()
if object.onValueChanged then if object.onValueChanged then
object.onValueChanged(workspace, object, e1, e2, e3, ...) object.onValueChanged(workspace, object, e1, e2, e3, e4, e5, ...)
end
elseif e1 == "scroll" then
object.value = object.value + (object.maximumValue-object.minimumValue)*object.scrollSensivity * e5
if object.value > object.maximumValue then object.value = object.maximumValue
elseif object.value < object.minimumValue then object.value = object.minimumValue end
workspace:draw ()
if object.onValueChanged then
object.onValueChanged (workspace, object, e1, e2, e3, e4, e5, ...)
end end
end end
end end
@ -1425,6 +1436,7 @@ function GUI.slider(x, y, width, activeColor, passiveColor, pipeColor, valueColo
object.minimumValue = minimumValue object.minimumValue = minimumValue
object.maximumValue = maximumValue object.maximumValue = maximumValue
object.value = value object.value = value
object.scrollSensivity = 0.05
object.showMaximumAndMinimumValues = showMaximumAndMinimumValues object.showMaximumAndMinimumValues = showMaximumAndMinimumValues
object.currentValuePrefix = currentValuePrefix object.currentValuePrefix = currentValuePrefix
object.currentValuePostfix = currentValuePostfix object.currentValuePostfix = currentValuePostfix
@ -4254,14 +4266,17 @@ end
local function windowEventHandler(workspace, window, e1, e2, e3, e4, ...) local function windowEventHandler(workspace, window, e1, e2, e3, e4, ...)
if window.movingEnabled then if window.movingEnabled then
if e1 == "touch" then if e1 == "touch" then
GUI.focusedObject = window
if not windowCheck(window, e3, e4) then if not windowCheck(window, e3, e4) then
window.lastTouchX, window.lastTouchY = e3, e4 window.lastTouchX, window.lastTouchY = e3, e4
end end
if window ~= window.parent.children[#window.parent.children] then if window ~= window.parent.children[#window.parent.children] then
window:focus() window:moveToFront()
if window.onFocus then
window.onFocus(workspace, window, e1, e2, e3, e4, ...)
end
workspace:draw() workspace:draw()
end end
elseif e1 == "drag" and window.lastTouchX and not windowCheck(window, e3, e4) then elseif e1 == "drag" and window.lastTouchX and not windowCheck(window, e3, e4) then
@ -4332,22 +4347,11 @@ function GUI.windowMinimize(window)
window.hidden = not window.hidden window.hidden = not window.hidden
end end
function GUI.windowFocus(window)
GUI.focusedObject = window
window.hidden = false
window:moveToFront()
if window.onFocus then
window.onFocus()
end
end
function GUI.window(x, y, width, height) function GUI.window(x, y, width, height)
local window = GUI.container(x, y, width, height) local window = GUI.container(x, y, width, height)
window.passScreenEvents = false window.passScreenEvents = false
window.focus = GUI.windowFocus
window.resize = windowResize window.resize = windowResize
window.maximize = GUI.windowMaximize window.maximize = GUI.windowMaximize
window.minimize = GUI.windowMinimize window.minimize = GUI.windowMinimize
@ -4769,4 +4773,4 @@ end
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
return GUI return GUI