Skip to content

Commit 1056b63

Browse files
committed
scroll() returns how much was actually scrolled.
wheelmoved() only returns handled if any scroll actually happened.
1 parent 32186ed commit 1056b63

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

InputField.lua

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--[[============================================================
22
--=
3-
--= InputField v3.3 - text input handling library for LÖVE (0.10.2+)
3+
--= InputField v3.3-dev - text input handling library for LÖVE (0.10.2+)
44
--= - Written by Marcus 'ReFreezed' Thunström
55
--= - MIT License (See the bottom of this file)
66
--= - https://github.com/ReFreezed/InputField
@@ -917,11 +917,18 @@ function InputField.setScrollY(field, scrollY)
917917
limitScroll(field)
918918
end
919919

920-
-- field:scroll( deltaX, deltaY )
920+
-- scrolledX, scrolledY = field:scroll( deltaX, deltaY )
921+
-- Returned values are how much was actually scrolled.
921922
function InputField.scroll(field, dx, dy)
922-
field.scrollX = field.scrollX + dx
923-
field.scrollY = field.scrollY + dy
923+
local oldScrollX = field.scrollX
924+
local oldScrollY = field.scrollY
925+
field.scrollX = oldScrollX + dx
926+
field.scrollY = oldScrollY + dy
927+
924928
limitScroll(field)
929+
930+
return field.scrollX - oldScrollX,
931+
field.scrollY - oldScrollY
925932
end
926933

927934
-- field:scrollToCursor( )
@@ -1786,13 +1793,17 @@ function InputField.wheelmoved(field, dx, dy)
17861793
dx, dy = dy, dx
17871794
end
17881795

1796+
if not ((dx ~= 0 and field:canScrollHorizontally()) or (dy ~= 0 and field:canScrollVertically())) then
1797+
return false
1798+
end
1799+
17891800
local fontH = field.font:getHeight()
1790-
field:scroll(
1801+
local scrolledX, scrolledY = field:scroll(
17911802
-dx * field.wheelScrollSpeedX*fontH,
17921803
-dy * field.wheelScrollSpeedY*fontH
17931804
)
17941805

1795-
return true -- Always handle event (for now).
1806+
return scrolledX ~= 0 or scrolledY ~= 0
17961807
end
17971808

17981809

0 commit comments

Comments
 (0)