mirror of https://gitea.it/1414codeforge/yui
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
990 B
Lua
38 lines
990 B
Lua
2 years ago
|
local BASE = (...):gsub('label', '')
|
||
|
|
||
|
local Widget = require BASE..'widget'
|
||
|
local core = require BASE..'core'
|
||
|
|
||
|
local shadowtext = require 'lib.gear.shadowtext'
|
||
|
local T = require('lib.moonspeak').translate
|
||
|
|
||
|
-- Labels don't accept focus
|
||
|
local Label = setmetatable({ nofocus = true }, Widget)
|
||
|
Label.__index = Label
|
||
|
|
||
|
|
||
|
function Label.new(args)
|
||
|
local self = setmetatable(args, Label)
|
||
|
|
||
|
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'
|
||
|
self.color = self.color or core.theme.color
|
||
|
return self
|
||
|
end
|
||
|
|
||
|
function Label:draw()
|
||
|
local x,y,w,h = self.x,self.y,self.w,self.h
|
||
|
local font = self.font or love.graphics.getFont()
|
||
|
local c = self.color.normal
|
||
|
|
||
|
y = y + core.verticalOffsetForAlign(self.valign, font, h)
|
||
|
|
||
|
love.graphics.setColor(c.fg)
|
||
|
love.graphics.setFont(font)
|
||
|
shadowtext.printf(self.text, x+2, y, w-4, self.align)
|
||
|
end
|
||
|
|
||
|
return Label
|