Skip to content

refactor: share GUI helpers between image and video examples - #18

Merged
PABannier merged 1 commit into
mainfrom
cleanup/examples-common-header
Sep 16, 2026
Merged

PABannier merged 1 commit into
mainfrom
cleanup/examples-common-header

Conversation

@PABannier

Copy link
Copy Markdown
Owner

What

examples/main_image.cpp and examples/main_video.cpp each had their own identical copy of:

  • INSTANCE_COLORS + N_COLORS
  • basename_of
  • apply_theme (53 lines)
  • upload_texture

These now live in one header-only examples/common.h (still static, unchanged), and both files include it.

Why

A theme or texture-upload change was having to be made twice, and the two copies could drift apart. Removes 158 duplicated lines.

Details

  • common.h includes <SDL.h>, <SDL_opengl.h>, <imgui.h>, <cstdint> and <string>, in the same order as the .cpp files. It relies on the same SDL/imgui targets (imgui-sdl2, SDL2::SDL2), so nothing changes for the Windows/vcpkg or Linux CI builds.
  • #include "common.h" goes after each file's system includes, so SDL_MAIN_HANDLED is still defined before <SDL.h> is first included.
  • No CMake change: the header sits next to the sources.
  • Nothing else was touched: screen_to_image, create_tracker, the app-state structs and all other lines are the same as before.

Verification

  • Full Release build on macOS (SDL2 installed): sam3_image and sam3_video both build. No errors and no new warnings. The only warnings are existing ones from ggml and stb.
  • Byte-identity: diff of the header body against the original blocks in both files shows no difference.
  • git diff of the .cpp files: the only added line in each is #include "common.h".
  • Every moved helper is used in both files, so there are no unused-static warnings.
$ git diff --shortstat origin/main
 3 files changed, 90 insertions(+), 158 deletions(-)

Caveats

  • Only built locally on macOS. The Windows (MSVC + vcpkg SDL2) and Linux builds are covered by CI.
  • Other cleanup PRs edit lines of main_video.cpp near the removed upload_texture block (around screen_to_image / create_tracker). If they merge first, expect small context-only rebase conflicts.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq

main_image.cpp and main_video.cpp carried byte-identical copies of
INSTANCE_COLORS/N_COLORS, basename_of, apply_theme and upload_texture.
Move them verbatim into a header-only examples/common.h (static
functions) included by both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq
@PABannier
PABannier merged commit dc6a2f7 into main Sep 16, 2026
3 checks passed
@PABannier
PABannier deleted the cleanup/examples-common-header branch September 16, 2026 18:48
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