11-- "version": "Beta v. Upbeat Giraffe",
22-- "author": "PenguinToast",
3- -- "version": "0.3.2 ",
3+ -- "version": "0.4 ",
44-- "support_url": "http://penguintoast.github.io/PenguinGUI"
55-- This script contains all the scripts in this library, so you only need to
66-- include this script for production purposes.
@@ -1586,6 +1586,9 @@ TextField.cursorColor = "white"
15861586TextField .cursorRate = 1
15871587TextField .filter = nil
15881588
1589+ TextField .repeatDelay = 0.5
1590+ TextField .repeatInterval = 0.05
1591+
15891592
15901593function TextField :_init (x , y , width , height , defaultText )
15911594 Component ._init (self )
@@ -1602,11 +1605,22 @@ function TextField:_init(x, y, width, height, defaultText)
16021605 self .textOffset = 0
16031606 self .textClip = nil
16041607 self .mouseOver = false
1608+ self .keyTimes = {}
16051609end
16061610
16071611
16081612function TextField :update (dt )
16091613 if self .hasFocus then
1614+ local keyTimes = self .keyTimes
1615+ for key ,dur in pairs (keyTimes ) do
1616+ local time = dur + dt
1617+ keyTimes [key ] = time
1618+ if time > self .repeatDelay + self .repeatInterval then
1619+ self :keyEvent (key , true )
1620+ keyTimes [key ] = self .repeatDelay
1621+ end
1622+ end
1623+
16101624 local timer = self .cursorTimer
16111625 local rate = self .cursorRate
16121626 timer = timer - dt
@@ -1743,6 +1757,12 @@ function TextField:clickEvent(position, button, pressed)
17431757end
17441758
17451759function TextField :keyEvent (keyCode , pressed )
1760+ if pressed then
1761+ self .keyTimes [keyCode ] = self .keyTimes [keyCode ] or 0
1762+ else
1763+ self .keyTimes [keyCode ] = nil
1764+ end
1765+
17461766 local keyState = GUI .keyState
17471767 if not pressed
17481768 or keyState [305 ] or keyState [306 ]
0 commit comments