fix: handle newlines and close-to-edge wrapping better
This commit is contained in:
parent
6c5f082299
commit
824c953102
@ -82,21 +82,31 @@ internal static class ImGuiUtil {
|
||||
// empty string
|
||||
if (text == null) {
|
||||
ImGui.TextUnformatted("");
|
||||
ImGui.TextUnformatted("");
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
var widthLeft = ImGui.GetContentRegionAvail().X;
|
||||
var endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft);
|
||||
if (endPrevLine == null) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
var firstSpace = FindFirstSpace(text, textEnd);
|
||||
var properBreak = firstSpace <= endPrevLine;
|
||||
if (properBreak) {
|
||||
Text(text, endPrevLine);
|
||||
} else {
|
||||
ImGui.TextUnformatted("");
|
||||
}
|
||||
|
||||
widthLeft = ImGui.GetContentRegionAvail().X;
|
||||
while (endPrevLine < textEnd) {
|
||||
if (properBreak) {
|
||||
text = endPrevLine;
|
||||
}
|
||||
|
||||
properBreak = true;
|
||||
|
||||
if (*text == ' ') {
|
||||
++text;
|
||||
} // skip a space at start of line
|
||||
@ -119,6 +129,16 @@ internal static class ImGuiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static unsafe byte* FindFirstSpace(byte* text, byte* textEnd) {
|
||||
for (var i = text; i < textEnd; i++) {
|
||||
if (char.IsWhiteSpace((char) *i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return textEnd;
|
||||
}
|
||||
|
||||
internal static bool IconButton(FontAwesomeIcon icon, string? id = null, string? tooltip = null) {
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user