TextAlignedV(): better handling of cursor position and DC boundary - #9455
TextAlignedV(): better handling of cursor position and DC boundary#9455dkosmari wants to merge 1 commit into
Conversation
…window DC boundary.
fe3d9e4 to
26c1278
Compare
|
cc #7024
[1] If you use
[2] This seems better indeed. I think my intuition then was to not claim more space than necessary in order to hypothetically be able to do a
[3] Correct.
[4] Which boundaries precisely? And why changing them? I think I agree on point 2 and 3 but not on 1, and 4 needs clarifying. |
|
I have pushed 551a0a6. It applies [2] which automatically fixes [3]. Let me know what you think! |
|
[1] I don't have a use case for that, other than "keep the same semantics as Button() just in case." [4] I think the incorrect position was not sizing the parent window correctly after ellipsizing. I'll check what the current code does. In my fork, I went ahead and deleted the SetTooltip() call altogether. I made the function return That said, I'd rather have a unified enum ImGui_TextFlags_ {
ImGui_TextFlags_None = 0, // no text processing, either show full text or clip
ImGui_TextFlags_Wrap = 1 << 0,
ImGui_TextFlags_Ellipsize = 1 << 1, // ellipsize text instead of clipping
ImGui_TextFlags_SingleLine = 1 << 2, // don't wrap, don't show anything beyond the first '\n'
ImGui_TextFlags_BreakAll = 1 << 3, // same meaning as CSS word-break: break-all
ImGui_TextFlags_Underline = 1 << 4, // add bold and italics flags too, if the font backends support it
};
typedef int ImGui_TextFlags;
struct ImTextSpecs {
ImVec2 size = { -1.0f, -1.0f };
ImVec2 align = { 0.0f, 0.5f };
ImGui_TextFlags flags = ImGui_TextFlags_None;
};
struct ImTextLayoutResult {
ImVec2 size; // area actually used to show the text
bool wrapped; // true if any text wrapping happened
bool incomplete; // true if any part of the text was not fully rendered
};
void ImGui::Text(const ImTextSpecs& specs, const char* fmt, ...);
void ImGui::Text(const ImTextSpecs& specs, ImTextLayoutResult& layout_result, const char* fmt, ...); |
The current
TextAlignedV()leaves the position and boundary in an inconsistent state, that limits its usefulness.With this PR:
widthwidth (parameter was calledsize_xbefore), unless:width == 0means the real text width, as obtained byCalcTextSize().x. Before,size_x == 0was giving me no rendered output, as if it was actually clipping the text to a zero-width region.width < 0meansContentRegionAvail().x.Here's a test code (call
test_text_aligned()from any example code), showing the bounding box, cursor position behavior, and how it behaves inside table cells:Here are images showing different outputs: