From 4b1b3a77cbb2acb26e1ee200c9cf63e004da26b8 Mon Sep 17 00:00:00 2001 From: mdgriffith Date: Mon, 18 May 2020 22:57:41 -0400 Subject: [PATCH] resolves #65, resolves #199 - maintain padding as `Float` internally even if the interface is as `Int` --- src/Element.elm | 81 ++++++++++++++++++++++++++++++++---------- src/Internal/Model.elm | 24 +++++++++---- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/Element.elm b/src/Element.elm index c686f92..693dc41 100644 --- a/src/Element.elm +++ b/src/Element.elm @@ -645,14 +645,34 @@ wrappedRow attrs children = newPadding = case padded of Just (Internal.Padding name t r b l) -> - if r >= (x // 2) && b >= (y // 2) then + if r >= (toFloat x / 2) && b >= (toFloat y / 2) then + let + newTop = + t - (toFloat y / 2) + + newRight = + r - (toFloat x / 2) + + newBottom = + b - (toFloat y / 2) + + newLeft = + l - (toFloat x / 2) + in Just <| - paddingEach - { top = t - (y // 2) - , right = r - (x // 2) - , bottom = b - (y // 2) - , left = l - (x // 2) - } + Internal.StyleClass Flag.padding + (Internal.PaddingStyle + (Internal.paddingNameFloat + newTop + newRight + newBottom + newLeft + ) + newTop + newRight + newBottom + newLeft + ) else Nothing @@ -1343,7 +1363,11 @@ moveLeft x = {-| -} padding : Int -> Attribute msg padding x = - Internal.StyleClass Flag.padding (Internal.PaddingStyle ("p-" ++ String.fromInt x) x x x x) + let + f = + toFloat x + in + Internal.StyleClass Flag.padding (Internal.PaddingStyle ("p-" ++ String.fromInt x) f f f f) {-| Set horizontal and vertical padding. @@ -1351,16 +1375,27 @@ padding x = paddingXY : Int -> Int -> Attribute msg paddingXY x y = if x == y then - Internal.StyleClass Flag.padding (Internal.PaddingStyle ("p-" ++ String.fromInt x) x x x x) + let + f = + toFloat x + in + Internal.StyleClass Flag.padding (Internal.PaddingStyle ("p-" ++ String.fromInt x) f f f f) else + let + xFloat = + toFloat x + + yFloat = + toFloat y + in Internal.StyleClass Flag.padding (Internal.PaddingStyle ("p-" ++ String.fromInt x ++ "-" ++ String.fromInt y) - y - x - y - x + yFloat + xFloat + yFloat + xFloat ) @@ -1381,16 +1416,26 @@ And then just do paddingEach : { top : Int, right : Int, bottom : Int, left : Int } -> Attribute msg paddingEach { top, right, bottom, left } = if top == right && top == bottom && top == left then - Internal.StyleClass Flag.padding (Internal.PaddingStyle ("p-" ++ String.fromInt top) top top top top) + let + topFloat = + toFloat top + in + Internal.StyleClass Flag.padding + (Internal.PaddingStyle ("p-" ++ String.fromInt top) + topFloat + topFloat + topFloat + topFloat + ) else Internal.StyleClass Flag.padding (Internal.PaddingStyle (Internal.paddingName top right bottom left) - top - right - bottom - left + (toFloat top) + (toFloat right) + (toFloat bottom) + (toFloat left) ) diff --git a/src/Internal/Model.elm b/src/Internal/Model.elm index 0c03e76..e1c206c 100644 --- a/src/Internal/Model.elm +++ b/src/Internal/Model.elm @@ -79,6 +79,7 @@ module Internal.Model exposing , onlyStyles , optionsToRecord , paddingName + , paddingNameFloat , pageClass , paragraphClass , reduceRecursive @@ -173,7 +174,7 @@ type Style | Colored String String Color | SpacingStyle String Int Int | BorderWidth String Int Int Int Int - | PaddingStyle String Int Int Int Int + | PaddingStyle String Float Float Float Float | GridTemplateStyle { spacing : ( Length, Length ) , columns : List Length @@ -1945,7 +1946,7 @@ type Spacing type Padding - = Padding String Int Int Int Int + = Padding String Float Float Float Float extractSpacingAndPadding : List (Attribute aligned msg) -> ( Maybe Padding, Maybe Spacing ) @@ -2856,13 +2857,13 @@ renderStyleRule options rule maybePseudo = maybePseudo class [ Property "padding" - (String.fromInt top + (String.fromFloat top ++ "px " - ++ String.fromInt right + ++ String.fromFloat right ++ "px " - ++ String.fromInt bottom + ++ String.fromFloat bottom ++ "px " - ++ String.fromInt left + ++ String.fromFloat left ++ "px" ) ] @@ -3192,6 +3193,17 @@ paddingName top right bottom left = ++ String.fromInt left +paddingNameFloat top right bottom left = + "pad-" + ++ floatClass top + ++ "-" + ++ floatClass right + ++ "-" + ++ floatClass bottom + ++ "-" + ++ floatClass left + + getStyleName : Style -> String getStyleName style = case style of