Skip to content

Add type-safe GUI widget accessor generator#5608

Open
JohnVonDrashek wants to merge 2 commits intosupertuxkart:masterfrom
JohnVonDrashek:feature/gui-widget-accessors
Open

Add type-safe GUI widget accessor generator#5608
JohnVonDrashek wants to merge 2 commits intosupertuxkart:masterfrom
JohnVonDrashek:feature/gui-widget-accessors

Conversation

@JohnVonDrashek
Copy link

Summary

  • Adds a Python code generator (tools/generate_gui_headers.py) that parses .stkgui XML files and generates type-safe C++ header files with widget accessor methods
  • Integrates generator into CMake build system
  • Converts existing screens and dialogs to use generated accessors, eliminating runtime string lookups
  • Improves type safety and code readability in GUI code

Changes

Generator Infrastructure:

  • tools/generate_gui_headers.py - Parses STKGUI files, generates typed accessors
  • CMakeLists.txt - Build integration
  • src/generated/gui/ - Generated header files

Screen Conversions:

  • Converted ~30 screens and dialogs to use type-safe widget accessors
  • Replaced getWidget<Type>("name") calls with generated widgets()->name() methods

Benefits

  • Type safety: Compile-time errors for widget type mismatches
  • No string lookups: Direct accessor methods instead of runtime lookups
  • IDE support: Autocomplete for widget names
  • Refactoring: Rename detection when widget IDs change

Test plan

  • Verify game compiles with generated headers
  • Verify screens function correctly with new accessors
  • Run generator on all STKGUI files

Split from #5606 per reviewer feedback to keep PRs focused

🤖 Generated with Claude Code

George Felter and others added 2 commits December 31, 2025 13:10
Generate C++ headers from .stkgui XML files providing compile-time
type safety for widget access. Replaces stringly-typed getWidget<T>("id")
calls with typed struct members, catching typos and type mismatches
at compile time instead of runtime.

Features:
- Python generator script (tools/generate_gui_headers.py)
- CMake integration (runs at configure time)
- 82 generated headers for all .stkgui files
- C++ keyword escaping (e.g., "new" -> "new_")

Demo conversion of OptionsScreenAudio to use generated widgets.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Bulk conversion of 26 screen/dialog pairs to use generated widget
accessor structs, replacing stringly-typed getWidget<T>("id") calls.

Converted:
- Options: 7 screens (device, display, general, language, ui, video, user)
- Online: 5 screens (online, lan, create_server, networking_lobby, user_search)
- Dialogs: 9 dialogs (addons_loading, confirm_resolution, custom_camera,
  custom_video, enter_address, ghost_replay_info, high_score_info,
  kart_color_slider, select_challenge)
- Main: 5 screens (main_menu, addons, arenas, race_setup, soccer_setup)

Generator improvements:
- Use AbstractTopLevelContainer* for bind() (works with Screen and ModalDialog)
- Handle identifiers starting with digits (prefix with underscore)
- Handle spaces in identifiers (replace with underscores)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant