- Switch SetTooltip to ImRaii based Tooltip

- Shorter date format for db viewer
This commit is contained in:
Infi
2024-11-21 12:31:09 +01:00
parent 3cfe65d2d4
commit d0a55e80ea
9 changed files with 30 additions and 30 deletions
+1 -1
View File
@@ -1644,7 +1644,7 @@ namespace ChatTwo.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Chat Type. /// Looks up a localized string similar to Channel.
/// </summary> /// </summary>
internal static string DbViewer_TableField_Type { internal static string DbViewer_TableField_Type {
get { get {
+1 -1
View File
@@ -1286,7 +1286,7 @@
<value>Date</value> <value>Date</value>
</data> </data>
<data name="DbViewer_TableField_Type" xml:space="preserve"> <data name="DbViewer_TableField_Type" xml:space="preserve">
<value>Chat Type</value> <value>Channel</value>
</data> </data>
<data name="DbViewer_TableField_Sender" xml:space="preserve"> <data name="DbViewer_TableField_Sender" xml:space="preserve">
<value>Sender</value> <value>Sender</value>
+4 -4
View File
@@ -553,7 +553,7 @@ public sealed class ChatLogWindow : Window
ImGui.OpenPopup(ChatChannelPicker); ImGui.OpenPopup(ChatChannelPicker);
if (activeTab.Channel is not null && ImGui.IsItemHovered()) if (activeTab.Channel is not null && ImGui.IsItemHovered())
ImGui.SetTooltip(Language.ChatLog_SwitcherDisabled); ImGuiUtil.Tooltip(Language.ChatLog_SwitcherDisabled);
using (var popup = ImRaii.Popup(ChatChannelPicker)) using (var popup = ImRaii.Popup(ChatChannelPicker))
{ {
@@ -1148,11 +1148,11 @@ public sealed class ChatLogWindow : Window
ImGui.TextUnformatted(timestamp); ImGui.TextUnformatted(timestamp);
// We use an IsItemHovered() check here instead of // We use an IsItemHovered() check here instead of
// just calling SetTooltip() to avoid computing the // just calling Tooltip() to avoid computing the
// tooltip string for all visible items on every // tooltip string for all visible items on every
// frame. // frame.
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(message.Date.ToLocalTime().ToString("F")); ImGuiUtil.Tooltip(message.Date.ToLocalTime().ToString("F"));
} }
else else
{ {
@@ -1704,7 +1704,7 @@ public sealed class ChatLogWindow : Window
ImGui.Dummy(emoteSize); ImGui.Dummy(emoteSize);
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(emotePayload.Code); ImGuiUtil.Tooltip(emotePayload.Code);
return; return;
} }
+2 -2
View File
@@ -47,7 +47,7 @@ public class DbViewer : Window
ChatCodes = TabsUtil.MostlyPlayer; ChatCodes = TabsUtil.MostlyPlayer;
DateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; DateFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
DateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern; DateTimeFormat = "ddd, dd MMM yyy HH:mm:ss";
LastProcessed = (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter, ChatCodes.Count); LastProcessed = (AfterDate, BeforeDate, CurrentPage, OnlyCurrentCharacter, ChatCodes.Count);
DateReset(); DateReset();
@@ -181,7 +181,7 @@ public class DbViewer : Window
ImGui.SetCursorPos(pos); ImGui.SetCursorPos(pos);
ImGui.Dummy(columnWidth); ImGui.Dummy(columnWidth);
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(message.Code.Type.Name()); ImGuiUtil.Tooltip(message.Code.Type.Name());
ImGui.TableNextColumn(); ImGui.TableNextColumn();
Plugin.ChatLogWindow.DrawChunks(message.Sender); Plugin.ChatLogWindow.DrawChunks(message.Sender);
+1 -1
View File
@@ -205,7 +205,7 @@ public partial class InputPreview : Window
ImGui.Dummy(emoteSize); ImGui.Dummy(emoteSize);
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(emotePayload.Code); ImGuiUtil.Tooltip(emotePayload.Code);
CursorPosition += emotePayload.Code.Length; CursorPosition += emotePayload.Code.Length;
return; return;
+3 -3
View File
@@ -107,16 +107,16 @@ internal sealed class Database : ISettingsTab
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ {
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
ImGui.SetTooltip(Language.Options_Database_Metadata_CopyConfigPath); ImGuiUtil.Tooltip(Language.Options_Database_Metadata_CopyConfigPath);
} }
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize))); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize)));
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(StringUtil.BytesToString(DatabaseSize)); ImGuiUtil.Tooltip(StringUtil.BytesToString(DatabaseSize));
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize))); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize)));
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(StringUtil.BytesToString(DatabaseLogSize)); ImGuiUtil.Tooltip(StringUtil.BytesToString(DatabaseLogSize));
ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount)); ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount));
+4 -4
View File
@@ -13,7 +13,7 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
{ {
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name())) using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name()))
{ {
if (combo) if (combo.Success)
{ {
foreach (var language in Enum.GetValues<LanguageOverride>()) foreach (var language in Enum.GetValues<LanguageOverride>())
if (ImGui.Selectable(language.Name())) if (ImGui.Selectable(language.Name()))
@@ -26,7 +26,7 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name())) using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name()))
{ {
if (combo) if (combo.Success)
{ {
foreach (var side in Enum.GetValues<CommandHelpSide>()) foreach (var side in Enum.GetValues<CommandHelpSide>())
if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side)) if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side))
@@ -39,7 +39,7 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name())) using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name()))
{ {
if (combo) if (combo.Success)
{ {
foreach (var mode in Enum.GetValues<KeybindMode>()) foreach (var mode in Enum.GetValues<KeybindMode>())
{ {
@@ -47,7 +47,7 @@ internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab
Mutable.KeybindMode = mode; Mutable.KeybindMode = mode;
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
ImGui.SetTooltip(mode.Tooltip()); ImGuiUtil.Tooltip(mode.Tooltip() ?? "");
} }
} }
} }
+1 -1
View File
@@ -101,7 +101,7 @@ internal sealed class Tabs : ISettingsTab
tab.UnreadMode = mode; tab.UnreadMode = mode;
if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered()) if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered())
ImGui.SetTooltip(tooltip); ImGuiUtil.Tooltip(tooltip);
} }
} }
} }
+13 -13
View File
@@ -191,11 +191,8 @@ internal static class ImGuiUtil
var ret = ImGui.Button(label, size); var ret = ImGui.Button(label, size);
Plugin.FontManager.FontAwesome.Pop(); Plugin.FontManager.FontAwesome.Pop();
if (tooltip != null && ImGui.IsItemHovered()) if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
{ Tooltip(tooltip);
using var startedTooltip = ImRaii.Tooltip();
ImGuiHelpers.SafeTextWrapped(tooltip);
}
return ret; return ret;
} }
@@ -266,6 +263,15 @@ internal static class ImGuiUtil
return r; return r;
} }
internal static void Tooltip(string tooltip)
{
using (ImRaii.Tooltip())
using (ImRaii.TextWrapPos(ImGui.GetFontSize() * 35.0f))
{
ImGui.TextUnformatted(tooltip);
}
}
public static SingleFontChooserDialog? FontChooser(string label, SingleFontSpec font, bool checkbox, ref bool checkboxValue, Predicate<IFontFamilyId>? exclusion = null, string? preview = null) public static SingleFontChooserDialog? FontChooser(string label, SingleFontSpec font, bool checkbox, ref bool checkboxValue, Predicate<IFontFamilyId>? exclusion = null, string? preview = null)
{ {
using var id = ImRaii.PushId(label); using var id = ImRaii.PushId(label);
@@ -325,10 +331,7 @@ internal static class ImGuiUtil
ret = ImGui.Button(label) && ctrlShiftHeld; ret = ImGui.Button(label) && ctrlShiftHeld;
if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
{ Tooltip(tooltip);
using var startedTooltip = ImRaii.Tooltip();
ImGuiHelpers.SafeTextWrapped(tooltip);
}
return ret; return ret;
} }
@@ -345,10 +348,7 @@ internal static class ImGuiUtil
var ret = ImGui.Button(label) && ctrlShiftHeld; var ret = ImGui.Button(label) && ctrlShiftHeld;
if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) if (!string.IsNullOrEmpty(tooltip) && ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
{ Tooltip(tooltip);
using var startedTooltip = ImRaii.Tooltip();
ImGuiHelpers.SafeTextWrapped(tooltip);
}
return ret; return ret;
} }