deploy: 1c90c6cf04
This commit is contained in:
@@ -1,42 +1,33 @@
|
||||
local elementManager = require("elementManager")
|
||||
local VisualElement = elementManager.getElement("VisualElement")
|
||||
local getCenteredPosition = require("libraries/utils").getCenteredPosition
|
||||
# Button : VisualElement
|
||||
|
||||
---@class Button : VisualElement
|
||||
local Button = setmetatable({}, VisualElement)
|
||||
Button.__index = Button
|
||||
## Properties
|
||||
|
||||
---@property text string Button Button text
|
||||
Button.defineProperty(Button, "text", {default = "Button", type = "string", canTriggerRender = true})
|
||||
|Property|Type|Default|Description|
|
||||
|---|---|---|---|
|
||||
|text|string|Button|Button text
|
||||
|
||||
---@event mouse_click The event that is triggered when the button is clicked
|
||||
Button.listenTo(Button, "mouse_click")
|
||||
Button.listenTo(Button, "mouse_up")
|
||||
## Functions
|
||||
|
||||
--- Creates a new Button instance
|
||||
--- @return table self The created instance
|
||||
function Button.new()
|
||||
local self = setmetatable({}, Button):__init()
|
||||
self.set("width", 10)
|
||||
self.set("height", 3)
|
||||
self.set("z", 5)
|
||||
return self
|
||||
end
|
||||
|Method|Returns|Description|
|
||||
|---|---|---|
|
||||
|[Button.new](#Button.new)|table|
|
||||
|[Button:init](#Button:init)|-|
|
||||
|[Button:render](#Button:render)|-|
|
||||
|
||||
--- Initializes the Button instance
|
||||
--- @param props table The properties to initialize the element with
|
||||
--- @param basalt table The basalt instance
|
||||
function Button:init(props, basalt)
|
||||
VisualElement.init(self, props, basalt)
|
||||
self.set("type", "Button")
|
||||
end
|
||||
@event mouse_click The event that is triggered when the button is clicked
|
||||
## Button.new()
|
||||
Creates a new Button instance
|
||||
|
||||
--- Renders the Button
|
||||
function Button:render()
|
||||
VisualElement.render(self)
|
||||
local text = self.get("text")
|
||||
local xO, yO = getCenteredPosition(text, self.get("width"), self.get("height"))
|
||||
self:textFg(xO, yO, text, self.get("foreground"))
|
||||
end
|
||||
### Returns
|
||||
* `table` `self` The created instance
|
||||
|
||||
## Button:init(props, basalt)
|
||||
Initializes the Button instance
|
||||
|
||||
### Parameters
|
||||
* `props` `table` The properties to initialize the element with
|
||||
* `basalt` `table` The basalt instance
|
||||
|
||||
## Button:render()
|
||||
Renders the Button
|
||||
|
||||
return Button
|
||||
Reference in New Issue
Block a user