Improve text wrapping for preview

This commit is contained in:
Infi
2024-05-20 16:05:32 +02:00
parent 592892e45a
commit aab4977ecf
3 changed files with 21 additions and 10 deletions
+1 -1
View File
@@ -2490,7 +2490,7 @@ namespace ChatTwo.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Only with parameter. /// Looks up a localized string similar to Must contain parameter.
/// </summary> /// </summary>
internal static string Options_PreviewOnlyIf_Name { internal static string Options_PreviewOnlyIf_Name {
get { get {
+1 -1
View File
@@ -1076,7 +1076,7 @@
<value>Tooltip</value> <value>Tooltip</value>
</data> </data>
<data name="Options_PreviewOnlyIf_Name" xml:space="preserve"> <data name="Options_PreviewOnlyIf_Name" xml:space="preserve">
<value>Only with parameter</value> <value>Must contain parameter</value>
</data> </data>
<data name="Options_PreviewOnlyIf_Description" xml:space="preserve"> <data name="Options_PreviewOnlyIf_Description" xml:space="preserve">
<value>Show only if the text contains special parameter</value> <value>Show only if the text contains special parameter</value>
+14 -3
View File
@@ -236,11 +236,21 @@ public class InputPreview : Window
return; return;
} }
foreach (var letter in text.Content) var splits = text.Content.Split(" ");
for (var i = 0; i < splits.Length; i++)
{
// The last character should never be an empty string
// Sorting this out because it leads to double whitespaces
if (i + 1 == splits.Length && splits[i] == "")
break;
var wordSize = ImGui.CalcTextSize(splits[i]);
if (ImGui.GetContentRegionAvail().X < wordSize.X)
ImGui.NewLine();
foreach (var letter in $"{splits[i]} ")
{ {
var letterSize = ImGui.CalcTextSize(letter.ToString()); var letterSize = ImGui.CalcTextSize(letter.ToString());
if (ImGui.GetContentRegionAvail().X < letterSize.X)
ImGui.NewLine();
CursorPosition++; CursorPosition++;
if (ImGui.Selectable($"{letter}##{CursorPosition + unique}", false, ImGuiSelectableFlags.None, letterSize)) if (ImGui.Selectable($"{letter}##{CursorPosition + unique}", false, ImGuiSelectableFlags.None, letterSize))
@@ -250,6 +260,7 @@ public class InputPreview : Window
} }
ImGui.SameLine(); ImGui.SameLine();
} }
}
ImGui.NewLine(); ImGui.NewLine();
} }
} }