Files
Basalt/Basalt/objects/Button.lua
Sabine Lim bdc241575b getProperty() and setProperty() (#80)
* Fuck

* Add getProperty() and setProperty()

* Add getters and setters to VisualObject

* Update Frame and BaseFrame

* Update Flexbox

* Update Button and Label

* Update Input

* Update Image

* Update Checkbox

* Update Program

* Update Progressbar

* Update Slider

* Update Scrollbar

* Update Switch

* Update Textfield

* Update Timer

* Update List

* Update Dropdown

* Update Radio

* Update Menubar

* Update Graph

* Update Treeview
2023-05-15 19:24:16 +02:00

77 lines
2.1 KiB
Lua

local utils = require("utils")
local tHex = require("tHex")
return function(name, basalt)
-- Button
local base = basalt.getObject("VisualObject")(name, basalt)
local objectType = "Button"
local textHorizontalAlign = "center"
local textVerticalAlign = "center"
local text = "Button"
base:setSize(12, 3)
base:setZIndex(5)
local object = {
getType = function(self)
return objectType
end,
isType = function(self, t)
return objectType==t or base.isType~=nil and base.isType(t) or false
end,
getBase = function(self)
return base
end,
getHorizontalAlign = function(self)
return textHorizontalAlign
end,
setHorizontalAlign = function(self, pos)
textHorizontalAlign = pos
self:updateDraw()
return self
end,
getVerticalAlign = function(self)
return textVerticalAlign
end,
setVerticalAlign = function(self, pos)
textVerticalAlign = pos
self:updateDraw()
return self
end,
getText = function(self)
return text
end,
setText = function(self, newText)
text = newText
self:updateDraw()
return self
end,
draw = function(self)
base.draw(self)
self:addDraw("button", function()
local w,h = self:getSize()
local verticalAlign = utils.getTextVerticalAlign(h, textVerticalAlign)
local xOffset
if(textHorizontalAlign=="center")then
xOffset = math.floor((w - text:len()) / 2)
elseif(textHorizontalAlign=="right")then
xOffset = w - text:len()
end
self:addText(xOffset + 1, verticalAlign, text)
self:addFG(xOffset + 1, verticalAlign, tHex[self:getForeground() or colors.white]:rep(text:len()))
end)
end,
}
object.__index = object
return setmetatable(object, base)
end