Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.Composition
Imports Nexamas.UI.General
Imports Nexamas.UI.Layout
Imports Nexamas.UI.TextRendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Controls

    Partial Public NotInheritable Class MASLabel
        Private Sub SetPaddingCore(left As Single, top As Single, right As Single, bottom As Single)
            If NearlyEqual(_paddingLeft, left) AndAlso
               NearlyEqual(_paddingTop, top) AndAlso
               NearlyEqual(_paddingRight, right) AndAlso
               NearlyEqual(_paddingBottom, bottom) Then
                Return
            End If

            _paddingLeft = left
            _paddingTop = top
            _paddingRight = right
            _paddingBottom = bottom

            InvalidateTypographyLayoutCache()
        End Sub

        Private Sub InvalidateTypographyLayoutCache()
            _singleLineLayoutValid = False
            _multiLineLayoutValid = False
            InvalidateVisual()
        End Sub

        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
            End If

            Return value
        End Function

        Private Shared Function NearlyEqual(a As Single, b As Single) As Boolean
            Return Math.Abs(a - b) < 0.001F
        End Function
    End Class

End Namespace
