Skip to content

Missing Bindings: format string arguments for ImGui.text and ImGui.coloredText #412

Description

@Ivan1pl

Version

1.92.0

What part of the binding has gaps?

Dear ImGui

What is missing?

In Dear ImGui, Text and TextColored accept a format string and varargs - format string arguments. According to ImGui.java, these are hardcoded to NULL:

    private static native void nText(String text); /*MANUAL
        auto text = obj_text == NULL ? NULL : (char*)env->GetStringUTFChars(obj_text, JNI_FALSE);
        ImGui::Text(text, NULL);
        if (text != NULL) env->ReleaseStringUTFChars(obj_text, text);
    */

Use case: measuring text size to position it before rendering. calcTextSize expects a pre-formatted string. But text and textColored still expect format strings, even though it is not possible to pass format string arguments. So if the string contains, for example, a % character, it needs to be encoded as %% - and that cannot be directly passed to calcTextSize - it will return incorrect value.

I can think of 2 possible solutions, depending on how difficult it is to bind varargs methods:

  1. allow to pass varargs (Object...) to text and textColored methods
  2. instead of ImGui::Text(text, NULL), invoke ImGui::Text("%s", text)

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing bindingSome of the original library API is missing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions