- Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtest_imgui.py
More file actions
Latest commit
59 lines (45 loc) · 1.91 KB
/
Copy pathtest_imgui.py
File metadata and controls
59 lines (45 loc) · 1.91 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
"""Dear ImGui UI binding (GL backend). Skips on a build without imgui."""
importthreeppastp
importpytest
pytestmark=pytest.mark.skipif(nottp.HAS_IMGUI, reason="built without imgui")
W, H=320, 240
@pytest.fixture(scope="module")
defgl():
canvas=tp.Canvas("imgui-test", width=W, height=H, headless=True)
renderer=tp.GLRenderer(canvas)
renderer.set_clear_color(0x202830)
ui=tp.ImguiContext(canvas, renderer) # after the renderer
returncanvas, renderer, ui
deftest_imgui_panel_draws(gl):
_, renderer, ui=gl
scene=tp.Scene()
cam=tp.PerspectiveCamera(60, W/H, 0.1, 100)
cam.position.z=5
captured= {}
defdraw():
tp.imgui.set_next_window_pos(8, 8)
tp.imgui.set_next_window_size(180, 130)
tp.imgui.begin("Panel")
tp.imgui.text("hello")
captured["slider"] =tp.imgui.slider_float("v", 0.5, 0.0, 1.0)
captured["check"] =tp.imgui.checkbox("on", True)
captured["button"] =tp.imgui.button("go")
tp.imgui.end()
renderer.render(scene, cam)
ui.render(draw)
img=renderer.read_pixels()
# widget return shapes
assertisinstance(captured["slider"], tuple) andlen(captured["slider"]) ==2
assertcaptured["check"][1] isTrue
assertcaptured["button"] isFalse# not clicked
# the panel region should contain non-background pixels (it drew)
panel=img[8:138, 8:188]
assertint(panel.max()) -int(panel.min()) >40
deftest_want_capture_flags(gl):
_, _, ui=gl
# no UI is hovered in a headless one-shot, but the properties resolve
assertui.want_capture_mousein (True, False)
assertui.want_capture_keyboardin (True, False)
# NOTE: the Vulkan ImGui tests live in test_vulkan.py — a GL and a Vulkan ImGui
# context must not be alive at the same time (two live ImGui contexts crash), and
# this module's GL `gl` fixture is torn down before test_vulkan.py runs.