Fix example in readme

This commit is contained in:
Matthias Richter 2013-02-06 13:27:55 +01:00
parent 3cc1581bf4
commit 7f0689d012

View file

@ -7,14 +7,12 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
local gui = require "Quickie" local gui = require "Quickie"
-- lazy font loading
local fonts = setmetatable({}, {__index = function(t,k)
local f = love.graphics.newFont(k)
rawset(t, k, f)
return f
end })
function love.load() function love.load()
-- preload fonts
fonts = {
[12] = love.graphics.newFont(12),
[20] = love.graphics.newFont(20),
}
love.graphics.setBackgroundColor(17,17,17) love.graphics.setBackgroundColor(17,17,17)
love.graphics.setFont(fonts[12]) love.graphics.setFont(fonts[12])
@ -35,15 +33,20 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
local input = {text = ""} local input = {text = ""}
local slider = {value = .5} local slider = {value = .5}
local slider2d = {value = {.5,.5}} local slider2d = {value = {.5,.5}}
function love.update(dt) function love.update(dt)
gui.group.push{grow = "down", pos = {5,5}} gui.group.push{grow = "down", pos = {5,5}}
-- all widgets return true if they are clicked on/activated
if gui.Checkbox{checked = menu_open.main, text = "Show Menu"} then if gui.Checkbox{checked = menu_open.main, text = "Show Menu"} then
menu_open.main = not menu_open.main menu_open.main = not menu_open.main
end end
if menu_open.main then if menu_open.main then
gui.group.push{grow = "right"} gui.group.push{grow = "right"}
if gui.Button{text = "Group stacking"} then
-- widgets can have custom ID's for tooltips etc (see below)
if gui.Button{id = "group stacking", text = "Group stacking"} then
menu_open.right = not menu_open.right menu_open.right = not menu_open.right
end end
@ -71,17 +74,16 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
if menu_open.demo then if menu_open.demo then
gui.group{grow = "down", pos = {200, 80}, function() gui.group{grow = "down", pos = {200, 80}, function()
love.graphics.setFont(fonts[20]) love.graphics.setFont(fonts[20])
gui.Label{text = "Widgets"} gui.Label{text = "Widgets"}
love.graphics.setFont(fonts[12]) love.graphics.setFont(fonts[12])
gui.group.push{grow = "right", function() gui.group{grow = "right", function()
gui.Button{text = "Button"} gui.Button{text = "Button"}
gui.Button{text = "Tight Button", size = {"tight"}} gui.Button{text = "Tight Button", size = {"tight"}}
gui.Button{text = "Tight² Button", size = {"tight", "tight"}} gui.Button{text = "Tight² Button", size = {"tight", "tight"}}
end} end}
gui.group.push{grow = "right", function() gui.group{grow = "right", function()
gui.Button{text = "", size = {2}} -- acts as separator gui.Button{text = "", size = {2}} -- acts as separator
gui.Label{text = "Tight Label", size = {"tight"}} gui.Label{text = "Tight Label", size = {"tight"}}
gui.Button{text = "", size = {2}} gui.Button{text = "", size = {2}}
@ -92,22 +94,24 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
end} end}
gui.group.push{grow = "right"} gui.group.push{grow = "right"}
if gui.Checkbox{checkbox = check1, text = "Checkbox", size = {"tight"}} then if gui.Checkbox{checked = check1, text = "Checkbox", size = {"tight"}} then
check1 = not check1 check1 = not check1
if gui.Checkbox{checkbox = check2, text = "Another Checkbox"} then print(check1)
end
if gui.Checkbox{checked = check2, text = "Another Checkbox"} then
check2 = not check2 check2 = not check2
end end
if gui.Checkbox{checkbox = check2, text = "Linked Checkbox"} then if gui.Checkbox{checked = check2, text = "Linked Checkbox"} then
check2 = not check2 check2 = not check2
end end
gui.group.pop{} gui.group.pop{}
gui.group.push{grow = "right", function() gui.group{grow = "right", function()
gui.Label{text = "Input", size = {70}} gui.Label{text = "Input", size = {70}}
gui.Input{info = input, size = {300}} gui.Input{info = input, size = {300}}
end} end}
gui.group.push{grow = "right", function() gui.group{grow = "right", function()
gui.Label{text = "Slider", size = {70}} gui.Label{text = "Slider", size = {70}}
gui.Slider{info = slider} gui.Slider{info = slider}
gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}} gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}}
@ -118,6 +122,12 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])} gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])}
end} end}
end end
-- tooltip (see above)
if gui.mouse.isHot('group stacking') then
local mx,my = love.mouse.getPosition()
gui.Label{text = 'Demonstrates group stacking', pos = {mx+10,my-20}}
end
end end
function love.draw() function love.draw()
@ -128,7 +138,6 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
gui.keyboard.pressed(key, code) gui.keyboard.pressed(key, code)
end end
# Documentation # Documentation
To be done... To be done...