2024-11-20 01:42:12 +02:00

57 lines
1.1 KiB
Lua

---@class widget.property_checkbox: druid.widget
---@field root node
---@field druid druid_instance
---@field text_name druid.text
---@field button druid.button
---@field selected node
local M = {}
function M:init()
self.root = self:get_node("root")
self.icon = self:get_node("icon")
gui.set_enabled(self.icon, false)
self.selected = self:get_node("selected")
gui.set_alpha(self.selected, 0)
self.text_name = self.druid:new_text("text_name")
self.button = self.druid:new_button("button", self.on_click)
self.container = self.druid:new_container(self.root)
self.container:add_container("text_name")
self.container:add_container("E_Anchor")
end
---@param value boolean
function M:set_value(value, is_instant)
if self._value == value then
return
end
self._value = value
gui.set_enabled(self.icon, value)
if not is_instant then
gui.set_alpha(self.selected, 1)
gui.animate(self.selected, "color.w", 0, gui.EASING_INSINE, 0.16)
end
end
---@return boolean
function M:get_value()
return self._value
end
function M:on_click()
self:set_value(not self:get_value())
end
return M