-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextbox.lua
41 lines (33 loc) · 1009 Bytes
/
textbox.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
Textbox = {}
Textbox.__index = Textbox
function Textbox.create(label, x, y)
local text = {} -- our new object
setmetatable(text,Textbox)
text.x = x
text.y = y
text.label = label
text.labelOffset = 100 -- TODO: calculate based on length of label
text.width = 130
text.height = 25
text.content = ""
return text
end
function Textbox:draw()
love.graphics.push()
love.graphics.translate(self.x, self.y)
love.graphics.print(self.label, 0, 0)
love.graphics.rectangle("fill", self.labelOffset, 0, self.width, self.height)
love.graphics.setColor(0, 0, 0)
love.graphics.print(self.content, self.labelOffset + 5, 0)
love.graphics.setColor(255, 255, 255)
love.graphics.pop()
end
function Textbox:mousepressed(x, y)
-- check if within bounds of text box
if x >= self.x + self.labelOffset and x <= self.x + self.width + self.labelOffset then
if y >= self.y and y <= self.y + self.height then
--selectedTextbox = self
return true
end
end
end