require("common.class") local ContainerField = require("components.pager.containerfield") local ServiceField = require("titlescreen.fields.service.servicefield") ---@class ListField: ContainerField, ServiceField local ListField = { __tostring = function() return "ListField" end, PADDING = {0, 0, 0, 0}, --{left, top, right, bottom} BGCOLOR = {0, 0, 0, 255}, --{r, g, b, a} BORDERCOLOR = {255, 255, 255, 255}, BORDERRADII = 4, BORDERWIDTH = 1 } ---Create a new ListField instance --- ---Inherits from Field ---@param o Field ---@return ListField function ListField:new(o) o = o or {} --set instance members o.aabbH = o.aabbH or self.MARGIN[2] + self.PADDING[2] + self.PADDING[4] + self.MARGIN[4] return Inherit(self, o, ContainerField, ServiceField) end ---Add field to list container ---@param field Field function ListField:addField(field) --place field to correct position local posY = self.PADDING[2] for _, child in ipairs(self.content) do posY = posY + child.aabbH end field.posX = self.PADDING[1] field.posY = posY --update size self.aabbH = posY + field.aabbH + self.PADDING[4] local fieldAabbW = field.aabbW + self.PADDING[1] + self.PADDING[3] if self.aabbW < fieldAabbW then self.aabbW = fieldAabbW end --add field to container ContainerField.addField(self, field) end function ListField:drawBackground(deltaTime) gfx.BeginPath() gfx.StrokeColor(255, 255, 255, 255) gfx.StrokeWidth(1) gfx.FillColor(0, 0, 0, 255) gfx.RoundedRect(self.posX, self.posY, self.aabbW, self.aabbH) gfx.Stroke() gfx.Fill() end function ListField:drawContent(deltaTime) gfx.Save() gfx.Scissor(self.PADDING[1], self.PADDING[2], self.aabbW - self.PADDING[1] - self.PADDING[3], self.aabbH - self.PADDING[2] - self.PADDING[4]) for _, field in ipairs(self.content) do field:render(deltaTime) end gfx.Restore() end function ListField:drawForeground(deltaTime) end return ListField