File docs/luadoc/goo.luadoc
GUI Library.
Goo is a gui lib that uses inherited positioning.
What this means is that a object's position is always relative to it's parent's position.
Some of you may recognise this as a scene graph.
Goo also uses skins and styles which means you can easily change and seperate the object look from it's logic.
To load place the following functions in their respective love function.
goo = require 'goo/goo'
goo:load()
goo:update(dt)
goo:draw()
goo:mousepressed(x,y,button)
goo:mousereleased(x,y,button)
goo:keypressed(key,unicode)
goo:keyreleased(key,unicode)
Functions
goo.object:new (parent) | Creates a goo object. |
goo:debugdraw () | Draw a debug interface. |
goo:draw () | Draws all goo objects. |
goo:load () | Loads the goo library. |
goo:setSkin (skin_name) | Sets the skin of goo, default is 'default'. |
goo:setSkinAllObjects (skin_name) | Sets the skin and updates all objects to use that skin. |
goo:update (dt) | Updates all goo objects. |
Tables
goo_object | Standard goo object structure. |
style | Style table structure. |
Examples
Panel with button. | Show a panel with a button that prints a message on click. |
Functions
- goo.object:new ( parent )
-
Creates a goo object.
This is the main method to create gui objects, replace goo.object with a goo object.
All goo objects inherit methods from goo.objectParameters
-
parent :goo_object
the parent object to use. Position and scale will be inherited from it's parent.
Usage:
panel = goo.panel:new(); button = goo.button:new( panel )
Return value:
goo_object: A goo object instance. Use links below to see the methods you can call on the table.
See also:
-
parent :goo_object
- goo:debugdraw ( )
-
Draw a debug interface.
Will show the mouse position and the name of the goo object the mouse is over. - goo:draw ( )
-
Draws all goo objects.
- goo:load ( )
-
Loads the goo library.
- goo:setSkin ( skin_name )
-
Sets the skin of goo, default is 'default'.
Skins are kept in goo/skins/
If you have already created objects you should use goo:setSkinAllObjectsParameters
-
skin_name :string
the name of the skin, i.e. 'default', 'dark'.
See also:
-
skin_name :string
- goo:setSkinAllObjects ( skin_name )
-
Sets the skin and updates all objects to use that skin.
any objects with overriden styles will be set to the skin's style.Parameters
-
skin_name :string
the name of the skin, i.e. 'default', 'dark'.
See also:
-
skin_name :string
- goo:update ( dt )
-
Updates all goo objects.
Tables
- goo_object
- Standard goo object structure.
Fields
- parent The parent instance of the object.
- super The parent class of the object. To hook an internal function rather than override use super.function(self,...), see usage below.
- children A list of all children instances.
- x The x position.
- y The y position.
- w The width.
- h The height.
- bounds The bounding box. Represented by a table: {x1,y1,x2,y2}. Used for detecting mouse events.
- xscale The x scale.
- yscale The y scale.
- opacity The opacity of the object.
- visible Boolean representing if the object is being drawn.
- mouseHover Boolean representing if the mouse is ontop of the object.
Usage:
button = goo.button:new()
button.draw = function(self)
super.draw(self)
love.graphics.circle( 'line', 0, 0, 20 ) -- we use 0 for x,y because position is always relative to itself.
end
-- will draw a button with a circle ontop, not just a circle.
- style
- Style table structure. Possible keys:
Fields
- backgroundColor
- backgroundColorHover
- borderColor
- borderColorHover
- borderWidth
- textColor
- textColorHover
- textFont
- color
- colorHover
- titleColor
- titleColorHover
- lineHeight
Usage:
excerpt from default/style.luastyle['goo button'] = {
backgroundColor = {100,100,100},
backgroundColorHover = {131,203,21},
borderColor = {0,0,0,255},
borderColorHover = {0,0,0},
textColor = {255,255,255},
textColorHover = {255,255,255},
textFont = fonts.oldsans12
}
Examples
- Panel with button.
-
local panel = goo.panel:new()
panel:setPos( 10, 10 )
panel:setSize( 200, 200 )
panel:setTitle( 'I am a panel' )
local button = goo.button:new( panel )
button:setPos( 10, 20 )
print( button:getAbsolutePos() ) -- 20, 30
button:setText( 'Click me' )
button:sizeToText()
button.onClick = function( self, x, y, button )
print( 'I have been clicked' )
end