-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathtest_text_graphic.py
More file actions
101 lines (77 loc) · 2.95 KB
/
test_text_graphic.py
File metadata and controls
101 lines (77 loc) · 2.95 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
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
99
100
101
from numpy import testing as npt
import fastplotlib as fpl
from fastplotlib.graphics._features import (
FeatureEvent,
TextData,
FontSize,
TextFaceColor,
TextOutlineColor,
TextOutlineThickness,
)
import pygfx
def test_create_graphic():
fig = fpl.Figure()
data = "lorem ipsum"
text = fig[0, 0].add_text(data)
assert isinstance(text, fpl.TextGraphic)
assert isinstance(text._text, TextData)
assert text.text == data
assert text.font_size == 14
assert isinstance(text._font_size, FontSize)
assert text.world_object.geometry.font_size == 14
assert text.face_color == pygfx.Color("w")
assert isinstance(text._face_color, TextFaceColor)
assert text.world_object.material.color == pygfx.Color("w")
assert text.outline_color == pygfx.Color("w")
assert isinstance(text._outline_color, TextOutlineColor)
assert text.world_object.material.outline_color == pygfx.Color("w")
assert text.outline_thickness == 0
assert isinstance(text._outline_thickness, TextOutlineThickness)
assert text.world_object.material.outline_thickness == 0
EVENT_RETURN_VALUE: FeatureEvent = None
def event_handler(ev):
global EVENT_RETURN_VALUE
EVENT_RETURN_VALUE = ev
def check_event(graphic, feature, value):
global EVENT_RETURN_VALUE
assert isinstance(EVENT_RETURN_VALUE, FeatureEvent)
assert EVENT_RETURN_VALUE.type == feature
assert EVENT_RETURN_VALUE.graphic == graphic
assert EVENT_RETURN_VALUE.target == graphic.world_object
if isinstance(EVENT_RETURN_VALUE.info["value"], float):
# floating point error
npt.assert_almost_equal(EVENT_RETURN_VALUE.info["value"], value)
else:
assert EVENT_RETURN_VALUE.info["value"] == value
def test_text_changes_events():
fig = fpl.Figure()
data = "lorem ipsum"
text = fig[0, 0].add_text(data)
text.add_event_handler(
event_handler,
"text",
"font_size",
"face_color",
"outline_color",
"outline_thickness",
)
text.text = "bah"
assert text.text == "bah"
# TODO: seems like there isn't a way in pygfx to get the current text as a str?
check_event(graphic=text, feature="text", value="bah")
text.font_size = 10.0
assert text.font_size == 10.0
assert text.world_object.geometry.font_size == 10
check_event(text, "font_size", 10)
text.face_color = "r"
assert text.face_color == pygfx.Color("r")
assert text.world_object.material.color == pygfx.Color("r")
check_event(text, "face_color", pygfx.Color("r"))
text.outline_color = "b"
assert text.outline_color == pygfx.Color("b")
assert text.world_object.material.outline_color == pygfx.Color("b")
check_event(text, "outline_color", pygfx.Color("b"))
text.outline_thickness = 0.3
npt.assert_almost_equal(text.outline_thickness, 0.3)
npt.assert_almost_equal(text.world_object.material.outline_thickness, 0.3)
check_event(text, "outline_thickness", 0.3)