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>
+19 -8
View File
@@ -236,19 +236,30 @@ 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++)
{ {
var letterSize = ImGui.CalcTextSize(letter.ToString()); // The last character should never be an empty string
if (ImGui.GetContentRegionAvail().X < letterSize.X) // 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(); ImGui.NewLine();
CursorPosition++; foreach (var letter in $"{splits[i]} ")
if (ImGui.Selectable($"{letter}##{CursorPosition + unique}", false, ImGuiSelectableFlags.None, letterSize))
{ {
SelectedCursorPos = CursorPosition; var letterSize = ImGui.CalcTextSize(letter.ToString());
LogWindow.KeepFocusedThroughPreview = true;
CursorPosition++;
if (ImGui.Selectable($"{letter}##{CursorPosition + unique}", false, ImGuiSelectableFlags.None, letterSize))
{
SelectedCursorPos = CursorPosition;
LogWindow.KeepFocusedThroughPreview = true;
}
ImGui.SameLine();
} }
ImGui.SameLine();
} }
ImGui.NewLine(); ImGui.NewLine();
} }