Option Strict On
Option Explicit On

Imports SkiaSharp

Namespace Nexamas.UI.Composition

    ''' <summary>
    ''' Lightweight layout-only spacer used by value templates when empty/filler space is needed.
    ''' It produces no placements, owns no controls, renders nothing, and does not mutate host/core state.
    ''' </summary>
    <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
    Friend NotInheritable Class MASSpacerLayoutNode
        Implements IMASLayoutNode

        Private ReadOnly _preferredWidth As Single
        Private ReadOnly _preferredHeight As Single

        Friend Sub New(Optional preferredWidth As Single = 0.0F,
                       Optional preferredHeight As Single = 0.0F)
            _preferredWidth = SafeNonNegative(preferredWidth)
            _preferredHeight = SafeNonNegative(preferredHeight)
        End Sub

        Public Function Measure(context As MASLayoutMeasureContext) As SKSize Implements IMASLayoutNode.Measure
            Return New SKSize(_preferredWidth, _preferredHeight)
        End Function

        Public Function Arrange(context As MASLayoutArrangeContext) As MASLayoutArrangeResult Implements IMASLayoutNode.Arrange
            Return New MASLayoutArrangeResult()
        End Function

        Private Shared Function SafeNonNegative(value As Single) As Single
            If Single.IsNaN(value) OrElse Single.IsInfinity(value) OrElse value < 0.0F Then Return 0.0F
            Return value
        End Function

    End Class

End Namespace
