214 lines
6.0 KiB
Python
214 lines
6.0 KiB
Python
from __future__ import annotations
|
|
from imgui_bundle import imgui
|
|
from imgui_bundle import imgui_node_editor
|
|
|
|
def window(name: str, visible: bool = True, flags: int = 0): return _ScopeWindow(name, visible, flags)
|
|
class _ScopeWindow:
|
|
def __init__(self, name: str, visible: bool, flags: int):
|
|
self._name = name
|
|
self._visible = visible
|
|
self._flags = flags
|
|
self._result = None
|
|
def __enter__(self):
|
|
self._result = imgui.begin(self._name, self._visible, self._flags)
|
|
return self._result
|
|
def __exit__(self, *args):
|
|
imgui.end()
|
|
return False
|
|
|
|
def child(id_str: str, size_x: float = 0, size_y: float = 0, flags: int = 0): return _ScopeChild(id_str, size_x, size_y, flags)
|
|
class _ScopeChild:
|
|
def __init__(self, id_str: str, size_x: float | imgui.ImVec2, size_y: float, flags: int):
|
|
self._id = id_str
|
|
# Check if size_x is likely an ImVec2 without using isinstance (which breaks with mocks)
|
|
if hasattr(size_x, 'x') and hasattr(size_x, 'y'):
|
|
self._size = size_x
|
|
else:
|
|
self._size = imgui.ImVec2(float(size_x), float(size_y))
|
|
self._flags = flags
|
|
def __enter__(self):
|
|
res = imgui.begin_child(self._id, self._size, self._flags)
|
|
return res
|
|
def __exit__(self, *args):
|
|
imgui.end_child()
|
|
return False
|
|
|
|
def table(name: str, columns: int, flags: int = 0): return _ScopeTable(name, columns, flags)
|
|
class _ScopeTable:
|
|
def __init__(self, name: str, columns: int, flags: int):
|
|
self._name = name
|
|
self._columns = columns
|
|
self._flags = flags
|
|
self._active = False
|
|
def __enter__(self):
|
|
self._active = imgui.begin_table(self._name, self._columns, self._flags)
|
|
return self._active
|
|
def __exit__(self, *args):
|
|
if self._active:
|
|
imgui.end_table()
|
|
return False
|
|
|
|
def menu_bar(): return _ScopeMenuBar()
|
|
class _ScopeMenuBar:
|
|
def __init__(self):
|
|
self._active = False
|
|
def __enter__(self):
|
|
self._active = imgui.begin_menu_bar()
|
|
return self._active
|
|
def __exit__(self, *args):
|
|
if self._active:
|
|
imgui.end_menu_bar()
|
|
return False
|
|
|
|
def menu(label: str): return _ScopeMenu(label)
|
|
class _ScopeMenu:
|
|
def __init__(self, label: str):
|
|
self._label = label
|
|
self._active = False
|
|
def __enter__(self):
|
|
self._active = imgui.begin_menu(self._label)
|
|
return self._active
|
|
def __exit__(self, *args):
|
|
if self._active:
|
|
imgui.end_menu()
|
|
return False
|
|
|
|
def popup(id_str: str): return _ScopePopup(id_str)
|
|
class _ScopePopup:
|
|
def __init__(self, id_str: str):
|
|
self._id = id_str
|
|
self._active = False
|
|
def __enter__(self):
|
|
self._active = imgui.begin_popup(self._id)
|
|
return self._active
|
|
def __exit__(self, *args):
|
|
if self._active:
|
|
imgui.end_popup()
|
|
return False
|
|
|
|
def popup_modal(name: str, visible: bool = True, flags: int = 0): return _ScopePopupModal(name, visible, flags)
|
|
class _ScopePopupModal:
|
|
def __init__(self, name: str, visible: bool, flags: int):
|
|
self._name = name
|
|
self._visible = visible
|
|
self._flags = flags
|
|
self._active = False
|
|
def __enter__(self):
|
|
self._active, self._visible = imgui.begin_popup_modal(self._name, self._visible, self._flags)
|
|
return self._active, self._visible
|
|
def __exit__(self, *args):
|
|
if self._active:
|
|
imgui.end_popup()
|
|
return False
|
|
|
|
def tooltip(): return _ScopeTooltip()
|
|
class _ScopeTooltip:
|
|
def __enter__(self):
|
|
return imgui.begin_tooltip()
|
|
def __exit__(self, *args):
|
|
imgui.end_tooltip()
|
|
return False
|
|
|
|
def group(): return _ScopeGroup()
|
|
class _ScopeGroup:
|
|
def __enter__(self):
|
|
return imgui.begin_group()
|
|
def __exit__(self, *args):
|
|
imgui.end_group()
|
|
return False
|
|
|
|
def node(name: str): return _ScopeNode(name)
|
|
class _ScopeNode:
|
|
def __init__(self, name: str):
|
|
self._name = name
|
|
def __enter__(self):
|
|
return imgui_node_editor.begin(self._name)
|
|
def __exit__(self, *args):
|
|
imgui_node_editor.end()
|
|
return False
|
|
|
|
def text_wrap(wrap_pos: float = 0.0): return _ScopeTextWrap(wrap_pos)
|
|
class _ScopeTextWrap:
|
|
def __init__(self, wrap_pos: float):
|
|
self._wrap_pos = wrap_pos
|
|
def __enter__(self):
|
|
imgui.push_text_wrap_pos(self._wrap_pos)
|
|
def __exit__(self, *args):
|
|
imgui.pop_text_wrap_pos()
|
|
return False
|
|
|
|
def id(str_id: str): return _ScopeId(str_id)
|
|
class _ScopeId:
|
|
def __init__(self, str_id: str):
|
|
self._id = str_id
|
|
def __enter__(self):
|
|
imgui.push_id(self._id)
|
|
def __exit__(self, *args):
|
|
imgui.pop_id()
|
|
return False
|
|
|
|
def tab_bar(id_str: str, flags: int = 0): return _ScopeTabBar(id_str, flags)
|
|
class _ScopeTabBar:
|
|
def __init__(self, id_str: str, flags: int):
|
|
self._id = id_str
|
|
self._flags = flags
|
|
self._active = False
|
|
def __enter__(self):
|
|
self._active = imgui.begin_tab_bar(self._id, self._flags)
|
|
return self._active
|
|
def __exit__(self, *args):
|
|
if self._active:
|
|
imgui.end_tab_bar()
|
|
return False
|
|
|
|
def tab_item(label: str, flags: int = 0): return _ScopeTabItem(label, flags)
|
|
class _ScopeTabItem:
|
|
def __init__(self, label: str, flags: int):
|
|
self._label = label
|
|
self._flags = flags
|
|
self._expanded = False
|
|
self._open = None
|
|
def __enter__(self):
|
|
self._expanded, self._open = imgui.begin_tab_item(self._label, flags=self._flags)
|
|
return self._expanded, self._open
|
|
def __exit__(self, *args):
|
|
if self._expanded:
|
|
imgui.end_tab_item()
|
|
return False
|
|
|
|
def style_color(col: int, val: Any): return _ScopeStyleColor(col, val)
|
|
class _ScopeStyleColor:
|
|
def __init__(self, col: int, val: Any):
|
|
self._col = col
|
|
self._val = val
|
|
def __enter__(self):
|
|
imgui.push_style_color(self._col, self._val)
|
|
def __exit__(self, *args):
|
|
imgui.pop_style_color()
|
|
return False
|
|
|
|
def style_var(var: int, val: Any): return _ScopeStyleVar(var, val)
|
|
class _ScopeStyleVar:
|
|
def __init__(self, var: int, val: Any):
|
|
self._var = var
|
|
self._val = val
|
|
def __enter__(self):
|
|
imgui.push_style_var(self._var, self._val)
|
|
def __exit__(self, *args):
|
|
imgui.pop_style_var()
|
|
return False
|
|
|
|
def tree_node_ex(label: str, flags: int = 0): return _ScopeTreeNodeEx(label, flags)
|
|
class _ScopeTreeNodeEx:
|
|
def __init__(self, label: str, flags: int):
|
|
self._label = label
|
|
self._flags = flags
|
|
self._opened = False
|
|
def __enter__(self):
|
|
self._opened = imgui.tree_node_ex(self._label, self._flags)
|
|
return self._opened
|
|
def __exit__(self, *args):
|
|
if self._opened:
|
|
imgui.tree_pop()
|
|
return False
|