diff --git a/src/gaemstone.Client/Systems/EntityInspector.cs b/src/gaemstone.Client/Systems/EntityInspector.cs index ee933b9..e65bdec 100644 --- a/src/gaemstone.Client/Systems/EntityInspector.cs +++ b/src/gaemstone.Client/Systems/EntityInspector.cs @@ -697,15 +697,15 @@ public class EntityInspector var isDisabled = entity.IsDisabled; var displayName = (docName != null) ? $"\"{docName}\"" : entity.Name ?? entity.Id.ToString(); - if (docIcon is string icon) displayName = $"{icon} {displayName}"; + if (docIcon != null) displayName = $"{docIcon} {displayName}"; - var font = ImGui.GetIO().Fonts.Fonts[(docName != null) ? 2 : 0]; + // Gotta push the font to calculate size properly. + // Can't just pass it to CalcTextSize for some reason. + ImGui.PushFont(ImGui.GetIO().Fonts.Fonts[(docName != null) ? 2 : 0]); var color = docColor ?? Color.FromRGBA(ImGui.GetColorU32(ImGuiCol.Text)); if (isDisabled) color = color.WithAlpha(ImGui.GetStyle().DisabledAlpha); - // Gotta push the font to calculate size properly. - // Can't just pass it to CalcTextSize for some reason. - ImGui.PushFont(font); var size = ImGui.CalcTextSize(displayName); ImGui.PopFont(); + var size = ImGui.CalcTextSize(displayName); if (isHeaderLike) size.X += ImGui.GetStyle().FramePadding.X * 2; if (spanAvailWidth) size.X = Math.Max(size.X, ImGui.GetContentRegionAvail().X); @@ -720,8 +720,9 @@ public class EntityInspector ImGui.PopStyleVar(); } else ImGui.InvisibleButton($"##{entity.Id}", size); - var shift = ImGui.IsKeyDown(ImGuiKey.ModShift); - var canClick = isHeaderLike || shift; + var shift = ImGui.IsKeyDown(ImGuiKey.ModShift); + var hovered = ImGui.IsItemHovered(); + var canClick = isHeaderLike || hovered || shift; if (canClick && ImGui.IsItemClicked()) { if (shift) window = NewEntityInspectorWindow(window.World); // Don't re-select this entity if it's already selected. @@ -732,15 +733,17 @@ public class EntityInspector var drawList = ImGui.GetWindowDrawList(); if (isHeaderLike) pos.X += ImGui.GetStyle().FramePadding.X; - drawList.AddText(font, ImGui.GetFontSize(), pos, color.RGBA, displayName); - if (!isHeaderLike && canClick && ImGui.IsItemHovered()) { + drawList.AddText(ImGui.GetFont(), ImGui.GetFontSize(), pos, color.RGBA, displayName); + if (!isHeaderLike && canClick && hovered) { // Draw a hyperlink-link underscore. - pos.Y -= 1.75f; - drawList.AddLine(pos + new Vector2(0, size.Y), pos + size, color.RGBA); + var p1 = pos + new Vector2( 0, size.Y - 1.75f); + var p2 = pos + new Vector2(size.X, size.Y - 1.75f); + if (docIcon != null) p1.X += ImGui.CalcTextSize($"{docIcon} ").X; + drawList.AddLine(p1, p2, color.RGBA); ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); } - if (ImGui.IsItemHovered()) { + if (hovered) { ImGui.BeginTooltip(); ImGui.PushFont(ImGui.GetIO().Fonts.Fonts[1]); ImGui.TextUnformatted(entity.GetFullPath().ToString()); @@ -754,6 +757,8 @@ public class EntityInspector if (entity.GetDocBrief() is string brief) ImGui.Text(brief); ImGui.EndTooltip(); } + + ImGui.PopFont(); } [Flags]