-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
48 lines (40 loc) · 1.35 KB
/
Copy pathmain.lua
File metadata and controls
48 lines (40 loc) · 1.35 KB
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
local love = require("love")
local anchors = require("anchors")
local root = {
anchors = { 0.25, 0.25, 0.75, 0.75 }, -- anchor sides in order: left, up, down, right
offsets = nil, -- { left, top, right, bottom }, in pixels
size = nil, -- { x, y }, relative to the top left position, ignore right and bottom anchors
children = {
-- each supports offets and size
{ anchors = { 0.05, 0.05, 0.45, 0.95 } },
{ anchors = { 0.55, 0.05, 0.95, 0.95 } },
{ anchors = { 0.25, 0.25, 0.75, 0.75 } }
}
}
local frame
function love.resize(_, _)
frame = anchors.build(root, love.graphics.getDimensions())
end
function love.load()
love.window.setMode(800, 600, {
resizable = true
})
love.window.setTitle("Anchors")
love.graphics.setDefaultFilter("nearest", "nearest")
frame = anchors.build(root)
end
function love.draw()
love.graphics.setColor(0, 0, 0)
love.graphics.clear()
love.graphics.setColor(0.2, 0.2, 0.2)
love.graphics.rectangle("fill", frame:toXYWH())
local frame1 = frame.children[1]
local frame2 = frame.children[2]
local frame3 = frame.children[3]
love.graphics.setColor(1, 0, 0, 0.7)
love.graphics.rectangle("fill", frame1:toXYWH())
love.graphics.setColor(0, 1, 0, 0.7)
love.graphics.rectangle("fill", frame2:toXYWH())
love.graphics.setColor(0, 0, 1, 0.7)
love.graphics.rectangle("fill", frame3:toXYWH())
end