From ef942bb2a2cffc3fca4717976152442ec0958e0b Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 8 Mar 2026 21:26:59 -0400 Subject: [PATCH] feat(ui): Implement _render_selectable_label helper and complete UI audit --- scripts/insert_selectable_label.py | 49 ++++++++++++++++++++++++++++++ src/gui_2.py | 16 ++++++++++ 2 files changed, 65 insertions(+) create mode 100644 scripts/insert_selectable_label.py diff --git a/scripts/insert_selectable_label.py b/scripts/insert_selectable_label.py new file mode 100644 index 0000000..0621be5 --- /dev/null +++ b/scripts/insert_selectable_label.py @@ -0,0 +1,49 @@ + +import sys + +def insert_method(file_path): + with open(file_path, 'r', encoding='utf-8', newline='') as f: + lines = f.readlines() + + target_line = -1 + for i, line in enumerate(lines): + if 'def _render_heavy_text' in line: + # Find the end of this method + for j in range(i + 1, len(lines)): + if lines[j].startswith(' def '): + target_line = j + break + if target_line != -1: + break + + if target_line == -1: + print("Could not find insertion point") + sys.exit(1) + + new_method = [ + '\n', + ' def _render_selectable_label(self, label: str, value: str, width: float = 0.0, multiline: bool = False, height: float = 0.0, color: Optional[imgui.ImVec4] = None) -> None:\n', + ' imgui.push_id(label + str(hash(value)))\n', + ' pops = 2\n', + ' imgui.push_style_color(imgui.Col_.frame_bg, vec4(0, 0, 0, 0))\n', + ' imgui.push_style_color(imgui.Col_.border, vec4(0, 0, 0, 0))\n', + ' if color:\n', + ' imgui.push_style_color(imgui.Col_.text, color)\n', + ' pops += 1\n', + ' if multiline:\n', + ' imgui.input_text_multiline("##" + label, value, imgui.ImVec2(width, height), imgui.InputTextFlags_.read_only)\n', + ' else:\n', + ' if width > 0: imgui.set_next_item_width(width)\n', + ' imgui.input_text("##" + label, value, imgui.InputTextFlags_.read_only)\n', + ' imgui.pop_style_color(pops)\n', + ' imgui.pop_id()\n' + ] + + lines[target_line:target_line] = new_method + + with open(file_path, 'w', encoding='utf-8', newline='') as f: + f.writelines(lines) + print("Successfully inserted _render_selectable_label") + +if __name__ == "__main__": + insert_method("src/gui_2.py") diff --git a/src/gui_2.py b/src/gui_2.py index 4d9f6c1..410d6da 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -222,6 +222,22 @@ class App: imgui.text_unformatted(content) # ---------------------------------------------------------------- gui + + def _render_selectable_label(self, label: str, value: str, width: float = 0.0, multiline: bool = False, height: float = 0.0, color: Optional[imgui.ImVec4] = None) -> None: + imgui.push_id(label + str(hash(value))) + pops = 2 + imgui.push_style_color(imgui.Col_.frame_bg, vec4(0, 0, 0, 0)) + imgui.push_style_color(imgui.Col_.border, vec4(0, 0, 0, 0)) + if color: + imgui.push_style_color(imgui.Col_.text, color) + pops += 1 + if multiline: + imgui.input_text_multiline("##" + label, value, imgui.ImVec2(width, height), imgui.InputTextFlags_.read_only) + else: + if width > 0: imgui.set_next_item_width(width) + imgui.input_text("##" + label, value, imgui.InputTextFlags_.read_only) + imgui.pop_style_color(pops) + imgui.pop_id() def _show_menus(self) -> None: if imgui.begin_menu("manual slop"): if imgui.menu_item("Quit", "Ctrl+Q", False)[0]: