2022-09-12 09:34:46 +02:00
|
|
|
--- Implements a static label widget
|
|
|
|
--
|
|
|
|
-- @classmod yui.Label
|
|
|
|
-- @copyright 2022, The DoubleFourteen Code Forge
|
|
|
|
-- @author Lorenzo Cogotti, Andrea Pasquini
|
|
|
|
|
2022-08-24 11:18:48 +02:00
|
|
|
local BASE = (...):gsub('label$', '')
|
2022-08-15 23:41:17 +02:00
|
|
|
|
2022-08-16 00:23:52 +02:00
|
|
|
local Widget = require(BASE..'widget')
|
|
|
|
local core = require(BASE..'core')
|
2022-08-15 23:41:17 +02:00
|
|
|
|
|
|
|
local shadowtext = require 'lib.gear.shadowtext'
|
|
|
|
local T = require('lib.moonspeak').translate
|
|
|
|
|
|
|
|
-- Labels don't accept focus
|
2022-08-24 11:18:48 +02:00
|
|
|
local Label = setmetatable({
|
|
|
|
nofocus = true,
|
2022-10-25 13:26:30 +02:00
|
|
|
__call = function(cls, args) return cls:new(args) end
|
2022-08-24 11:18:48 +02:00
|
|
|
}, Widget)
|
2022-08-15 23:41:17 +02:00
|
|
|
Label.__index = Label
|
|
|
|
|
2022-09-12 09:34:46 +02:00
|
|
|
--- Attributes accepted by the @{Label} widget in addition to the standard @{yui.Widget.WidgetAttributes|attributes}.
|
|
|
|
--
|
|
|
|
-- @field text (string) text displayed inside the Label
|
|
|
|
-- @field[opt='center'] valign (string) vertical alignment 'top', 'bottom', 'center'
|
|
|
|
-- @field[opt='center'] align (string) horizontal alignment, 'left', 'center', 'right'
|
|
|
|
-- @field notranslate (boolean) don't translate text
|
|
|
|
-- @table LabelAttributes
|
2022-08-15 23:41:17 +02:00
|
|
|
|
2022-09-12 09:34:46 +02:00
|
|
|
--- Label constructor
|
|
|
|
-- @param args (@{LabelAttributes}) widget attributes
|
2022-10-25 13:26:30 +02:00
|
|
|
function Label:new(args)
|
|
|
|
self = setmetatable(args, self)
|
2022-08-15 23:41:17 +02:00
|
|
|
|
|
|
|
self.text = self.text or ""
|
|
|
|
self.text = self.notranslate and self.text or T(self.text)
|
|
|
|
self.align = self.align or 'center'
|
|
|
|
self.valign = self.valign or 'center'
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
function Label:draw()
|
|
|
|
local x,y,w,h = self.x,self.y,self.w,self.h
|
2022-10-25 19:06:57 +02:00
|
|
|
local color, font, _ = core.themeForWidget(self)
|
2022-08-15 23:41:17 +02:00
|
|
|
|
|
|
|
y = y + core.verticalOffsetForAlign(self.valign, font, h)
|
|
|
|
|
2022-10-25 19:06:57 +02:00
|
|
|
love.graphics.setColor(color.normal.fg)
|
2022-08-15 23:41:17 +02:00
|
|
|
love.graphics.setFont(font)
|
|
|
|
shadowtext.printf(self.text, x+2, y, w-4, self.align)
|
|
|
|
end
|
|
|
|
|
|
|
|
return Label
|