Skip to content
tavuntu edited this page Jan 9, 2017 · 19 revisions

Let's create a button with an event. X and Y coordinates are 10 and 10 by default, width and height fit the text:

require "gooi"
function love.load()
	gooi.newButton("Exit"):onRelease(function()
		love.event.quit()
	end)
end

function love.draw()
	gooi.draw()
end

function love.mousepressed(x, y, button)  gooi.pressed() end
function love.mousereleased(x, y, button) gooi.released() end

-- Use these for Android:
--[[
	function love.touchpressed(id, x, y)  gooi.pressed(id, x, y) end
	function love.touchreleased(id, x, y) gooi.released(id, x, y) end
	function love.touchmoved(id, x, y)    gooi.moved(id, x, y) end
]]

Result:

demo_button.png

Adding more:

require "gooi"
function love.load()
    gooi.newButton({
        text = "Exit",
        x = 100,
        y = 100,
        w = 150,
        h = 35,
        align = "left"
    }):onRelease(function()
        gooi.confirm("Are you sure?", function()
            love.event.quit()
        end)
    end)
    :bg("#FFFF00")-- yellow
    :fg({0, 0, 0})-- black
    :setRadius(6)-- corner radius
    :border(3, "#FF8800")-- 3 pixels width, orange

end

function love.draw()
    gooi.draw()
end

function love.mousepressed(x, y, button)  gooi.pressed() end
function love.mousereleased(x, y, button) gooi.released() end

Result:

btn_more_1.png btn_more_2.png

Channeling a value:

require "gooi"
function love.load()
	btn = gooi.newButton({
		text = "Exit",
		x = 100,
		y = 100,
		w = 150,
		h = 35,
		align = "left"
	}):onRelease(function()
		gooi.confirm("Are you sure?", function()
			love.event.quit()
		end)
	end)
	:bg("#FFFF00")-- yellow
	:fg({0, 0, 0})-- black
	:setRadius(6)-- corner radius
	:border(3, "#FF8800")-- 3 pixels width, orange

	slider = gooi.newSlider(1)-- move it to change from yellow to red
end

function love.update(dt)
	gooi.update(dt)
	btn:bg({255, slider:getValue() * 255, 0})
end

function love.draw()
	gooi.draw()
end

function love.mousepressed(x, y, button)  gooi.pressed() end
function love.mousereleased(x, y, button) gooi.released() end

btn_more_3.png

Clone this wiki locally