-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy path_subplot_toolbar.py
More file actions
73 lines (58 loc) · 2.56 KB
/
Copy path_subplot_toolbar.py
File metadata and controls
73 lines (58 loc) · 2.56 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
from imgui_bundle import imgui, icons_fontawesome_6 as fa, imgui_ctx
from ._base import ImguiWindow
from ..layouts._utils import IMGUI_TOOLBAR_HEIGHT
class SubplotToolbar(ImguiWindow):
def __init__(self):
"""
Subplot toolbar shown below all subplots. The subplot is provided via ``_fpl_add_hook()`` when the
toolbar is added to the subplot.
"""
super().__init__()
def draw(self):
# get subplot rect
x, y, width, height = self._subplot.frame.rect
# place the toolbar window below the subplot
pos = (x + 1, y + height - IMGUI_TOOLBAR_HEIGHT)
imgui.set_next_window_size((width - 18, 0))
imgui.set_next_window_pos(pos)
flags = (
imgui.WindowFlags_.no_collapse
| imgui.WindowFlags_.no_title_bar
| imgui.WindowFlags_.no_background
# stay behind floating and fixed overlays so they remain accessible when drawn over the toolbar
| imgui.WindowFlags_.no_bring_to_front_on_focus
)
imgui.begin(f"Toolbar-{hex(id(self._subplot))}", p_open=None, flags=flags)
# push ID to prevent conflict between multiple figs with same UI
imgui.push_id(self._id_counter)
# draw the toolbar and any appended imgui elements
for update_call in self._update_calls:
update_call()
# pop id when all UI has been written to window
imgui.pop_id()
# end window
imgui.end()
def update(self):
with imgui_ctx.begin_horizontal(f"toolbar-{hex(id(self._subplot))}"):
# autoscale button
if imgui.button(fa.ICON_FA_MAXIMIZE):
self._subplot.auto_scale()
if imgui.is_item_hovered(0):
imgui.set_tooltip("autoscale scene")
# center scene
if imgui.button(fa.ICON_FA_ALIGN_CENTER):
self._subplot.center_scene()
if imgui.is_item_hovered(0):
imgui.set_tooltip("center scene")
# checkbox controller
_, self._subplot.controller.enabled = imgui.checkbox(
fa.ICON_FA_COMPUTER_MOUSE, self._subplot.controller.enabled
)
if imgui.is_item_hovered(0):
imgui.set_tooltip("enable/disable controller")
# checkbox maintain_aspect
_, self._subplot.camera.maintain_aspect = imgui.checkbox(
fa.ICON_FA_EXPAND, self._subplot.camera.maintain_aspect
)
if imgui.is_item_hovered(0):
imgui.set_tooltip("maintain aspect")