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
|
// empty string
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
ImGui.TextUnformatted("");
|
ImGui.TextUnformatted("");
|
||||||
ImGui.TextUnformatted("");
|
continue;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var widthLeft = ImGui.GetContentRegionAvail().X;
|
var widthLeft = ImGui.GetContentRegionAvail().X;
|
||||||
var endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft);
|
var endPrevLine = ImGuiNative.ImFont_CalcWordWrapPositionA(ImGui.GetFont().NativePtr, ImGuiHelpers.GlobalScale, text, textEnd, widthLeft);
|
||||||
if (endPrevLine == null) {
|
if (endPrevLine == null) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var firstSpace = FindFirstSpace(text, textEnd);
|
||||||
|
var properBreak = firstSpace <= endPrevLine;
|
||||||
|
if (properBreak) {
|
||||||
Text(text, endPrevLine);
|
Text(text, endPrevLine);
|
||||||
|
} else {
|
||||||
|
ImGui.TextUnformatted("");
|
||||||
|
}
|
||||||
|
|
||||||
widthLeft = ImGui.GetContentRegionAvail().X;
|
widthLeft = ImGui.GetContentRegionAvail().X;
|
||||||
while (endPrevLine < textEnd) {
|
while (endPrevLine < textEnd) {
|
||||||
|
if (properBreak) {
|
||||||
text = endPrevLine;
|
text = endPrevLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
properBreak = true;
|
||||||
|
|
||||||
if (*text == ' ') {
|
if (*text == ' ') {
|
||||||
++text;
|
++text;
|
||||||
} // skip a space at start of line
|
} // 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) {
|
internal static bool IconButton(FontAwesomeIcon icon, string? id = null, string? tooltip = null) {
|
||||||
ImGui.PushFont(UiBuilder.IconFont);
|
ImGui.PushFont(UiBuilder.IconFont);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user