-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputLayout.py
More file actions
62 lines (49 loc) · 1.94 KB
/
inputLayout.py
File metadata and controls
62 lines (49 loc) · 1.94 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Draw
from HTMl_Tags import Text
from utils.getFonts import getFonts
import globals
class InputLayout:
def __init__(self, node, parent, previous):
self.node = node
self.parent = parent
self.previous = previous
self.children = []
self.width = globals.INPUT_WIDTH
def layout(self):
weight = self.node.style["font-weight"]
style = self.node.style["font-style"]
if style == "normal": style = "roman"
size = int(float(self.node.style["font-size"][:-2]) * .75)
self.font = getFonts(size, weight, style)
if self.previous:
space = self.previous.font.measure(" ")
self.x = self.previous.x + space + self.previous.width
else:
self.x = self.parent.x
self.height = self.font.metrics("linespace")
def should_paint(self):
return True
def paint(self):
commands = []
backgroundColour = self.node.style.get("background-color", "transparent")
if backgroundColour != "transparent":
rect = Draw.DrawRectangle(
Draw.Rect(self.x, self.y, self.x + self.width, self.y + self.height),
backgroundColour
)
commands.append(rect)
if self.node.tag == "input":
text = self.node.attributes.get("value", "")
elif self.node.tag == "button":
if len(self.node.children) == 1 and \
isinstance(self.node.children[0], Text):
text = self.node.children[0].text
else:
print("Ignoring HTML Content")
text = ""
if self.node.focused:
cx = self.x + self.font.measure(text)
commands.append(Draw.DrawLine(cx, self.y, cx, self.y + self.height, "black", 1))
color = self.node.style["color"]
commands.append(Draw.DrawText(self.x, self.y, text, self.font, color))
return commands