Module goo
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:keypressed (key, unicode) | Send keypress to goo |
goo:keyreleased (key, unicode) | Send keyrelease to goo |
goo:load () | Loads the goo library. |
goo:mousepressed (x, y, button) | Send mousepress to goo |
goo:mouserelease (x, y, button) | Send mouserelease to goo |
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. |
Slide in panel. | Show a panel that slides in. |
Zoom in panel. | Show a panel that zooms in bouncily with animated opacity too. |
Overriding styles. | Show a panel with two buttons, one of which has an overridden style. |
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:keypressed ( key, unicode )
-
Send keypress to goo
- goo:keyreleased ( key, unicode )
-
Send keyrelease to goo
- goo:load ( )
-
Loads the goo library.
- goo:mousepressed ( x, y, button )
-
Send mousepress to goo
- goo:mouserelease ( x, y, button )
-
Send mouserelease to goo
- 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, button )
print( 'I have been clicked' )
end
- Slide in panel.
-
local panel = goo.panel:new()
panel:setPos( -250, 50 )
panel:setSize( 200, 200 )
panel:setTitle( 'I am a panel' )
local checkbox = goo.checkbox:new( panel )
checkbox:setPos( 10, 20 )
function checkbox:onClick( button )
print( self.class.name .. ' has been clicked' )
end
function checkbox:enterHover()
print( self.class.name .. ' enter hover')
end
local slideIn = anim:new{
table = panel,
key = 'x',
finish = 350,
time = 2,
style = 'expoOut'
}
slideIn:play()
function slideIn:onFinish()
checkbox:setChecked( true )
end
- Zoom in panel.
-
local testPanel = goo.panel:new()
testPanel:setPos( 100, 50 )
testPanel:setSize( 370, 500 )
testPanel:setTitle( "This is a Color Panel." )
testPanel:setOpacity( 10 )
local colorPicker = goo.colorpick:new( testPanel )
colorPicker:setPos(0,20)
local input = goo.textinput:new( testPanel )
input:setPos(3,486)
input:setSize(360,20)
input:setText('hello!')
function colorPicker:onClick()
local r,g,b = self:getColor()
local str = string.format( 'Red = %i, Green = %i, Blue = %i', r,g,b)
input:setText( str )
end
anim:easy( testPanel, 'xscale', 0, 1, 3, 'elastic')
anim:easy( testPanel, 'yscale', 0.9, 1, 3, 'elastic')
anim:easy( testPanel, 'opacity', 0, 255, 0.5, 'quadInOut')
- Overriding styles.
-
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, button )
print( 'I have been clicked' )
end
local redButton = goo.button:new( panel )
redButton:setPos( 10, 100 )
redButton:setText( 'My style has been overridden' )
redButton:sizeToText( 10 )
local redStyle = {
backgroundColor = {255,0,0},
backgroundColorHover = {125,0,0},
borderColor = {0,0,0,0},
borderColorHover = {0,0,0,0},
}
redButton:setStyle( redStyle )