This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-05-21 21:50:48 +07:00
parent 5cf9deb9eb
commit 68d4e04142
2 changed files with 16 additions and 14 deletions

View File

@@ -116,14 +116,16 @@ function button:press(x, y)
end
---Trigger release action, don't need ``self._hovering`` to ``true``
---@param isMouse? boolean Button just released by mouse?
function button:release(x, y, isTouch)
if self:isHovering(x, y) and self._pressed then
self.codeWhenReleased()
self._pressed = false
if isTouch then
self._hovering = false
else
function button:release(x, y, isMouse)
if self:isHovering(x, y) then
if self._pressed then
self.codeWhenReleased()
self._pressed = false
end
if isMouse then
self:isHovering(x, y)
elseif self._hovering then
self._hovering = false
end
end
end
@@ -226,7 +228,7 @@ end
---Calling BUTTON.press will trigger this, but you can call it when moving mouse so button can be highlighted when being hovered
---@param list table<BUTTON.button>
---@param x number # Mouse position
---@param y nunber # Mouse position
---@param y number # Mouse position
function BUTTON.checkHovering(list, x, y)
for _, v in pairs(list) do v:isHovering(x, y) end
end
@@ -234,7 +236,7 @@ end
--- Trigger the press action, only if ``button._hovering == true``
---@param list table<BUTTON.button>
---@param x number # Mouse position
---@param y nunber # Mouse position
---@param y number # Mouse position
function BUTTON.press(list, x, y)
for _, v in pairs(list) do v:press(x, y) end
end
@@ -242,10 +244,10 @@ end
---Trigger the release action
---@param list table<BUTTON.button>
---@param x number # Mouse position
---@param y nunber # Mouse position
---@param y number # Mouse position
---@param isMouse? boolean # Is mouse just released a button?
function BUTTON.release(list, x, y, isTouch)
for _, v in pairs(list) do v:release(x, y, isTouch) end
function BUTTON.release(list, x, y, isMouse)
for _, v in pairs(list) do v:release(x, y, isMouse) end
end
return BUTTON

View File

@@ -83,9 +83,9 @@ end
---@param e SCENE_onInput
function TouchConfigScene:onInputRelease(e)
if e.type == "mouse" then
BUTTON.release(buttonList, e.x, e.y)
elseif e.type == "touch" then
BUTTON.release(buttonList, e.x, e.y, true)
elseif e.type == "touch" then
BUTTON.release(buttonList, e.x, e.y)
end
end