using System.Numerics; using Dalamud.Bindings.ImGui; using HellionChat.Util; namespace HellionChat.Ui.StyleEngine.Widgets; // Visual state of a list row. Deliberately carries no Tab: v1.11.0 swaps the // sidebar from tab rows to channel rows and should only have to change the // caller, not the chrome. internal readonly record struct RowVisualState { public RowVisualState() { } public bool IsActive { get; init; } public float HoverAmount { get; init; } public uint SurfaceHoverAbgr { get; init; } public uint SurfaceActiveAbgr { get; init; } public uint AccentAbgr { get; init; } public uint BorderAbgr { get; init; } } internal readonly record struct RowStyle { public RowStyle() { } public float AccentBarWidth { get; init; } = 2f; public bool DrawSeparator { get; init; } = true; } internal static class Row { // Painted before icon and label, and strictly with draw-list calls only: // TabContextMenu binds to the last submitted item, so an interactive widget // between the row button and the popup call would steal its right-click. internal static void Draw( Vector2 origin, Vector2 size, RowVisualState state, RowStyle? styleOverride = null ) { if (size.X <= 0f || size.Y <= 0f) return; var style = styleOverride ?? new RowStyle(); var dl = ImGui.GetWindowDrawList(); var max = origin + size; // Idle rows draw no fill at all. GlobalStyleScope zeroes ChildBg below // full window opacity so WindowBg alone carries the coverage, and the // default is 0.85 -- an opaque fill per row would make the sidebar a // solid block inside a translucent window. if (state.IsActive) dl.AddRectFilled(origin, max, state.SurfaceActiveAbgr); if (state.HoverAmount > 0f) dl.AddRectFilled( origin, max, ColourUtil.ApplyAlpha(state.SurfaceHoverAbgr, state.HoverAmount) ); if (state.IsActive && style.AccentBarWidth > 0f) { var barWidth = style.AccentBarWidth * Metrics.Scale; dl.AddRectFilled(origin, new Vector2(origin.X + barWidth, max.Y), state.AccentAbgr); } if (style.DrawSeparator) dl.AddLine( new Vector2(origin.X, max.Y - 1f), new Vector2(max.X, max.Y - 1f), state.BorderAbgr, Metrics.Scale ); } }