Skip to content

ImGui::RenderTextEllipsis cuts a few pixels of letters: p, q, g #6236

@SC5Shout

Description

@SC5Shout

Version: 1.89
Branch: docking

I want to render a text using ImGui::RenderTextEllipsis. It cuts a few pixels on the Y-axis, though.

I've looked into void ImGui::TableHeader(const char* label) to get more information on how to use it.
I've adopted the code to my needs:

std::string name = "Text that is too long";
static constexpr float thumbnailSize = 100.0f;
static constexpr float edgeOffset = 4.0f;

ImGuiWindow* window = ImGui::GetCurrentWindow();
ImGuiContext& g = *GImGui;

const char* label = name.c_str();
const char* label_end = ImGui::FindRenderedTextEnd(label);
ImVec2 label_size = ImGui::CalcTextSize(label, label_end, true);
ImVec2 label_pos = window->DC.CursorPos;

float ellipsis_max = label_pos.x + (thumbnailSize - edgeOffset * 2.0f);
ImGui::RenderTextEllipsis(
	window->DrawList,
	label_pos,
	ImVec2(ellipsis_max, label_pos.y + label_size.y + g.Style.FramePadding.y),
	ellipsis_max,
	ellipsis_max,
	label,
	label_end,
	&label_size
);

Result:

image

Something's wrong with p and g (I believe there's the same problem with q).

Adding 1.0f to ImVec2(ellipsis_max, label_pos.y + label_size.y + g.Style.FramePadding.y) helps, but I guess it shouldn't work like this.

ImGui::RenderTextEllipsis(
	window->DrawList,
	label_pos,
	ImVec2(ellipsis_max, label_pos.y + label_size.y + g.Style.FramePadding.y + 1.0f), // !!!
	ellipsis_max,
	ellipsis_max,
	label,
	label_end,
	&label_size
);

Expected result:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions