|
25 | 25 | TabBarFlags = int # see enum imgui.TabBarFlags_
|
26 | 26 | TabItemFlags = int # see enum imgui.TabItemFlags_
|
27 | 27 | DragDropFlags = int # see enum imgui.DragDropFlags_
|
| 28 | +TreeNodeFlags = int # see enum imgui.TreeNodeFlags_ |
28 | 29 |
|
29 | 30 |
|
30 | 31 | OptExceptType = Optional[Type[BaseException]]
|
@@ -641,6 +642,39 @@ def tree_node(label: str) -> _WithTreeNode:
|
641 | 642 | return _WithTreeNode(label)
|
642 | 643 |
|
643 | 644 |
|
| 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 | + |
644 | 678 | class _WithPushID:
|
645 | 679 | _enter_callback: _EnterCallback
|
646 | 680 |
|
|
0 commit comments