Compare commits

...

2 Commits

Author SHA1 Message Date
Gabriel Tofvesson
655ac6f4b2 Index children by UID 2024-10-09 06:36:18 +02:00
Gabriel Tofvesson
3960eb0cd2 Specify unique identifier for props 2024-10-09 06:35:54 +02:00
4 changed files with 19 additions and 12 deletions

View File

@ -1,7 +1,7 @@
local Prop = require("gfx.prop") local Prop = require("gfx.prop")
local Element = require("gfx.element") local Element = require("gfx.element")
local Event = require("gfx.event") local Event = require("gfx.event")
local Children = Prop:new{ defaultState = {} } local Children = Prop:new{ defaultState = {}, uid = "CHILDREN" }
function Children:with(elementType) function Children:with(elementType)
local propSelf = self local propSelf = self

View File

@ -2,11 +2,15 @@ local Prop = {}
Prop.__index = Prop Prop.__index = Prop
function Prop:getState(element) function Prop:getState(element)
return element[self] return element[self:getId()]
end end
function Prop:setState(element, state) function Prop:setState(element, state)
element[self] = state element[self:getId()] = state
end
function Prop:getId()
return self.uid
end end
function Prop.attach(elementType, prop, defaultState) function Prop.attach(elementType, prop, defaultState)
@ -15,10 +19,12 @@ function Prop.attach(elementType, prop, defaultState)
end end
function Prop:new(o) function Prop:new(o)
local obj = o or {} if o.uid == nil then
setmetatable(obj, Prop) error("Property must carry a unique identifier")
obj.__index = obj end
return obj setmetatable(o, Prop)
o.__index = o
return o
end end
return Prop return Prop

View File

@ -1,5 +1,5 @@
local Prop = require("gfx.prop") local Prop = require("gfx.prop")
local Orientation = Prop:new{ defaultState = false } local Orientation = Prop:new{ defaultState = false, uid = "ORIENTATION" }
function Orientation:with(elementType) function Orientation:with(elementType)
local propSelf = self local propSelf = self

View File

@ -6,6 +6,7 @@ local List = require("gfx.list")
local Event = require("gfx.event") local Event = require("gfx.event")
local Padding = require("gfx.padding") local Padding = require("gfx.padding")
local Container = require("gfx.container") local Container = require("gfx.container")
local Children = require("gfx.prop.children")
local CACHE_FILE = "/.storage.cache" local CACHE_FILE = "/.storage.cache"
@ -125,7 +126,7 @@ local function itemList(groups, wBudget, hBudget, savedState, onClick, setPage,
} }
local tabLine = List:new{ local tabLine = List:new{
children = { [Children:getId()] = {
btnPrev, btnPrev,
padImport, padImport,
padNext padNext
@ -173,7 +174,7 @@ local function itemList(groups, wBudget, hBudget, savedState, onClick, setPage,
} }
local list = List:new{ local list = List:new{
children = { [Children:getId()] = {
paddedText, paddedText,
countLabel countLabel
}, },
@ -193,7 +194,7 @@ local function itemList(groups, wBudget, hBudget, savedState, onClick, setPage,
table.insert(entries, tabLinePad) table.insert(entries, tabLinePad)
return List:new{ return List:new{
children = entries, [Children:getId()] = entries,
vertical = true vertical = true
}, state }, state
end end
@ -310,7 +311,7 @@ local PAGES = {
} }
local stuffContainer = Container:new{ local stuffContainer = Container:new{
children = { [Children:getId()] = {
paddedTitle paddedTitle
}, },
width = state.width, width = state.width,