aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Richter <vrld@vrld.org>2013-02-06 13:27:55 +0100
committerMatthias Richter <vrld@vrld.org>2013-02-06 13:27:55 +0100
commit7f0689d012c62cd4068cabe1ec3f0e0920901b03 (patch)
tree8ed1a560eb8f9942789e44d00c0ba57801bc98fc
parent3cc1581bf4cb27f4c0a7baf9511c49ad10cb45d8 (diff)
downloadQuickie-7f0689d012c62cd4068cabe1ec3f0e0920901b03.tar.gz
Quickie-7f0689d012c62cd4068cabe1ec3f0e0920901b03.tar.bz2
Quickie-7f0689d012c62cd4068cabe1ec3f0e0920901b03.tar.xz
Quickie-7f0689d012c62cd4068cabe1ec3f0e0920901b03.zip
Fix example in readme
-rw-r--r--README.md255
1 files changed, 132 insertions, 123 deletions
diff --git a/README.md b/README.md
index bd34479..bb76e4c 100644
--- a/README.md
+++ b/README.md
@@ -5,129 +5,138 @@ Quickie is an [immediate mode gui][IMGUI] library for [L&Ouml;VE][LOVE]. Initial
# Example
- 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()
- love.graphics.setBackgroundColor(17,17,17)
- love.graphics.setFont(fonts[12])
-
- -- group defaults
- gui.group.default.size[1] = 150
- gui.group.default.size[2] = 25
- gui.group.default.spacing = 5
- end
-
- local menu_open = {
- main = false,
- 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
- gui.group.push{grow = "right"}
- if gui.Button{text = "Group stacking"} then
- menu_open.right = not menu_open.right
- end
-
- if menu_open.right then
- gui.group.push{grow = "up"}
- 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"}
- gui.Button{text = "Baz"}
- end
- gui.group.pop{}
-
- if gui.Button{text = "Widget demo"} then
- menu_open.demo = not menu_open.open
- end
-
- end
- gui.group.pop{}
-
- if menu_open.demo then
- gui.group{grow = "down", pos = {200, 80}, function()
-
- love.graphics.setFont(fonts[20])
- gui.Label{text = "Widgets"}
- 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()
- gui.Button{text = "", size = {2}} -- acts as separator
- gui.Label{text = "Tight Label", size = {"tight"}}
- gui.Button{text = "", size = {2}}
- gui.Label{text = "Center Label", align = "center"}
- gui.Button{text = "", size = {2}}
- gui.Label{text = "Another Label"}
- gui.Button{text = "", size = {2}}
- end}
-
- gui.group.push{grow = "right"}
- if gui.Checkbox{checkbox = check1, text = "Checkbox", size = {"tight"}} then
- check1 = not check1
- if gui.Checkbox{checkbox = check2, text = "Another Checkbox"} then
- check2 = not check2
- end
- if gui.Checkbox{checkbox = check2, text = "Linked Checkbox"} then
- check2 = not check2
- end
- gui.group.pop{}
-
- gui.group.push{grow = "right", function()
- gui.Label{text = "Input", size = {70}}
- gui.Input{info = input, size = {300}}
- end}
-
- gui.group.push{grow = "right", function()
- gui.Label{text = "Slider", size = {70}}
- gui.Slider{info = slider}
- gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}}
- end}
-
- gui.Label{text = "2D Slider", pos = {nil,10}}
- gui.Slider2D{info = slider2d, size = {250, 250}}
- gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])}
- end}
- end
- end
-
- function love.draw()
- gui.core.draw()
- end
-
- function love.keypressed(key, code)
- gui.keyboard.pressed(key, code)
- end
-
+ local gui = require "Quickie"
+
+ function love.load()
+ -- preload fonts
+ fonts = {
+ [12] = love.graphics.newFont(12),
+ [20] = love.graphics.newFont(20),
+ }
+ love.graphics.setBackgroundColor(17,17,17)
+ love.graphics.setFont(fonts[12])
+
+ -- group defaults
+ gui.group.default.size[1] = 150
+ gui.group.default.size[2] = 25
+ gui.group.default.spacing = 5
+ end
+
+ local menu_open = {
+ main = false,
+ 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}}
+
+ -- all widgets return true if they are clicked on/activated
+ if gui.Checkbox{checked = menu_open.main, text = "Show Menu"} then
+ menu_open.main = not menu_open.main
+ end
+
+ if menu_open.main then
+ gui.group.push{grow = "right"}
+
+ -- 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
+ end
+
+ if menu_open.right then
+ gui.group.push{grow = "up"}
+ 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"}
+ gui.Button{text = "Baz"}
+ end
+ gui.group.pop{}
+
+ if gui.Button{text = "Widget demo"} then
+ menu_open.demo = not menu_open.open
+ end
+
+ end
+ gui.group.pop{}
+
+ if menu_open.demo then
+ gui.group{grow = "down", pos = {200, 80}, function()
+ love.graphics.setFont(fonts[20])
+ gui.Label{text = "Widgets"}
+ love.graphics.setFont(fonts[12])
+ gui.group{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{grow = "right", function()
+ gui.Button{text = "", size = {2}} -- acts as separator
+ gui.Label{text = "Tight Label", size = {"tight"}}
+ gui.Button{text = "", size = {2}}
+ gui.Label{text = "Center Label", align = "center"}
+ gui.Button{text = "", size = {2}}
+ gui.Label{text = "Another Label"}
+ gui.Button{text = "", size = {2}}
+ end}
+
+ gui.group.push{grow = "right"}
+ if gui.Checkbox{checked = check1, text = "Checkbox", size = {"tight"}} then
+ check1 = not check1
+ 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{grow = "right", function()
+ gui.Label{text = "Input", size = {70}}
+ gui.Input{info = input, size = {300}}
+ end}
+
+ gui.group{grow = "right", function()
+ gui.Label{text = "Slider", size = {70}}
+ gui.Slider{info = slider}
+ gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}}
+ end}
+
+ gui.Label{text = "2D Slider", pos = {nil,10}}
+ gui.Slider2D{info = slider2d, size = {250, 250}}
+ gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])}
+ 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
+
+ function love.draw()
+ gui.core.draw()
+ end
+
+ function love.keypressed(key, code)
+ gui.keyboard.pressed(key, code)
+ end
# Documentation