Feature Request: custom symbols by using render function pointers #8243

Closed
opened 2024-12-18 16:51:22 +00:00 by Sytoplis · 0 comments
Sytoplis commented 2024-12-18 16:51:22 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version 1.89, Branch: docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Linux + GCC

Full config/build information:

No response

Details:

The Problem of Drawing Custom Symbols

So i wanted to use ImGui::Checkbox, ImGui::Bullet, ImGui::TreeNode
But as i am making a game, i wanted to change the looks of the Check, the Bulletpoint-Circle and the Tree-Triangle, which get rendered with RenderCheckMark, RenderBullet and RenderArrow. The problem is that these render functions are hardcoded, so i would have to either change the imgui library locally to use my own style or i would have to reimplement these functions, which isnt too bad for ImGui::Bullet, but the implementation of ImGui::TreeNode looks like a nightmare to reimplement and maintain.

Question / Feature Request:
Is there a better/easier option already to change those symbols? If not, I would like there to be one.

Expanding on the Feature request:
As i see that this is a big library and time is rare, i wanted to give my idea of how to implement it with no real performance loss and backwards compatibility (maybe security risks tho?). If the idea is stupid, you may tell me.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

Trying to explain this using ImGui::Bullet

imgui.h:
ocornut/imgui@32f11402f9/imgui.h (L559)

using BulletRenderFn = void (*) (ImDrawList* draw_list, ImVec2 pos, ImU32 col);
    IMGUI_API void          Bullet(BulletRenderFn renderBullet = RenderBullet);                                                       // draw a small circle + keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses

imgui_widgets.cpp:
ocornut/imgui@32f11402f9/imgui_widgets.cpp (L1382)

void ImGui::Bullet(BulletRenderFn renderBullet)
{
    ImGuiWindow* window = GetCurrentWindow();
    if (window->SkipItems)
        return;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const float line_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), g.FontSize);
    const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize, line_height));
    ItemSize(bb);
    if (!ItemAdd(bb, 0))
    {
        SameLine(0, style.FramePadding.x * 2);
        return;
    }

    // Render and stay on same line
    ImU32 text_col = GetColorU32(ImGuiCol_Text);
    renderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize * 0.5f, line_height * 0.5f), text_col);
    SameLine(0, style.FramePadding.x * 2.0f);
}

Because now I could just create my own function calling into ImGui::Bullet and would have no trouble with any of the logic.

### Version/Branch of Dear ImGui: Version 1.89, Branch: docking ### Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp ### Compiler, OS: Linux + GCC ### Full config/build information: _No response_ ### Details: **The Problem of Drawing Custom Symbols** So i wanted to use ImGui::Checkbox, ImGui::Bullet, ImGui::TreeNode But as i am making a game, i wanted to change the looks of the Check, the Bulletpoint-Circle and the Tree-Triangle, which get rendered with RenderCheckMark, RenderBullet and RenderArrow. The problem is that these render functions are hardcoded, so i would have to either change the imgui library locally to use my own style or i would have to reimplement these functions, which isnt too bad for ImGui::Bullet, but the implementation of ImGui::TreeNode looks like a nightmare to reimplement and maintain. **Question / Feature Request:** Is there a better/easier option already to change those symbols? If not, I would like there to be one. **Expanding on the Feature request:** As i see that this is a big library and time is rare, i wanted to give my idea of how to implement it with no real performance loss and backwards compatibility (maybe security risks tho?). If the idea is stupid, you may tell me. ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code: Trying to explain this using ImGui::Bullet imgui.h: https://github.com/ocornut/imgui/blob/32f11402f96f516be68b56f9eb338f382c544819/imgui.h#L559 ```cpp using BulletRenderFn = void (*) (ImDrawList* draw_list, ImVec2 pos, ImU32 col); IMGUI_API void Bullet(BulletRenderFn renderBullet = RenderBullet); // draw a small circle + keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses ``` imgui_widgets.cpp: https://github.com/ocornut/imgui/blob/32f11402f96f516be68b56f9eb338f382c544819/imgui_widgets.cpp#L1382 ```cpp void ImGui::Bullet(BulletRenderFn renderBullet) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; const float line_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), g.FontSize); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize, line_height)); ItemSize(bb); if (!ItemAdd(bb, 0)) { SameLine(0, style.FramePadding.x * 2); return; } // Render and stay on same line ImU32 text_col = GetColorU32(ImGuiCol_Text); renderBullet(window->DrawList, bb.Min + ImVec2(style.FramePadding.x + g.FontSize * 0.5f, line_height * 0.5f), text_col); SameLine(0, style.FramePadding.x * 2.0f); } ``` Because now I could just create my own function calling into ImGui::Bullet and would have no trouble with any of the logic.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#8243
No description provided.