pthom / hello_imgui

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

An api which can help us get assets folder path #56

Closed XMNXofficial closed 1 year ago

XMNXofficial commented 1 year ago

An New API

Source(In hello_imgui_assets.cpp)

    std::string GetAssetFolderPath() {
        std::string a = FileUtils::GetCurrentDirectory();
#if defined(__ANDROID__)
        a+="/";
#else
        a += "\\";
#endif
        a += gAssetsSubfolderFolderName;
        return a;
    }

How to use

    ImGui::Text("%s", HelloImGui::GetAssetFolderPath().c_str());

Photo

Photo

pthom commented 1 year ago

I know, the assets API is a bit complex. However, there are up to four possible different locations for the assets folder, as shown by computePossibleAssetsFolders(), and they are all tested in succession when trying to look for an asset:

  1. gOverrideAssetsFolder (valid only if it was filled by manually calling SetAssetsFolder())
  2. Current executable folder + "/" + gAssetsSubfolderFolderName (gAssetsSubfolderFolderName = "assets" by default)
  3. Current working directory + "/" + gAssetsSubfolderFolderName
  4. "/" + gAssetsSubfolderFolderName (emscripten only)

In practice, it will mainly vary between 3 and 4.

As such, providing GetAssetFolderPath() is not that easy.

XMNXofficial commented 1 year ago

Thank you, your solution is very helpful!