Allow copying paths out of the resource logger.

This commit is contained in:
Ottermandias 2024-09-09 14:10:54 +02:00
parent bd59591ed8
commit 0c6d777c75

View file

@ -4,6 +4,7 @@ using OtterGui;
using OtterGui.Classes; using OtterGui.Classes;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Table; using OtterGui.Table;
using OtterGui.Text;
using Penumbra.Enums; using Penumbra.Enums;
using Penumbra.Interop.Structs; using Penumbra.Interop.Structs;
using Penumbra.String; using Penumbra.String;
@ -52,36 +53,41 @@ internal sealed class ResourceWatcherTable : Table<Record>
private static unsafe void DrawByteString(CiByteString path, float length) private static unsafe void DrawByteString(CiByteString path, float length)
{ {
Vector2 vec; if (path.IsEmpty)
ImGuiNative.igCalcTextSize(&vec, path.Path, path.Path + path.Length, 0, 0); return;
if (vec.X <= length)
var size = ImUtf8.CalcTextSize(path.Span);
var clicked = false;
if (size.X <= length)
{ {
ImGuiNative.igTextUnformatted(path.Path, path.Path + path.Length); clicked = ImUtf8.Selectable(path.Span);
} }
else else
{ {
var fileName = path.LastIndexOf((byte)'/'); var fileName = path.LastIndexOf((byte)'/');
CiByteString shortPath; using (ImRaii.Group())
if (fileName != -1)
{ {
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, new Vector2(2 * UiHelpers.Scale)); CiByteString shortPath;
using var font = ImRaii.PushFont(UiBuilder.IconFont); if (fileName != -1)
ImGui.TextUnformatted(FontAwesomeIcon.EllipsisH.ToIconString()); {
ImGui.SameLine(); using var font = ImRaii.PushFont(UiBuilder.IconFont);
shortPath = path.Substring(fileName, path.Length - fileName); clicked = ImUtf8.Selectable(FontAwesomeIcon.EllipsisH.ToIconString());
} ImUtf8.SameLineInner();
else shortPath = path.Substring(fileName, path.Length - fileName);
{ }
shortPath = path; else
{
shortPath = path;
}
clicked |= ImUtf8.Selectable(shortPath.Span, false, ImGuiSelectableFlags.AllowItemOverlap);
} }
ImGuiNative.igTextUnformatted(shortPath.Path, shortPath.Path + shortPath.Length); ImUtf8.HoverTooltip(path.Span);
if (ImGui.IsItemClicked())
ImGuiNative.igSetClipboardText(path.Path);
if (ImGui.IsItemHovered())
ImGuiNative.igSetTooltip(path.Path);
} }
if (clicked)
ImUtf8.SetClipboardText(path.Span);
} }
private sealed class RecordTypeColumn : ColumnFlags<RecordType, Record> private sealed class RecordTypeColumn : ColumnFlags<RecordType, Record>