Skip to content

1.92: Auto convert ImTextureID from ImTextureUserID ? #86

@ocornut

Description

@ocornut

I've published (#8465) a dynamic_fonts branch which is expected to get merged in 1-2 months as 1.92. Started asking feature for feedback and expecting people to slowly adopt it.

One problem I couldn't solve cleanly relate to language bindings and binding generators.
I've circled around this topic for a while and couldn't find an ideal solution.

In the new design:

  • ImTextureID has been renamed to ImTextureUserID. (the type default to u64 but may be compile-time configurable)
  • A new struct called ImTextureID contains a ImTextureUserID among other things.
  • This can be mostly transparent for C++ users, as ImTextureID can be constructed from ImTextureUserID:
    ImTextureID(ImTextureUserID tex_user_id) { [....] _TexUserID = tex_user_id; }
  • The low-level functions all still use ImTextureID:
void ImGui::Image(ImTextureID user_texture_id, ....);
void ImGui::ImageWithBg(ImTextureID user_texture_id, ....);
bool ImGui::ImageButton(ImTextureID user_texture_id, ....);
void ImDrawList::PushTextureID(ImTextureID user_texture_id);
void ImDrawList::AddImage(ImTextureID user_texture_id, ....);
void ImDrawList::AddImageQuad(ImTextureID user_texture_id, ....);
void ImDrawList::AddImageRounded(ImTextureID user_texture_id, ....);
void ImDrawList::_SetTextureID(ImTextureID texture_id);

Those all those the functions using this type.

It is expected that in 99.9% of case the end-user will want to create a ImTextureID from a ImTextureUserID.


My suggestion is that binding generators make this transparent to the user.

So maybe C++ ImGui::Image(ImTextureID user_texture_id, ....); should be generated as C igImage(ImTextureUserID id) and NOT as igImage(ImTextureID id) ?

The implementation of the function (the one-liner C->C++ wrapper) will automatically convert the ImTextureUserID to a ImTextureID thanks to the constructor. So I believe you can solve this by only replacing the type in the function signature.

Do you think dear bindings could implement this?

The branch has #define IMGUI_HAS_TEXTURES if needed to differentiate with/without the feature, so technically if this was implemented it could perfectly be pushed today.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions