1
0
mirror of https://github.com/AR2000AR/openComputers_codes.git synced 2025-09-04 12:45:58 +02:00

[libgui] refactoring

This commit is contained in:
2023-04-13 16:47:47 +02:00
parent 121da642b7
commit e6aa8d7242
3 changed files with 25 additions and 25 deletions

View File

@@ -47,7 +47,7 @@ function Keypad.setValidateCallback(self, fct) if (type(fct) == "function") then
function Keypad.enable(self, enable)
self.private.enabled = enable
if (self.private.event ~= -1) then --if a event listener is present
event.cancel(self.private.event) --cancel the event listener
event.cancel(self.private.event --[[@as number]]) --cancel the event listener
self.private.event = -1 --set event to -1 (no listener)
end
if (enable) then
@@ -124,12 +124,12 @@ function Keypad.private.drawInput(self)
gpu.fill(self:getX() + 1, self:getY() + 1, self:getWidth() - 2, 1, " ")
--fill the text field
local displayText = self:getInput():sub( -1 * (self:getWidth() - 2))
local displayText = self:getInput():sub(-1 * (self:getWidth() - 2))
if (self:isInputHidden()) then
displayText = displayText:gsub('.', '*') --replace each char with '*'
end
if (#self:getInput() > self:getWidth() - 2) then --if the input if longer than the text field
displayText = "<" .. displayText:sub( -1 * (self:getWidth() - 3)) --replace the first character of the displayed text with "<" to indicate a trucated string
displayText = "<" .. displayText:sub(-1 * (self:getWidth() - 3)) --replace the first character of the displayed text with "<" to indicate a trucated string
end
gpu.set(self:getX() + 1, self:getY() + 1, displayText)

View File

@@ -49,9 +49,9 @@ function Input.private.callback(self, eventName, uuid, x, y, button, playerName)
self.private.keyDownEvent = event.listen("key_down", function(...) self.private.onKeyDown(self, ...) end)
self.private.touchEvent = event.listen("touch", function(eventName, uuid, x, y, button, playerName)
if (not self:collide(x, y)) then
if (self.private.keyDownEvent) then event.cancel(self.private.keyDownEvent) end
if (self.private.keyDownEvent) then event.cancel(self.private.keyDownEvent --[[@as number]]) end
self.private.keyDownEvent = nil
if (self.private.touchEvent) then event.cancel(self.private.touchEvent) end
if (self.private.touchEvent) then event.cancel(self.private.touchEvent --[[@as number]]) end
self.private.touchEvent = nil
end
end)

View File

@@ -37,4 +37,4 @@ while (run) do
os.sleep()
end
--stop processing touch events
event.cancel(touchEvent)
event.cancel(touchEvent --[[@as number]])