pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
678 stars 103 forks source link

macOS bundle support #71

Closed wkjarosz closed 12 months ago

wkjarosz commented 1 year ago

Thanks for the great project.

After playing around a bit it, am I correct that Hello ImGui doesn't properly support macOS bundles (as it does for iOS), or am I doing something wrong?

After calling hello_imgui_add_app, I was able to make my app a macOS bundle using set_target_properties with MACOSX_BUNDLE, MACOSX_BUNDLE_INFO_PLIST, etc.

However, it doesn't seem that Hello ImGui's font loading capabilities work reliably in this case. How the app is launched (and the resulting working directory) determines whether the asset directory and therefore the fonts are found. Just double-clicking the app bundle in Finder results in ugly default fonts.

For a macOS app, I would expect either: 1) the fonts and other assets to be copied into the Resources subdirectory of the app bundle and the working directory to be set so that e.g. AssetFileFullPath works properly; or 2) assets like fonts to be directly embedded as binary data into the executable so Hello ImGui could use something like AddFontFromMemoryTTF to circumvent the filesystem entirely.

Do you have a recommended workflow to create native-like macOS apps?

Thanks again!

wkjarosz commented 1 year ago

Doing a bit more digging, I think I have a suggested fix:

If we want to build as bundles on macOS, then I believe the following changes would be needed:

It seems to me that bundling should be the default behavior for a gui "app" on macOS. Is this change something you would consider?

pthom commented 1 year ago

Hello Wojciech,

(I just merged your PR about custom background, many thanks! I also added a nice demo for it.)

Concerning MacOS bundles, it is true that I did not take time to handle them. I'm using a Mac, but my main usage is with the command line.

However, adding them would be a nice addition, though!

Would you like to give it a try? I'll help!

Notes: bundling should be the default behavior for a gui "app" on macOS, you are right, but it would be desirable to be able to bypass it. For example by adding an option HELLOIMGUI_MAC_NO_BUNDLE in the main CMakeLists.

Doing a bit more digging, I think I have a suggested fix:

If we want to build as bundles on macOS, then I believe the following changes would be needed:

have hello_imgui_bundle_assets_from_folder bundle assets under the Resources folder, just like on iOS set the MACOSX_BUNDLE to true on the app target, and set various other HELLO_IMGUIBUNDLE properties, again just like on iOS do not call glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE); in runner_glfw_opengl3.cpp:40

Quite a nice digging :-)