Skip to content

Instantly share code, notes, and snippets.

@pablomayobre
Last active August 28, 2016 23:21
Show Gist options
  • Save pablomayobre/54a8c415205a3503bf9737c19239793e to your computer and use it in GitHub Desktop.
Save pablomayobre/54a8c415205a3503bf9737c19239793e to your computer and use it in GitHub Desktop.
Styled text reference
--"?" Means optional
--"*" Means 0 or more times
--"+" Means 1 or more times
--NUMBER is a valid Lua number, most of the time it should be positive and never +inf or -inf, it may be floating point
--FONT is a font for the specific engine the library is being used in (LÖVE)
--This will change in the future to use a framework agnostic type
--COLOR is a table with three or four numbers for red, green, blue and alpha, in that order and in the range of [0,255].
--Example: {0, 255, 0, 128} green with half transparency
--TEXT is a string representing the text to be drawn for that subnode
text = {
type = "Styled Text"
--Useful to dimension the text area
height = NUMBER,
width = NUMBER,
LINE*
}
LINE = {
--Finding end of the line for cursor
length = NUMBER,
width = NUMBER,
--Line height
height = NUMBER,
--Y positioning
y = NUMBER,
NODE*
}
NODE = {
--Font of the node
font = FONT,
SUBNODE*
}
SUBNODE = {
--This function is called before anything is drawn
predraw = PREDRAW?,
--Colors
background = COLOR?, --Defaults to {0, 0, 0, 0}
color = COLOR?, --Defaults to engine.getColor()
--This function is called after background has been set and before the text has been drawn
draw = DRAW?,
--This function is called after rendering is complete
postdraw = POSTDRAW?,
--X positioning of this subnode
x = NUMBER,
--The actual string to be printed
TEXT
}
--NOTE: All drawing operations should happen inside of the bounding box declared as x, y, w and lineheight
--If not, then they may interfere with other parts of the text
POSTDRAW = function (text, x, y, w, h, lineheight, font, color, background)
return --Ignored
end
DRAW = function (text, x, y, w, h, lineheight, font, color, background, postdraw)
return --true: Don't render the text
end
PREDRAW = function (text, x, y, w, h, lineheight, font, color, background, draw, postdraw)
return --true: Stop drawing this subnode
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment