Annotation Stuff
This commit is contained in:
@@ -31,7 +31,7 @@ BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"})
|
||||
--- @property eventCallbacks table BaseElement The event callbacks for the element
|
||||
BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"})
|
||||
|
||||
---@private
|
||||
--- Registers a new event listener for the element (on class level)
|
||||
function BaseElement.defineEvent(class, eventName, requiredEvent)
|
||||
if not rawget(class, '_eventConfigs') then
|
||||
class._eventConfigs = {}
|
||||
@@ -42,7 +42,7 @@ function BaseElement.defineEvent(class, eventName, requiredEvent)
|
||||
}
|
||||
end
|
||||
|
||||
---@private
|
||||
--- Registers a new event callback for the element (on class level)
|
||||
function BaseElement.registerEventCallback(class, callbackName, ...)
|
||||
local methodName = callbackName:match("^on") and callbackName or "on"..callbackName
|
||||
local events = {...}
|
||||
|
||||
@@ -4,8 +4,8 @@ local tHex = require("libraries/colorHex")
|
||||
---@configDescription An element that displays an image in bimg format
|
||||
---@configDefault false
|
||||
|
||||
--- This is the Image element class which can be used to display bimg format images.
|
||||
--- The bimg format is a universal ComputerCraft image format.
|
||||
--- This is the Image element class which can be used to display bimg formatted images.
|
||||
--- Bimg is a universal ComputerCraft image format.
|
||||
--- See: https://github.com/SkyTheCodeMaster/bimg
|
||||
---@class Image : VisualElement
|
||||
local Image = setmetatable({}, VisualElement)
|
||||
@@ -187,13 +187,19 @@ function Image:setText(x, y, text)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the text at the specified position
|
||||
--- @shortDescription Gets the text at the specified position
|
||||
--- @param x number The x position
|
||||
--- @param y number The y position
|
||||
--- @param length number The length of the text to get
|
||||
--- @return string text The text at the specified position
|
||||
function Image:getText(x, y, length)
|
||||
if not x or not y then return end
|
||||
if not x or not y then return "" end
|
||||
local frame = self.get("bimg")[self.get("currentFrame")]
|
||||
if not frame or not frame[y] then return end
|
||||
if not frame or not frame[y] then return "" end
|
||||
|
||||
local text = frame[y][1]
|
||||
if not text then return end
|
||||
if not text then return "" end
|
||||
|
||||
if length then
|
||||
return text:sub(x, x + length - 1)
|
||||
@@ -231,13 +237,19 @@ function Image:setFg(x, y, pattern)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the foreground color at the specified position
|
||||
--- @shortDescription Gets the foreground color at the specified position
|
||||
--- @param x number The x position
|
||||
--- @param y number The y position
|
||||
--- @param length number The length of the foreground color pattern to get
|
||||
--- @return string fg The foreground color pattern
|
||||
function Image:getFg(x, y, length)
|
||||
if not x or not y then return end
|
||||
if not x or not y then return "" end
|
||||
local frame = self.get("bimg")[self.get("currentFrame")]
|
||||
if not frame or not frame[y] then return end
|
||||
if not frame or not frame[y] then return "" end
|
||||
|
||||
local fg = frame[y][2]
|
||||
if not fg then return end
|
||||
if not fg then return "" end
|
||||
|
||||
if length then
|
||||
return fg:sub(x, x + length - 1)
|
||||
@@ -275,13 +287,19 @@ function Image:setBg(x, y, pattern)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the background color at the specified position
|
||||
--- @shortDescription Gets the background color at the specified position
|
||||
--- @param x number The x position
|
||||
--- @param y number The y position
|
||||
--- @param length number The length of the background color pattern to get
|
||||
--- @return string bg The background color pattern
|
||||
function Image:getBg(x, y, length)
|
||||
if not x or not y then return end
|
||||
if not x or not y then return "" end
|
||||
local frame = self.get("bimg")[self.get("currentFrame")]
|
||||
if not frame or not frame[y] then return end
|
||||
if not frame or not frame[y] then return "" end
|
||||
|
||||
local bg = frame[y][3]
|
||||
if not bg then return end
|
||||
if not bg then return "" end
|
||||
|
||||
if length then
|
||||
return bg:sub(x, x + length - 1)
|
||||
@@ -338,7 +356,11 @@ function Image:addFrame()
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Updates the specified frame with the provided data
|
||||
--- @shortDescription Updates the specified frame with the provided data
|
||||
--- @param frameIndex number The index of the frame to update
|
||||
--- @param frame table The new frame data
|
||||
--- @return Image self The Image instance
|
||||
function Image:updateFrame(frameIndex, frame)
|
||||
local frames = self.get("bimg")
|
||||
frames[frameIndex] = frame
|
||||
@@ -355,6 +377,9 @@ function Image:getFrame(frameIndex)
|
||||
return frames[frameIndex or self.get("currentFrame")]
|
||||
end
|
||||
|
||||
--- Gets the metadata of the image
|
||||
--- @shortDescription Gets the metadata of the image
|
||||
--- @return table metadata The metadata of the image
|
||||
function Image:getMetadata()
|
||||
local metadata = {}
|
||||
local bimg = self.get("bimg")
|
||||
@@ -366,6 +391,11 @@ function Image:getMetadata()
|
||||
return metadata
|
||||
end
|
||||
|
||||
--- Sets the metadata of the image
|
||||
--- @shortDescription Sets the metadata of the image
|
||||
--- @param key string The key of the metadata to set
|
||||
--- @param value string The value of the metadata to set
|
||||
--- @return Image self The Image instance
|
||||
function Image:setMetadata(key, value)
|
||||
if(type(key)=="table")then
|
||||
for k,v in pairs(key)do
|
||||
|
||||
@@ -70,8 +70,8 @@ function Input:char(char)
|
||||
local maxLength = self.get("maxLength")
|
||||
local pattern = self.get("pattern")
|
||||
|
||||
if maxLength and #text >= maxLength then return end
|
||||
if pattern and not char:match(pattern) then return end
|
||||
if maxLength and #text >= maxLength then return false end
|
||||
if pattern and not char:match(pattern) then return false end
|
||||
|
||||
self.set("text", text:sub(1, pos-1) .. char .. text:sub(pos))
|
||||
self.set("cursorPos", pos + 1)
|
||||
|
||||
@@ -127,6 +127,7 @@ function Tree:mouse_click(button, x, y)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Registers a callback for when a node is selected
|
||||
@@ -153,6 +154,7 @@ function Tree:mouse_scroll(direction, x, y)
|
||||
self.set("scrollOffset", newScroll)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--- Gets the size of the tree
|
||||
|
||||
@@ -78,7 +78,7 @@ VisualElement.combineProperties(VisualElement, "size", "width", "height")
|
||||
---@combinedProperty color {foreground number, background number} Combined foreground, background colors
|
||||
VisualElement.combineProperties(VisualElement, "color", "foreground", "background")
|
||||
|
||||
---@event onClick {button, x, y} Fired on mouse click
|
||||
---@event onClick {button string, x number, y number} Fired on mouse click
|
||||
---@event onMouseUp {button, x, y} Fired on mouse button release
|
||||
---@event onRelease {button, x, y} Fired when mouse leaves while clicked
|
||||
---@event onDrag {button, x, y} Fired when mouse moves while clicked
|
||||
@@ -110,8 +110,6 @@ local max, min = math.max, math.min
|
||||
|
||||
--- Creates a new VisualElement instance
|
||||
--- @shortDescription Creates a new visual element
|
||||
--- @param props table The properties to initialize the element with
|
||||
--- @param basalt table The basalt instance
|
||||
--- @return VisualElement object The newly created VisualElement instance
|
||||
--- @private
|
||||
function VisualElement.new()
|
||||
|
||||
Reference in New Issue
Block a user