State management is a very clean way to make your UIs interactable. You can create State Variables and change them on certain events. When state is changed, Enoria rebuilds only the widget that is affected (and it's childrens).
For example, with a simple counter app, we would need one state variable: the counter itself. We would initialize it to 0, and increment it when the player presses a button:
local e = require(game.ReplicatedStorage.Enoria.Enoria)
local Widget = require(game.ReplicatedStorage.Enoria.Enoria.Parent.Widgets.Widget)
local Counter = {}
Counter.__index = Counter
setmetatable(Counter, Widget)
function Counter.new(context, increment)
local self = Widget.new(nil, nil, context)
setmetatable(self, Counter)
self.CurrentNumber = 0
self.Increment = increment or 1
return self
end
function Counter:Build()
local tree = self:BuildTree(
e.TextButton(tostring(self.CurrentNumber), {
Name = self.Increment,
OnClick = function()
self:SetState(function()
self.CurrentNumber += self.Increment
end)
end,
})
)
return tree
end
return Counter