Skip to content

Commit 22d37ef

Browse files
committed
Merge branch 'imgui_ctx_with_tree_node_ex'
2 parents 50bdd86 + e950f2a commit 22d37ef

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

bindings/imgui_bundle/imgui_ctx.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
TabBarFlags = int # see enum imgui.TabBarFlags_
2626
TabItemFlags = int # see enum imgui.TabItemFlags_
2727
DragDropFlags = int # see enum imgui.DragDropFlags_
28+
TreeNodeFlags = int # see enum imgui.TreeNodeFlags_
2829

2930

3031
OptExceptType = Optional[Type[BaseException]]
@@ -641,6 +642,39 @@ def tree_node(label: str) -> _WithTreeNode:
641642
return _WithTreeNode(label)
642643

643644

645+
class _WithTreeNodeEx:
646+
visible: bool
647+
_enter_callback: _EnterCallback
648+
649+
def __init__(self, label: str, flags: TreeNodeFlags = 0) -> None:
650+
self._enter_callback = lambda: imgui.tree_node_ex(label, flags)
651+
652+
def __enter__(self) -> "_WithTreeNodeEx":
653+
self.visible = self._enter_callback()
654+
return self
655+
656+
def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
657+
if self.visible:
658+
imgui.tree_pop()
659+
660+
def __bool__(self) -> bool:
661+
return self.visible
662+
663+
def __repr__(self) -> str:
664+
return "{}(opened={})".format(
665+
self.__class__.__qualname__, self.visible
666+
)
667+
668+
def __eq__(self, other) -> bool:
669+
if other.__class__ is self.__class__:
670+
return self.visible is other.visible
671+
return self.visible is other
672+
673+
674+
def tree_node_ex(label: str, flags: TreeNodeFlags = 0) -> _WithTreeNodeEx:
675+
return _WithTreeNodeEx(label, flags)
676+
677+
644678
class _WithPushID:
645679
_enter_callback: _EnterCallback
646680

0 commit comments

Comments
 (0)