require("common.class") local dim = require("common.dimensions") local Field = require("components.pager.field") ---@class ServiceFieldState ServiceFieldState = { INACTIVE = 0, FOCUSED = 1, ACTIVE = 2 } ---@class ServiceField: Field ---@field label string ---@field value any ---@field footer string|string[] ---@field _state ServiceFieldState local ServiceField = { SERVICE_DEFAULT_FONT_SIZE = 24, SERVICE_DEFAULT_FONT_FACE = "dfmarugoth.ttf", SERVICE_DEFAULT_FONT_COLOR = {255, 255, 255, 255}, --{r, g, b, a} } function ServiceField:new(o) o = Inherit(self, Field, o) o.label = o.label or "" o.value = o.value or nil o.footer = o.footer or nil o._state = ServiceFieldState.INACTIVE return o end function ServiceField:activate() self._state = ServiceFieldState.ACTIVE end function ServiceField:focus() self._state = ServiceFieldState.FOCUSED end function ServiceField:deactivate() self._state = ServiceFieldState.INACTIVE end function ServiceField:drawValue(deltaTime) gfx.Save() gfx.BeginPath() gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR)) if type(self.value) == "string" then gfx.Text(string.upper(self.value), dim.design.width / 2, 0) else gfx.Text("N/A", dim.design.width / 2, 0) end gfx.Restore() end function ServiceField:render(deltaTime) gfx.Save() gfx.Translate(self.posX, self.posY) gfx.FontSize(self.SERVICE_DEFAULT_FONT_SIZE) gfx.LoadSkinFont(self.SERVICE_DEFAULT_FONT_FACE) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT | gfx.TEXT_ALIGN_TOP) if self._state == ServiceFieldState.FOCUSED then gfx.FillColor(255, 0, 0, 255) else gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR)) end gfx.BeginPath() gfx.Text(self.label, 0, 0) self:drawValue(deltaTime) gfx.Restore() end return ServiceField