Repository navigation
refactor: share GUI helpers between image and video examples - #18
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
examples/main_image.cppandexamples/main_video.cppeach had their own identical copy of:INSTANCE_COLORS+N_COLORSbasename_ofapply_theme(53 lines)upload_textureThese now live in one header-only
examples/common.h(stillstatic, 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.hincludes<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, soSDL_MAIN_HANDLEDis still defined before<SDL.h>is first included.screen_to_image,create_tracker, the app-state structs and all other lines are the same as before.Verification
sam3_imageandsam3_videoboth build. No errors and no new warnings. The only warnings are existing ones from ggml and stb.diffof the header body against the original blocks in both files shows no difference.git diffof the .cpp files: the only added line in each is#include "common.h".Caveats
main_video.cppnear the removedupload_textureblock (aroundscreen_to_image/create_tracker). If they merge first, expect small context-only rebase conflicts.🤖 Generated with Claude Code
https://claude.ai/code/session_01M2qLmQ9ag49hT61V6i9qAq