Layouter is a simple UI grid layout library for LÖVE 2D game engine.
It currently supports these element types:
- text (including spacer = blank text)
- text button
- image
layouter = require 'layouter'
Defaults=15px, white background, black color, debug disabled:
layouter.initialize()
or with a custom look (font=20px, background=black, color=white, debug mode enabled=draw grid):
layouter.initialize({font=love.graphics.newFont(20), background={0,0,0}, color={255,255,255}, debug=true})
layouter.add('Hello world!')
layouter.add({content = 'Second text paragraph', font = love.graphics.newFont(50), color = {13, 46, 63}})
layouter.add()
layouter.add({content = love.graphics.newImage('logo.png'), type = 'image', key = 'logo'})
layouter.add({content = 'Start game', type = 'button', callback = function() startGame() end})
Note the automatically assigned key eastereggs
that is created from the text.
layouter.add({content = '* easter! Eggs $@', type = 'button', callback = function() layouter.replace('eastereggs', 'Currently does nothing.') end})
Set where to draw your elements, how they should be aligned horizontaly or vertically and if auto spacing (based on number of elements) should be done.
x=position X, y=position Y, direction=horizontal
or vertical
, spacing=auto
for automatical centering, optionally also padding=(in pixels)
layouter.prepare({x = layouter.COLUMN6, y = layouter.ROW4, direction = 'vertical', spacing = 'auto'})
function love.draw()
layouter.draw()
end
This functions needs to be called to enable interaction for buttons.
function love.mousepressed(x, y, mouse_button, is_touch)
layouter.processMouse(x, y, mouse_button, is_touch)
end
The grid comes with 24 columns and 16 rows. Layouter automatically calculates sizes of columns and rows and generates helper variables. You can use these helper variables to position your elements and layout easily:
-- columns:
layouter.COLUMN1 -- first column's right side, i.e. will position element right after first column
-- ...
layouter.COLUMN8 -- X position after width of eight columns
--- rows:
layouter.ROW1 -- Y position after height of a first row
-- ...
layouter.ROW4 -- Y position after height of four rows