progress on fixing up gui code

This commit is contained in:
2026-05-12 15:20:34 -04:00
parent fb45b44824
commit c4e1cca66b
6 changed files with 198 additions and 197 deletions
+25 -1
View File
@@ -131,7 +131,31 @@ max-locals = 8
max-args = 5
```
## 11. Structural Dependency Mapping (SDM)
### 11. ImGui Defer Patterns
To prevent `PopID` or `End` leaks in immediate-mode rendering, and to keep code flat (0-1 levels of nesting) for AI agents, use the following patterns:
- **The Context Manager Pattern (Mandatory for complex blocks):**
Wrap all `Begin/End` blocks in `imscope` context managers (from `src/imgui_scopes.py`).
```python
with imscope.window("My Window") as (exp, opened):
if exp:
imgui.text("Hello")
with imscope.tab_item("My Tab") as (exp, _):
if exp:
self._render_tab_content()
```
This adds only 1 space of indentation (project standard) and guarantees the corresponding `End` is called even on early returns or exceptions. **Crucial:** Always check the `exp` (expanded/visible) state before rendering content to avoid ID conflicts and performance overhead.
- **The Flat Dispatch Pattern (Recommended for the main loop):**
To avoid nesting multiple window checks, use a dispatch helper that encapsulates the state check and the scope.
```python
self._render_window_if_open("My Window", self._render_my_panel)
```
This keeps the main GUI loop as a flat sequence of declarative calls.
## 12. Structural Dependency Mapping (SDM)
To assist AI agents in evaluating refactoring impact across dynamic codebases, all major definitions SHOULD include terse SDM tags at the end of their docstrings.