| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888 |
- """
- imgui_ctx provides context managers to simplify the use of paired ImGui functions such as:
- 1. `imgui.begin()` / `imgui.end()`
- can be replaced by: `with imgui_ctx.begin() as window:` + `if window:`
- 2. `imgui.begin_child()` / `imgui.end_child()`
- can be replaced by: `with imgui_ctx.begin_child() as child:` + `if child:`
- 3. `imgui.begin_menu_bar()` / `imgui.end_menu_bar()`
- can be replaced by: `with imgui_ctx.begin_menu_bar() as menu_bar:` + `if menu_bar:`
- ...
- Note:
- ImGui’s "begin"/"end" functions typically return a boolean indicating whether the context is open and usable.
- You may (and often should) use this boolean to guard the inner code, as in the example below:
- ```python
- with imgui_ctx.begin_main_menu_bar() as menu_bar:
- if menu_bar:
- with imgui_ctx.begin_menu("Edit1") as menu_edit:
- if menu_edit:
- imgui.menu_item_simple("Undo")
- imgui.menu_item_simple("Redo")
- ```
- This pattern avoids rendering UI elements inside a closed or collapsed container, as per ImGui’s recommended usage.
- """
- from imgui_bundle import imgui, ImVec2, ImVec4
- from types import TracebackType
- from typing import Optional, Callable, Any, Type
- ChildFlags = int # see enum imgui.ChildFlags_
- WindowFlags = int # see enum imgui.WindowFlags_
- TableFlags = int # see enum imgui.TableFlags_
- 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]]
- OptBaseException = Optional[BaseException]
- OptTraceback = Optional[TracebackType]
- _EnterCallback = Callable[[], Any]
- IM_VEC2_ZERO = ImVec2(0.0, 0.0)
- class _BeginEndChild:
- visible: bool
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- _enter_callback: _EnterCallback
- def __init__(self,
- str_id: str,
- size: ImVec2 = IM_VEC2_ZERO,
- child_flags: ChildFlags = 0,
- window_flags: WindowFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin_child(str_id, size, child_flags, window_flags)
- def __enter__(self) -> "_BeginEndChild":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.end_child()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(visible={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_child(str_id: str,
- size: ImVec2 = IM_VEC2_ZERO,
- child_flags: ChildFlags = 0,
- window_flags: WindowFlags = 0) -> _BeginEndChild:
- return _BeginEndChild(str_id, size, child_flags, window_flags)
- class _BeginEnd:
- expanded: bool
- opened: bool
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- _enter_callback: _EnterCallback
- def __init__(self, name: str, p_open: Optional[bool] = None, flags: WindowFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin(name, p_open, flags)
- def __enter__(self) -> "_BeginEnd":
- self.expanded, self.opened = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.end()
- def __bool__(self) -> bool:
- if self.opened is None:
- return self.expanded
- else:
- return self.expanded and self.opened
- def __getitem__(self, item: int) -> bool:
- return (self.expanded, self.opened)[item]
- def __iter__(self) -> Any:
- return iter((self.expanded, self.opened))
- def __repr__(self) -> str:
- return "{}(expanded={}, opened={})".format(
- self.__class__.__name__, self.expanded, self.opened
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return (self.expanded, self.opened) == (other.expanded, other.opened)
- return (self.expanded, self.opened) == other
- def begin(name: str, p_open: Optional[bool] = None, flags: WindowFlags = 0) -> _BeginEnd:
- r = _BeginEnd(name, p_open, flags)
- return r
- class _BeginEndListBox:
- opened: bool
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- _enter_callback: _EnterCallback
- def __init__(self, label: str, size: ImVec2 = IM_VEC2_ZERO) -> None:
- self._enter_callback = lambda: imgui.begin_list_box(label, size)
- def __enter__(self) -> "_BeginEndListBox":
- self.opened = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.opened: # only call end_list_box if begin_list_box was successful
- imgui.end_list_box()
- def __bool__(self) -> bool:
- return self.opened
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.opened
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.opened is other.opened
- return self.opened is other
- def begin_list_box(label: str, size: ImVec2 = IM_VEC2_ZERO) -> _BeginEndListBox:
- return _BeginEndListBox(label, size)
- class _BeginEndTooltip:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self) -> None:
- self._enter_callback = lambda: imgui.begin_tooltip()
- def __enter__(self) -> "_BeginEndTooltip":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible:
- imgui.end_tooltip()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_tooltip() -> _BeginEndTooltip:
- return _BeginEndTooltip()
- class _BeginEndMenuMainBar:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self) -> None:
- self._enter_callback = lambda: imgui.begin_main_menu_bar()
- def __enter__(self) -> "_BeginEndMenuMainBar":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, exc_type: OptExceptType, exc_val: OptBaseException, exc_tb: OptTraceback) -> None:
- if self.visible:
- imgui.end_main_menu_bar()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_main_menu_bar() -> _BeginEndMenuMainBar:
- return _BeginEndMenuMainBar()
- class _BeginEndMenuBar:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self) -> None:
- self._enter_callback = lambda: imgui.begin_menu_bar()
- def __enter__(self) -> "_BeginEndMenuBar":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible: # only call end_list_box if begin_tooltip was successful
- imgui.end_menu_bar()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_menu_bar() -> _BeginEndMenuBar:
- return _BeginEndMenuBar()
- class _BeginEndMenu:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self, label: str, enabled: bool = True) -> None:
- self._enter_callback = lambda: imgui.begin_menu(label, enabled)
- def __enter__(self) -> "_BeginEndMenu":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible: # only call end_list_box if begin_tooltip was successful
- imgui.end_menu()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_menu(label: str, enabled: bool = True) -> _BeginEndMenu:
- return _BeginEndMenu(label, enabled)
- class _BeginEndPopup:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self, str_id: str, flags: WindowFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin_popup(str_id, flags)
- def __enter__(self) -> "_BeginEndPopup":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible: # only call end_list_box if begin_tooltip was successful
- imgui.end_popup()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_popup(str_id: str, flags: WindowFlags = 0) -> _BeginEndPopup:
- return _BeginEndPopup(str_id, flags)
- class _BeginEndPopupModal:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self, name: str, flags: WindowFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin_popup_modal(name, None, flags)
- def __enter__(self) -> "_BeginEndPopupModal":
- self.visible, _ = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible: # only call end_list_box if begin_tooltip was successful
- imgui.end_popup()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_popup_modal(name: str, flags: WindowFlags = 0) -> _BeginEndPopupModal:
- return _BeginEndPopupModal(name, flags)
- class _BeginEndTable:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self,
- str_id: str,
- column: int,
- flags: TableFlags = 0,
- outer_size: ImVec2 = IM_VEC2_ZERO,
- inner_width: float = 0.0) -> None:
- self._enter_callback = lambda: imgui.begin_table(str_id, column, flags, outer_size, inner_width)
- def __enter__(self) -> "_BeginEndTable":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible: # only call end_list_box if begin_tooltip was successful
- imgui.end_table()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_table(str_id: str,
- column: int,
- flags: TableFlags = 0,
- outer_size: ImVec2 = IM_VEC2_ZERO,
- inner_width: float = 0.0) -> _BeginEndTable:
- return _BeginEndTable(str_id, column, flags, outer_size, inner_width)
- class _BeginEndTabBar:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self, str_id: str, flags: TabBarFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin_tab_bar(str_id, flags)
- def __enter__(self) -> "_BeginEndTabBar":
- self.visible = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible: # only call end_list_box if begin_tooltip was successful
- imgui.end_tab_bar()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_tab_bar(str_id: str, flags: TabBarFlags = 0) -> _BeginEndTabBar:
- return _BeginEndTabBar(str_id, flags)
- class _BeginEndTabItem:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self, label: str, flags: TabItemFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin_tab_item(label, None, flags)
- def __enter__(self) -> "_BeginEndTabItem":
- self.visible, _ = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.visible:
- imgui.end_tab_item()
- def __bool__(self) -> bool:
- return self.visible
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- def begin_tab_item(label: str, flags: TabItemFlags = 0) -> _BeginEndTabItem:
- return _BeginEndTabItem(label, flags)
- class _BeginEndDragDropSource:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- is_dragging: bool
- _enter_callback: _EnterCallback
- def __init__(self, flags: DragDropFlags = 0) -> None:
- self._enter_callback = lambda: imgui.begin_drag_drop_source(flags)
- def __enter__(self) -> "_BeginEndDragDropSource":
- self.is_dragging = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.is_dragging:
- imgui.end_drag_drop_source()
- def __bool__(self) -> bool:
- return self.is_dragging
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.is_dragging
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.is_dragging is other.is_dragging
- return self.is_dragging is other
- def begin_drag_drop_source(flags: DragDropFlags = 0) -> _BeginEndDragDropSource:
- return _BeginEndDragDropSource(flags)
- class _BeginEndDragDropTarget:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- is_receiving: bool
- _enter_callback: _EnterCallback
- def __init__(self) -> None:
- self._enter_callback = lambda: imgui.begin_drag_drop_target()
- def __enter__(self) -> "_BeginEndDragDropTarget":
- self.is_receiving = self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- if self.is_receiving:
- imgui.end_drag_drop_target()
- def __bool__(self) -> bool:
- return self.is_receiving
- def __repr__(self) -> str:
- return "{}(opened={})".format(
- self.__class__.__name__, self.is_receiving
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.is_receiving is other.is_receiving
- return self.is_receiving is other
- def begin_drag_drop_target() -> _BeginEndDragDropTarget:
- return _BeginEndDragDropTarget()
- class _BeginEndGroup:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- _enter_callback: _EnterCallback
- def __init__(self) -> None:
- self._enter_callback = lambda: imgui.begin_group()
- def __enter__(self) -> "_BeginEndGroup":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.end_group()
- def __repr__(self) -> str:
- return "{}".format(self.__class__.__name__)
- def begin_group() -> _BeginEndGroup:
- return _BeginEndGroup()
- class _BeginHorizontal:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- _enter_callback: _EnterCallback
- def __init__(self, str_id: str, size: ImVec2 | None = None, align: float = -1.0) -> None:
- if size is None:
- size = ImVec2(0, 0)
- self._enter_callback = lambda: imgui.begin_horizontal(str_id, size, align)
- def __enter__(self) -> "_BeginHorizontal":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.end_horizontal()
- def __repr__(self) -> str:
- return "{}".format(self.__class__.__name__)
- def begin_horizontal(str_id: str, size: ImVec2 | None = None, align: float = -1.0) -> _BeginHorizontal:
- return _BeginHorizontal(str_id, size, align)
- class _BeginVertical:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- _enter_callback: _EnterCallback
- def __init__(self, str_id: str, size: ImVec2 | None = None, align: float = -1.0) -> None:
- if size is None:
- size = ImVec2(0, 0)
- self._enter_callback = lambda: imgui.begin_vertical(str_id, size, align)
- def __enter__(self) -> "_BeginVertical":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.end_vertical()
- def __repr__(self) -> str:
- return "{}".format(self.__class__.__name__)
- def begin_vertical(str_id: str, size: ImVec2 | None = None, align: float = -1.0) -> _BeginVertical:
- return _BeginVertical(str_id, size, align)
- class _WithTreeNode:
- # _enter_callback will be called in __enter__. Captures all __init__ arguments.
- visible: bool
- _enter_callback: _EnterCallback
- def __init__(self, label: str) -> None:
- self._enter_callback = lambda: imgui.tree_node(label)
- def __enter__(self) -> "_WithTreeNode":
- 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__.__name__, self.visible
- )
- def __eq__(self, other: object) -> bool:
- if other.__class__ is self.__class__:
- return self.visible is other.visible
- return self.visible is other
- 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: object) -> 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
- def __init__(self, str_id: str) -> None:
- self._enter_callback = lambda: imgui.push_id(str_id)
- def __enter__(self) -> "_WithPushID":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_id()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_id(str_id: str) -> _WithPushID:
- return _WithPushID(str_id)
- def push_obj_id(obj: Any) -> _WithPushID:
- return _WithPushID(str(id(obj)))
- class _WithPushFont:
- _enter_callback: _EnterCallback
- def __init__(self, font: imgui.ImFont, font_size_base_unscaled: float = 0.0) -> None:
- self._enter_callback = lambda: imgui.push_font(font, font_size_base_unscaled)
- def __enter__(self) -> "_WithPushFont":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_font()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_font(font: imgui.ImFont) -> _WithPushFont:
- return _WithPushFont(font)
- class _WithPushStyleColor:
- _enter_callback: _EnterCallback
- def __init__(self, idx: int, col: ImVec4) -> None:
- self._enter_callback = lambda: imgui.push_style_color(idx, col)
- def __enter__(self) -> "_WithPushStyleColor":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_style_color()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_style_color(idx: int, col: ImVec4) -> _WithPushStyleColor:
- return _WithPushStyleColor(idx, col)
- class _WithPushStyleVar:
- _enter_callback: _EnterCallback
- def __init__(self, idx: int, val: Any) -> None:
- self._enter_callback = lambda: imgui.push_style_var(idx, val)
- def __enter__(self) -> "_WithPushStyleVar":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_style_var()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_style_var(idx: int, val: Any) -> _WithPushStyleVar:
- return _WithPushStyleVar(idx, val)
- class _WithPushItemWidth:
- _enter_callback: _EnterCallback
- def __init__(self, item_width: float) -> None:
- self._enter_callback = lambda: imgui.push_item_width(item_width)
- def __enter__(self) -> "_WithPushItemWidth":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_item_width()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_item_width(item_width: float) -> _WithPushItemWidth:
- return _WithPushItemWidth(item_width)
- class _WithPushTextWrapPos:
- _enter_callback: _EnterCallback
- def __init__(self, wrap_pos_x: float = 0.0) -> None:
- self._enter_callback = lambda: imgui.push_text_wrap_pos(wrap_pos_x)
- def __enter__(self) -> "_WithPushTextWrapPos":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_text_wrap_pos()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_text_wrap_pos(wrap_pos_x: float = 0.0) -> _WithPushTextWrapPos:
- return _WithPushTextWrapPos(wrap_pos_x)
- class _WithPushButtonRepeat:
- _enter_callback: _EnterCallback
- def __init__(self, repeat: bool = True) -> None:
- self._enter_callback = lambda: imgui.push_item_flag(imgui.ItemFlags_.button_repeat.value, True)
- def __enter__(self) -> "_WithPushButtonRepeat":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_item_flag()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_button_repeat(repeat: bool = True) -> _WithPushButtonRepeat:
- return _WithPushButtonRepeat(repeat)
- class _WithPushClipRect:
- _enter_callback: _EnterCallback
- def __init__(self, clip_rect_min: ImVec2, clip_rect_max: ImVec2, intersect_with_current_clip_rect: bool) -> None:
- self._enter_callback = lambda: imgui.push_clip_rect(
- clip_rect_min, clip_rect_max, intersect_with_current_clip_rect)
- def __enter__(self) -> "_WithPushClipRect":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_clip_rect()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_clip_rect(
- clip_rect_min: ImVec2,
- clip_rect_max: ImVec2,
- intersect_with_current_clip_rect: bool
- ) -> _WithPushClipRect:
- return _WithPushClipRect(clip_rect_min, clip_rect_max, intersect_with_current_clip_rect)
- class _WithPushTabStop:
- _enter_callback: _EnterCallback
- def __init__(self, tab_stop: bool) -> None:
- self._enter_callback = lambda: imgui.push_tab_stop(tab_stop)
- def __enter__(self) -> "_WithPushTabStop":
- self._enter_callback()
- return self
- def __exit__(self, _exc_type: OptExceptType, _exc_val: OptBaseException, _exc_tb: OptTraceback) -> None:
- imgui.pop_tab_stop()
- def __repr__(self) -> str:
- return self.__class__.__name__
- def push_tab_stop(tab_stop: bool) -> _WithPushTabStop:
- return _WithPushTabStop(tab_stop)
|