-
Notifications
You must be signed in to change notification settings - Fork 3
Button Object (Cobalt UI)
ebernerd edited this page Aug 14, 2016
·
4 revisions
The button object is, well... a button. It can have varying widths and heights (which can be percentages, i.e. 50%
) and actions.
This object requires cobalt.mousepressed( x, y, button )
and cobalt.mousereleased( x, y, button )
to be defined, with Cobalt UI's callbacks inserted.
-
x
- the x position, relative to the parent -
y
- the y position, relative to the parent -
w
- the width of the object -
h
- the height of the object -
text
- the text to display on the button -
backColour
- the background colour of the object -
foreColour
- the colour of thetext
-
marginleft
- the left margin, relative to the parent -
margintop
- the top margin, relative to the parent -
wrap
- tells the object how to wrap (left
,center
) *Note - as of Cobalt v1.0, this only works on the x axis) -
state
- determines if the object should draw, depending oncobalt.state
. Useful for multi-screen apps. Default is its parent'sstate
.
-
:resize( w, h )
- tells the button to resize. UsingButton.w
orButton.h
to resize may cause unexpected results. -
:setMargins( top, left )
- sets the margins -
.onclick()
- defined by the user to tell the object what to do when it is clicked.
This example will output a simple button that changes colour when you press it.
local cobalt = dofile( "cobalt" )
cobalt.ui = dofile( "cobalt-ui/init.lua" )
local Panel = cobalt.ui.new({ w = "50%", marginleft="25%", h = "50%", margintop = "25%" })
local Button = Panel:add("button", { wrap="center", y = 4})
Button.onclick = function()
Button.backColour = 2 ^ math.random( 1, 15 )
end
function cobalt.draw()
cobalt.ui.draw()
end
function cobalt.mousepressed( x, y, button )
cobalt.ui.mousepressed( x, y, button )
end
function cobalt.mousereleased( x, y, button )
cobalt.ui.mousereleased( x, y, button )
end
cobalt.initLoop()
Result:
This project has been retired. Please view Cobalt 2.