Skip to content

Add imgui_ctx.tree_node_ex (flags are missing in imgui_ctx.tree_node) #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions bindings/imgui_bundle/imgui_ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
TabBarFlags = int # see enum imgui.TabBarFlags_
TabItemFlags = int # see enum imgui.TabItemFlags_
DragDropFlags = int # see enum imgui.DragDropFlags_
TreeNodeFlags = int # see enum imgui.TreeNodeFlags_


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


class _WithTreeNodeEx:
visible: bool
_enter_callback: _EnterCallback

def __init__(self, label: str, flags: TreeNodeFlags = 0) -> None:
self._enter_callback = lambda: imgui.tree_node_ex(label, flags)

def __enter__(self) -> "_WithTreeNodeEx":
self.visible = self._enter_callback()
return self

def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
if self.visible:
imgui.tree_pop()

def __bool__(self) -> bool:
return self.visible

def __repr__(self) -> str:
return "{}(opened={})".format(
self.__class__.__qualname__, self.visible
)

def __eq__(self, other) -> bool:
if other.__class__ is self.__class__:
return self.visible is other.visible
return self.visible is other


def tree_node_ex(label: str, flags: TreeNodeFlags = 0) -> _WithTreeNodeEx:
return _WithTreeNodeEx(label, flags)


class _WithPushID:
_enter_callback: _EnterCallback

Expand Down