Estimating width of SeparatorText #9554

Open
opened 2026-09-24 11:46:13 +00:00 by bostick · 4 comments
bostick commented 2026-09-24 11:46:13 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

xx

Back-ends:

xx

Compiler, OS:

xx

Full config/build information:

No response

Details:

I am using a SeparatorText on a small screen (mobile device) and the text gets truncated. This is fine. However, I would like to supply the shorter text myself instead of just relying on "..."

This is the actual problem I'd like to solve, but it doesn't look like there is a way to supply custom truncation text.

As a second approach, I would like to know whether the SeparatorText was going to be truncated, and supply shorter text for the label myself.

What is a good way to estimate the width of the SeparatorText, horizontal bars and everything? I would like to compare that with available width, and supply different text accordingly.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

### Version/Branch of Dear ImGui: xx ### Back-ends: xx ### Compiler, OS: xx ### Full config/build information: _No response_ ### Details: I am using a SeparatorText on a small screen (mobile device) and the text gets truncated. This is fine. However, I would like to supply the shorter text myself instead of just relying on "..." This is the actual problem I'd like to solve, but it doesn't look like there is a way to supply custom truncation text. As a second approach, I would like to know whether the SeparatorText was going to be truncated, and supply shorter text for the label myself. What is a good way to estimate the width of the SeparatorText, horizontal bars and everything? I would like to compare that with available width, and supply different text accordingly. ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code:
ocornut commented 2026-09-24 12:42:32 +00:00 (Migrated from github.com)

Honestly if I were you I would simply patch the code in TreeNodeBehavior():

        // Label
        if (display_frame)
--          RenderTextClipped(text_pos, frame_bb.Max, label, label_end, &label_size);
++          RenderTextEllipsis(window->DrawList, text_pos, frame_bb.Max, frame_bb.Max.x, label, label_end, &label_size);
        else

I am not ready to apply this to all widgets as for perf/api reason I am not happy with the current ellipsis rendering logic but it should be reworked during 1.93.x.

Honestly if I were you I would simply patch the code in `TreeNodeBehavior()`: ```patch // Label if (display_frame) -- RenderTextClipped(text_pos, frame_bb.Max, label, label_end, &label_size); ++ RenderTextEllipsis(window->DrawList, text_pos, frame_bb.Max, frame_bb.Max.x, label, label_end, &label_size); else ``` I am not ready to apply this to all widgets as for perf/api reason I am not happy with the current ellipsis rendering logic but it should be reworked during 1.93.x.
bostick commented 2026-09-24 13:00:38 +00:00 (Migrated from github.com)

Sorry, I just realized I was pasting the wrong widget name. I meant I am using SeparatorText (not CollapsingHeader).

I'm wondering about estimating the width of SeparatorText, so that I may supply different, shorter text if it is going to be truncated.

(I edited CollapsingHeader -> SeparatorText in my original post)

Sorry, I just realized I was pasting the wrong widget name. I meant I am using SeparatorText (not CollapsingHeader). I'm wondering about estimating the width of SeparatorText, so that I may supply different, shorter text if it is going to be truncated. (I edited CollapsingHeader -> SeparatorText in my original post)
ocornut commented 2026-09-24 13:28:45 +00:00 (Migrated from github.com)

You can infer it from the code SeparatorTextEx():

ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
const ImVec2 padding = g.Style.SeparatorTextPadding;
const float sep1_x1 = window->DC.CursorPos.x;
const float sep2_x2 = window->WorkRect.Max.x;
const float label_avail_w = ImMax(0.0f, sep2_x2 - sep1_x1 - padding.x * 2.0f);
You can infer it from the code `SeparatorTextEx()`: ```cpp ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; const ImVec2 padding = g.Style.SeparatorTextPadding; const float sep1_x1 = window->DC.CursorPos.x; const float sep2_x2 = window->WorkRect.Max.x; const float label_avail_w = ImMax(0.0f, sep2_x2 - sep1_x1 - padding.x * 2.0f); ```
bostick commented 2026-09-24 14:27:15 +00:00 (Migrated from github.com)

Thank you, I will take a look

Thank you, I will take a look
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#9554
No description provided.