40 lines
866 B
Lua
40 lines
866 B
Lua
require 'point'
|
|
|
|
-- default font size
|
|
local fontsize = 12
|
|
|
|
-- UI Text
|
|
---@class Text
|
|
---@field position Point
|
|
---@field size Point
|
|
---@field text string
|
|
---@field align love.AlignMode
|
|
Text = {
|
|
position = Point:new( 1, 1 ),
|
|
size = Point:new( 1, 1 ),
|
|
text = "Sample text",
|
|
align = "center"
|
|
}
|
|
|
|
function Text:new( position, size, text, align )
|
|
local txt = {
|
|
position = position or Text.position,
|
|
size = size or Text.size,
|
|
text = text or Text.text,
|
|
align = align or Text.align
|
|
}
|
|
|
|
setmetatable( txt, { __index = self } )
|
|
|
|
return txt
|
|
end
|
|
|
|
function Text:draw()
|
|
local x, y = self.position:coords()
|
|
local w, h = self.size:coords()
|
|
local oy = 0
|
|
if self.align == "center" then
|
|
oy = -h / 2 + fontsize / 2
|
|
end
|
|
love.graphics.printf(self.text, x, y, w, self.align, 0, 1, 1, 0, oy )
|
|
end
|