summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-11 22:06:54 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-11 22:06:54 +0100
commita791ef162868c65284903ab479731e0dc9e7a223 (patch)
tree28384c5647086db87c822b186860492dfce23af3 /tests
parentd34707a6ae058560140c83af21365884451e9274 (diff)
Pretty good stack layouter ✈
Diffstat (limited to 'tests')
-rw-r--r--tests/layouts/stack.typ81
-rw-r--r--tests/layouts/test.typ52
-rw-r--r--tests/render.py5
3 files changed, 84 insertions, 54 deletions
diff --git a/tests/layouts/stack.typ b/tests/layouts/stack.typ
new file mode 100644
index 00000000..934480ca
--- /dev/null
+++ b/tests/layouts/stack.typ
@@ -0,0 +1,81 @@
+[page.size: w=5cm, h=5cm]
+[page.margins: 0cm]
+
+// Test 1
+[box: w=1, h=1, debug=false][
+ [box][
+ [align: center]
+ [box: ps=3cm, ss=1cm]
+ [direction: ttb, ltr]
+ [box: ps=3cm, ss=1cm]
+ [box: ps=1cm, ss=1cm]
+ [box: ps=2cm, ss=1cm]
+ [box: ps=1cm, ss=1cm]
+ ]
+]
+[page.break]
+
+// Test 2
+[box: w=1, h=1, debug=false][
+ [align: secondary=top] Top
+ [align: secondary=center] Center
+ [align: secondary=bottom] Bottom
+ [direction: ttb, ltr]
+ [align: secondary=origin, primary=bottom]
+ [box: w=1cm, h=1cm]
+]
+[page.break]
+
+// Test 3
+[box: w=1, h=1, debug=false][
+ [align: center][
+ Somelongspacelessword!
+ [align: left] Some
+ [align: right] word!
+ ]
+]
+[page.break]
+
+// Test 4
+[box: w=1, h=1, debug=false][
+ [direction: ltr, ttb]
+ [align: center]
+ [align: secondary=origin]
+ [box: ps=1cm, ss=1cm]
+ [align: secondary=center]
+ [box: ps=3cm, ss=1cm]
+ [box: ps=4cm, ss=0.5cm]
+ [align: secondary=end]
+ [box: ps=2cm, ss=1cm]
+]
+[page.break]
+
+// Test 5
+[box: w=1, h=1, debug=false][
+ [direction: primary=btt, secondary=ltr]
+ [align: primary=center, secondary=left]
+ [box: h=2cm, w=1cm]
+
+ [direction: rtl, btt]
+ [align: center]
+ [align: vertical=origin] ORIGIN
+ [align: vertical=center] CENTER
+ [align: vertical=end] END
+]
+[page.break]
+
+// Test 6
+[box: w=1, h=1, debug=false][
+ [box: w=4cm, h=1cm]
+
+ [align: primary=right, secondary=center] CENTER
+
+ [direction: btt, rtl]
+ [align: primary=center, secondary=origin]
+ [box: w=0.5cm, h=0.5cm]
+ [box: w=0.5cm, h=1cm]
+ [box: w=0.5cm, h=0.5cm]
+
+ [align: primary=origin, secondary=end]
+ END
+]
diff --git a/tests/layouts/test.typ b/tests/layouts/test.typ
deleted file mode 100644
index 4b55e556..00000000
--- a/tests/layouts/test.typ
+++ /dev/null
@@ -1,52 +0,0 @@
-[page.size: w=5cm, h=5cm]
-[page.margins: 0cm]
-
-// Test 1
-// [box][
-// [align: center]
-// [box: ps=3cm, ss=1cm]
-// [direction: ttb, ltr]
-// [box: ps=3cm, ss=1cm]
-// [box: ps=1cm, ss=1cm]
-// [box: ps=2cm, ss=1cm]
-// [box: ps=1cm, ss=1cm]
-// ]
-
-// Test 2
-// [align: secondary=top] Top
-// [align: secondary=center] Center
-// [align: secondary=bottom] Bottom
-// [direction: ttb, ltr]
-// [align: primary=bottom]
-// [box: w=1cm, h=1cm]
-
-// Test 3
-// [align: center][
-// Somelongspacelessword!
-// [align: left] Some
-// [align: right] word!
-// ]
-
-// Test 4: In all combinations, please!
-// [direction: ltr, ttb]
-// [align: center]
-// [align: secondary=origin]
-// [box: ps=1cm, ss=1cm]
-// [align: secondary=center]
-// [box: ps=3cm, ss=1cm]
-// [box: ps=4cm, ss=0.5cm]
-// [align: secondary=end]
-// [box: ps=2cm, ss=1cm]
-
-[align: primary=left, secondary=center]
-[box: w=4cm, h=2cm]
-
-[direction: primary=btt, secondary=ltr]
-[align: primary=center, secondary=left]
-[box: h=2cm, w=1cm]
-
-// [direction: rtl, btt]
-// [align: center]
-// [align: vertical=origin] ORIGIN
-// [align: vertical=center] CENTER
-// [align: vertical=end] END
diff --git a/tests/render.py b/tests/render.py
index 93d59ea8..fe7a1de4 100644
--- a/tests/render.py
+++ b/tests/render.py
@@ -56,7 +56,6 @@ class MultiboxRenderer:
renderer = BoxRenderer(self.fonts, width, height)
for i in range(action_count):
- if i == 0: continue
command = self.content[start + i]
renderer.execute(command)
@@ -134,7 +133,7 @@ class BoxRenderer:
if cmd == 'm':
x, y = (pix(float(s)) for s in parts)
- self.cursor = (x, y)
+ self.cursor = [x, y]
elif cmd == 'f':
index = int(parts[0])
@@ -143,7 +142,9 @@ class BoxRenderer:
elif cmd == 'w':
text = command[2:]
+ width = self.draw.textsize(text, font=self.font)[0]
self.draw.text(self.cursor, text, (0, 0, 0, 255), font=self.font)
+ self.cursor[0] += width
elif cmd == 'b':
x, y = self.cursor