aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: bd344798642bc796ea91c0fde175aa1d080df741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# QUICKIE

Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial inspiration came from the article [Sol on Immediate Mode GUIs (IMGUI)][Sol]. You should check it out to understand how Quickie works.


# 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


# Documentation

To be done...


# License

Copyright (c) 2012 Matthias Richter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

Except as contained in this notice, the name(s) of the above copyright holders
shall not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


[LOVE]: http://love2d.org
[IMGUI]: http://www.mollyrocket.com/forums/viewforum.php?f=10
[Sol]: http://sol.gfxile.net/imgui/