Fix example in readme

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

217
README.md
View file

@ -5,129 +5,138 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
# Example # Example
local gui = require "Quickie" local gui = require "Quickie"
-- lazy font loading function love.load()
local fonts = setmetatable({}, {__index = function(t,k) -- preload fonts
local f = love.graphics.newFont(k) fonts = {
rawset(t, k, f) [12] = love.graphics.newFont(12),
return f [20] = love.graphics.newFont(20),
end }) }
love.graphics.setBackgroundColor(17,17,17)
love.graphics.setFont(fonts[12])
function love.load() -- group defaults
love.graphics.setBackgroundColor(17,17,17) gui.group.default.size[1] = 150
love.graphics.setFont(fonts[12]) gui.group.default.size[2] = 25
gui.group.default.spacing = 5
end
-- group defaults local menu_open = {
gui.group.default.size[1] = 150 main = false,
gui.group.default.size[2] = 25 right = false,
gui.group.default.spacing = 5 foo = false,
end demo = false
}
local check1 = false
local check2 = false
local input = {text = ""}
local slider = {value = .5}
local slider2d = {value = {.5,.5}}
local menu_open = { function love.update(dt)
main = false, gui.group.push{grow = "down", pos = {5,5}}
right = false,
foo = false,
demo = false
}
local check1 = false
local check2 = false
local input = {text = ""}
local slider = {value = .5}
local slider2d = {value = {.5,.5}}
function love.update(dt)
gui.group.push{grow = "down", pos = {5,5}}
if gui.Checkbox{checked = menu_open.main, text = "Show Menu"} then
menu_open.main = not menu_open.main
end
if menu_open.main then -- all widgets return true if they are clicked on/activated
gui.group.push{grow = "right"} if gui.Checkbox{checked = menu_open.main, text = "Show Menu"} then
if gui.Button{text = "Group stacking"} then menu_open.main = not menu_open.main
menu_open.right = not menu_open.right end
end
if menu_open.right then if menu_open.main then
gui.group.push{grow = "up"} gui.group.push{grow = "right"}
if gui.Button{text = "Foo"} then
menu_open.foo = not menu_open.foo
end
if menu_open.foo then
gui.Button{text = "???"}
end
gui.group.pop{}
gui.Button{text = "Bar"} -- widgets can have custom ID's for tooltips etc (see below)
gui.Button{text = "Baz"} if gui.Button{id = "group stacking", text = "Group stacking"} then
end menu_open.right = not menu_open.right
gui.group.pop{} end
if gui.Button{text = "Widget demo"} then if menu_open.right then
menu_open.demo = not menu_open.open gui.group.push{grow = "up"}
end if gui.Button{text = "Foo"} then
menu_open.foo = not menu_open.foo
end
if menu_open.foo then
gui.Button{text = "???"}
end
gui.group.pop{}
end gui.Button{text = "Bar"}
gui.group.pop{} gui.Button{text = "Baz"}
end
gui.group.pop{}
if menu_open.demo then if gui.Button{text = "Widget demo"} then
gui.group{grow = "down", pos = {200, 80}, function() menu_open.demo = not menu_open.open
end
love.graphics.setFont(fonts[20]) end
gui.Label{text = "Widgets"} gui.group.pop{}
love.graphics.setFont(fonts[12])
gui.group.push{grow = "right", function()
gui.Button{text = "Button"}
gui.Button{text = "Tight Button", size = {"tight"}}
gui.Button{text = "Tight² Button", size = {"tight", "tight"}}
end}
gui.group.push{grow = "right", function() if menu_open.demo then
gui.Button{text = "", size = {2}} -- acts as separator gui.group{grow = "down", pos = {200, 80}, function()
gui.Label{text = "Tight Label", size = {"tight"}} love.graphics.setFont(fonts[20])
gui.Button{text = "", size = {2}} gui.Label{text = "Widgets"}
gui.Label{text = "Center Label", align = "center"} love.graphics.setFont(fonts[12])
gui.Button{text = "", size = {2}} gui.group{grow = "right", function()
gui.Label{text = "Another Label"} gui.Button{text = "Button"}
gui.Button{text = "", size = {2}} gui.Button{text = "Tight Button", size = {"tight"}}
end} gui.Button{text = "Tight² Button", size = {"tight", "tight"}}
end}
gui.group.push{grow = "right"} gui.group{grow = "right", function()
if gui.Checkbox{checkbox = check1, text = "Checkbox", size = {"tight"}} then gui.Button{text = "", size = {2}} -- acts as separator
check1 = not check1 gui.Label{text = "Tight Label", size = {"tight"}}
if gui.Checkbox{checkbox = check2, text = "Another Checkbox"} then gui.Button{text = "", size = {2}}
check2 = not check2 gui.Label{text = "Center Label", align = "center"}
end gui.Button{text = "", size = {2}}
if gui.Checkbox{checkbox = check2, text = "Linked Checkbox"} then gui.Label{text = "Another Label"}
check2 = not check2 gui.Button{text = "", size = {2}}
end end}
gui.group.pop{}
gui.group.push{grow = "right", function() gui.group.push{grow = "right"}
gui.Label{text = "Input", size = {70}} if gui.Checkbox{checked = check1, text = "Checkbox", size = {"tight"}} then
gui.Input{info = input, size = {300}} check1 = not check1
end} print(check1)
end
if gui.Checkbox{checked = check2, text = "Another Checkbox"} then
check2 = not check2
end
if gui.Checkbox{checked = check2, text = "Linked Checkbox"} then
check2 = not check2
end
gui.group.pop{}
gui.group.push{grow = "right", function() gui.group{grow = "right", function()
gui.Label{text = "Slider", size = {70}} gui.Label{text = "Input", size = {70}}
gui.Slider{info = slider} gui.Input{info = input, size = {300}}
gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}} end}
end}
gui.Label{text = "2D Slider", pos = {nil,10}} gui.group{grow = "right", function()
gui.Slider2D{info = slider2d, size = {250, 250}} gui.Label{text = "Slider", size = {70}}
gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])} gui.Slider{info = slider}
end} gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}}
end end}
end
function love.draw() gui.Label{text = "2D Slider", pos = {nil,10}}
gui.core.draw() gui.Slider2D{info = slider2d, size = {250, 250}}
end gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])}
end}
end
function love.keypressed(key, code) -- tooltip (see above)
gui.keyboard.pressed(key, code) if gui.mouse.isHot('group stacking') then
end local mx,my = love.mouse.getPosition()
gui.Label{text = 'Demonstrates group stacking', pos = {mx+10,my-20}}
end
end
function love.draw()
gui.core.draw()
end
function love.keypressed(key, code)
gui.keyboard.pressed(key, code)
end
# Documentation # Documentation