Added text table
This commit is contained in:
parent
d7dcda1ada
commit
8f9f2dd8f4
3 changed files with 56 additions and 5 deletions
40
text.lua
Normal file
40
text.lua
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue