#nullable enable using T3.Editor.Gui.Interaction.Snapping; using T3.Editor.UiModel; using T3.Editor.UiModel.Selection; namespace T3.Editor.Gui.MagGraph.Model; /// /// A wrapper to to provide damping other potential other features of the mag graph UI. /// internal sealed class MagGraphSection : ISelectableCanvasObject, IValueSnapAttractor { public required Section Section; public ISelectableCanvasObject Selectable => Section; public Vector2 PosOnCanvas { get => Section.PosOnCanvas; set => Section.PosOnCanvas = value; } public Vector2 Size { get => Section.Size; set => Section.Size = value; } public Vector2 DampedPosOnCanvas; public Vector2 DampedSize; public Guid Id { get; init; } public int LastUpdateCycle; public bool IsRemoved; /// /// Nesting depth in the section tree (0 = top level). Drives draw order so outer sections /// paint before the inner ones they contain — otherwise an outer section's translucent /// background washes over the nested sections' text. /// public int NestingDepth; void IValueSnapAttractor.CheckForSnap(ref SnapResult snapResult) { if (snapResult.Orientation == SnapResult.Orientations.Horizontal) { snapResult.TryToImproveWithAnchorValue(DampedPosOnCanvas.X); snapResult.TryToImproveWithAnchorValue(DampedPosOnCanvas.X + DampedSize.X); } else if (snapResult.Orientation == SnapResult.Orientations.Vertical) { snapResult.TryToImproveWithAnchorValue(DampedPosOnCanvas.Y); snapResult.TryToImproveWithAnchorValue(DampedPosOnCanvas.Y + DampedSize.Y); } } }