Not important updates

This commit is contained in:
SweetSea-ButImNotSweet
2024-05-20 19:23:00 +07:00
parent 62dc4b1abf
commit 2c1f7485ad
5 changed files with 97 additions and 40 deletions

View File

@@ -93,6 +93,7 @@ function button:draw()
end
---Check if current position is hovering the button, if yes, set ``self._hovering`` to true and return true
function button:isHovering(x,y)
if not y then self._hovering = false; return false end
if
x >= self.x and
y >= self.y and
@@ -111,7 +112,10 @@ function button:press()
end
---Trigger release action, don't need ``self._hovering`` to ``true``
function button:release()
self.codeWhenReleased()
if self._hovering then
self.codeWhenReleased()
self._hovering = false
end
end
@@ -122,18 +126,19 @@ local BUTTON = {}
---@return nil
---Validate the provided data, will be called by ``BUTTON.new`` and ``BUTTON.setDefaultOption``<br>
---***WARNING! THIS FUNCTION WILL RAISE EXCEPTION IF DATA IS INVALID!***
function BUTTON.checkDataValidation(D)
-- <SAFE TO IGNORE>
assert(type(D.text) == "string" == "string","[text] is missing, or you just passed an empty data?")
assert(type(D.x) == "number" , "[x] must be a integer")
assert(type(D.y) == "number" , "[y] must be a integer")
assert(type(D.w) == "number" and D.w > 0, "[w] must be a positive integer")
assert(type(D.h) == "number" and D.h > 0, "[h] must be a positive integer")
-- </>
function BUTTON.checkDataValidation(D, safe)
if not safe then
assert(type(D.text) == "string","[text] is missing, or you just passed an empty data?")
assert(type(D.x) == "number" , "[x] must be a integer")
assert(type(D.y) == "number" , "[y] must be a integer")
assert(type(D.w) == "number" and D.w > 0, "[w] must be a positive integer")
assert(type(D.h) == "number" and D.h > 0, "[h] must be a positive integer")
assert((type(D.r) == "number" and D.r >= 0 and D.r <= D.w * 0.5 and D.r <= D.h * 0.5) or D.r == nil, "[r] must be a positive integer and cannot larger than half of button's width and half of button's height")
else
assert(type(D.r) == "number" and D.r >= 0 or D.r == nil, "[r] must be a positive integer (CAUTION: a extra condition is temproraily ignored because you are setting default option)")
end
assert(table.contains({"center","justify","left","right"}, D.textOrientation) or D.textOrientation == nil, "[borderJoin] must be 'bevel', 'miter' or 'none")
assert((type(D.r) == "number" and D.r >= 0 and D.r <= D.w * 0.5 and D.r <= D.h * 0.5) or D.r == nil, "[r] must be a positive integer and cannot larger than half of button's width and half of button's height")
assert((type(D.borderWidth) == "number" and D.borderWidth > 0) or D.borderWidth == nil, "[borderWidth] must be a postive integer")
assert(table.contains({"bevel", "miter", "none"}, D.borderJoin) or D.borderJoin == nil, "[borderJoin] must be 'bevel', 'miter' or 'none")
assert(table.contains({"rough", "smooth"}, D.borderStyle) or D.borderStyle == nil, "[borderStyle] must be 'rough' or 'smooth'")