mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-27 02:49:18 +01:00
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using System.Numerics;
|
|
|
|
using Dalamud.Bindings.ImGui;
|
|
using Dalamud.Interface.ImGuiNotification;
|
|
using Dalamud.Interface.ImGuiNotification.Internal;
|
|
using Dalamud.Interface.Utility;
|
|
|
|
namespace Dalamud.Interface.Internal.Windows.Data;
|
|
|
|
/// <summary>Useful functions for implementing data window widgets.</summary>
|
|
internal static class DataWindowWidgetExtensions
|
|
{
|
|
/// <summary>Draws a text column, and make it copiable by clicking.</summary>
|
|
/// <param name="widget">Owner widget.</param>
|
|
/// <param name="s">String to display.</param>
|
|
/// <param name="alignRight">Whether to align to right.</param>
|
|
/// <param name="framepad">Whether to offset to frame padding.</param>
|
|
public static void TextColumnCopiable(this IDataWindowWidget widget, string s, bool alignRight, bool framepad)
|
|
{
|
|
var offset = ImGui.GetCursorScreenPos() + new Vector2(0, framepad ? ImGui.GetStyle().FramePadding.Y : 0);
|
|
if (framepad)
|
|
ImGui.AlignTextToFramePadding();
|
|
if (alignRight)
|
|
{
|
|
var width = ImGui.CalcTextSize(s).X;
|
|
var xoff = ImGui.GetColumnWidth() - width;
|
|
offset.X += xoff;
|
|
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + xoff);
|
|
ImGui.Text(s);
|
|
}
|
|
else
|
|
{
|
|
ImGui.Text(s);
|
|
}
|
|
|
|
if (ImGui.IsItemHovered())
|
|
{
|
|
ImGui.SetNextWindowPos(offset - ImGui.GetStyle().WindowPadding);
|
|
var vp = ImGui.GetWindowViewport();
|
|
var wrx = (vp.WorkPos.X + vp.WorkSize.X) - offset.X;
|
|
ImGui.SetNextWindowSizeConstraints(Vector2.One, new(wrx, float.MaxValue));
|
|
ImGui.BeginTooltip();
|
|
ImGui.PushTextWrapPos(wrx);
|
|
ImGuiHelpers.SafeTextWrapped(s.Replace("%", "%%"));
|
|
ImGui.PopTextWrapPos();
|
|
ImGui.EndTooltip();
|
|
}
|
|
|
|
if (ImGui.IsItemClicked())
|
|
{
|
|
ImGui.SetClipboardText(s);
|
|
Service<NotificationManager>.Get().AddNotification(
|
|
$"Copied {ImGui.TableGetColumnName()} to clipboard.",
|
|
widget.DisplayName,
|
|
NotificationType.Success);
|
|
}
|
|
}
|
|
}
|