Skip to content

Commit

Permalink
Add ImageAndSizeFromAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Feb 14, 2024
1 parent bd541cc commit 0576001
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/hello_imgui/doc_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ ImTextureID ImTextureIdFromAsset(const char *assetPath);
// will return the size of an image loaded from the assets.
ImVec2 ImageSizeFromAsset(const char *assetPath);


// `HelloImGui::ImageAndSize HelloImGui::ImageAndSizeFromAsset(assetPath)`:
// will return the texture ID and the size of an image loaded from the assets.
struct ImageAndSize
{
ImTextureID textureId = ImTextureID(0);
ImVec2 size = ImVec2(0.f, 0.f);
};
ImageAndSize ImageAndSizeFromAsset(const char *assetPath);


// `ImVec2 HelloImGui::ImageProportionalSize(askedSize, imageSize)`:
// will return the displayed size of an image.
// - if askedSize.x or askedSize.y is 0, then the corresponding dimension
Expand Down
11 changes: 11 additions & 0 deletions src/hello_imgui/image_from_asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ ImTextureID ImTextureIdFromAsset(const char *assetPath);
// will return the size of an image loaded from the assets.
ImVec2 ImageSizeFromAsset(const char *assetPath);


// `HelloImGui::ImageAndSize HelloImGui::ImageAndSizeFromAsset(assetPath)`:
// will return the texture ID and the size of an image loaded from the assets.
struct ImageAndSize
{
ImTextureID textureId = ImTextureID(0);
ImVec2 size = ImVec2(0.f, 0.f);
};
ImageAndSize ImageAndSizeFromAsset(const char *assetPath);


// `ImVec2 HelloImGui::ImageProportionalSize(askedSize, imageSize)`:
// will return the displayed size of an image.
// - if askedSize.x or askedSize.y is 0, then the corresponding dimension
Expand Down
8 changes: 8 additions & 0 deletions src/hello_imgui/internal/image_from_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ namespace HelloImGui
return ImVec2((float)cachedImage->Width, (float)cachedImage->Height);
}

ImageAndSize ImageAndSizeFromAsset(const char *assetPath)
{
auto cachedImage = _GetCachedImage(assetPath);
if (cachedImage == nullptr)
return {};
return {cachedImage->TextureID(), ImVec2((float)cachedImage->Width, (float)cachedImage->Height)};
}

namespace internal
{
void Free_ImageFromAssetMap()
Expand Down

0 comments on commit 0576001

Please sign in to comment.