-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
98 lines (76 loc) · 2.21 KB
/
main.lua
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
io.stdout:setvbuf('no') -- show debug output live in SublimeText console
local composer = require "composer"
local layout_idx = 0
local layout = nil
local window_w = 0
local window_h = 0
local function updateLayout()
local is_debug = true
layout_idx = layout_idx + 1
if layout_idx > 3 then layout_idx = 1 end
local path = "examples/example" .. layout_idx .. ".lua"
print("loading:", path)
layout = composer.load(path, is_debug)
layout.getElement("test1", function(e)
e.widget.setText("this text is changed using the ID")
end)
layout.getElement("button", function(e)
e.widget.setTitle("these colors are changed using the ID")
e.widget.setColors({ 0.5, 0.0, 0.0 }, { 0.0, 0.5, 0.0, 0.5 })
end)
end
local function resizeLayout()
layout.resize(window_w, window_h, function(e)
e.widget.setFrame(e.rect.x, e.rect.y, e.rect.w, e.rect.h)
print(e)
end)
end
function love.load(args)
local desktop_w, desktop_h = love.window.getDesktopDimensions()
local flags = {
resizable = true,
minwidth = desktop_w * 0.4,
minheight = desktop_h * 0.5,
}
love.window.setMode(desktop_w * 0.6, desktop_h * 0.7, flags)
love.keyboard.pressed = {}
love.keyboard.wasPressed = function(key)
return love.keyboard.pressed[key] == true
end
love.keyboard.released = {}
love.keyboard.wasReleased = function(key)
return love.keyboard.released[key] == true
end
-- add custom controls to the layout engine loader
composer.require("widgets/widgets.lua")
updateLayout()
window_w, window_h = love.window.getMode()
resizeLayout()
love.window.setTitle("Composer v" .. composer._VERSION)
--[[ print("\n\n")
for k, v in pairs(_G.package.loaded) do
print(k, v)
end
print("\n\n")
--]]
end
function love.update(dt)
layout.update(dt)
end
function love.draw()
-- draw white background
love.graphics.setColor(1.0, 1.0, 1.0)
love.graphics.rectangle("fill", 0, 0, window_w, window_h)
layout:draw()
end
function love.resize(w, h)
window_w, window_h = w, h
resizeLayout()
end
function love.keypressed(key, code)
if key == "g" then
updateLayout()
local window_w, window_h = love.window.getMode()
resizeLayout(window_w, window_h)
end
end