git.iko.soy/typeable/elm-ui
on master help sign in
symmetrical model for wrapped row padding
commit6f0a7186782c395a642fe2db4ecbe78c4491b71f authorMatthew Griffith <mdg.griffith@gmail.com> dateTue 18 Sep 2018, 15:46 (8 years ago) parent2cc2080
2 files changed+50−26
src/Element.elm+37−18 src/Internal/Model.elm+13−8
src/Element.elm+37−18
@@ -647,21 +647,14 @@ wrappedRow attrs children =
647647 newPadding =
648648 case padded of
649649 Just (Internal.Padding name t r b l) ->
650− if r >= x && b >= y then
650+ if r >= (x // 2) && b >= (y // 2) then
651651 Just <|
652− Internal.StyleClass
653− Flag.padding
654− (Internal.PaddingStyle
655− (Internal.paddingName t
656− (r - x)
657− (b - y)
658− l
659− )
660− t
661− (r - x)
662− (b - y)
663− l
664− )
652+ paddingEach
653+ { top = t - (y // 2)
654+ , right = r - (x // 2)
655+ , bottom = b - (y // 2)
656+ , left = l - (x // 2)
657+ }
665658
666659 else
667660 Nothing
@@ -690,6 +683,13 @@ wrappedRow attrs children =
690683
691684 Nothing ->
692685 -- Not enough space in padding to compensate for spacing
686+ let
687+ halfX =
688+ negate (toFloat x / 2)
689+
690+ halfY =
691+ negate (toFloat y / 2)
692+ in
693693 Internal.element
694694 Internal.asEl
695695 Internal.div
@@ -706,9 +706,28 @@ wrappedRow attrs children =
706706 ++ classes.wrapped
707707 )
708708 :: Internal.Attr
709− (Html.Attributes.style "margin-bottom" (String.fromInt (negate y) ++ "px"))
710− :: width fill
711− :: height fill
709+ (Html.Attributes.style "margin"
710+ (String.fromFloat halfY
711+ ++ "px"
712+ ++ " "
713+ ++ String.fromFloat halfX
714+ ++ "px"
715+ )
716+ )
717+ :: Internal.Attr
718+ (Html.Attributes.style "width"
719+ ("calc(100% + "
720+ ++ String.fromInt x
721+ ++ "px)"
722+ )
723+ )
724+ :: Internal.Attr
725+ (Html.Attributes.style "height"
726+ ("calc(100% + "
727+ ++ String.fromInt y
728+ ++ "px)"
729+ )
730+ )
712731 :: Internal.StyleClass Flag.spacing (Internal.SpacingStyle spaceName x y)
713732 :: []
714733 )
@@ -730,7 +749,7 @@ type alias Todo =
730749 el
731750 [ Element.explain Debug.todo
732751 ]
733− (text "Help! I'm being debugged!")
752+ (text "Help, I'm being debugged!")
734753
735754-}
736755explain : Todo -> Attribute msg
src/Internal/Model.elm+13−8
@@ -2563,6 +2563,12 @@ toStyleSheetString options stylesheet =
25632563 class =
25642564 "." ++ cls
25652565
2566+ halfX =
2567+ String.fromFloat (toFloat x / 2) ++ "px"
2568+
2569+ halfY =
2570+ String.fromFloat (toFloat y / 2) ++ "px"
2571+
25662572 xPx =
25672573 String.fromInt x ++ "px"
25682574
@@ -2597,21 +2603,20 @@ toStyleSheetString options stylesheet =
25972603 "." ++ Internal.Style.classes.single
25982604 in
25992605 String.concat
2600− [ renderStyle maybePseudo (class ++ row ++ " > " ++ any) [ Property "margin-right" xPx ]
2606+ [ renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ " + " ++ any) [ Property "margin-left" xPx ]
26012607
26022608 -- margins don't apply to last element of normal, unwrapped rows
2603− , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":last-child") [ Property "margin" "0" ]
2604−
2609+ -- , renderStyle maybePseudo (class ++ row ++ " > " ++ any ++ ":first-child") [ Property "margin" "0" ]
26052610 -- For wrapped rows, margins always apply because we handle "canceling out" the other margins manually in the element.
26062611 , renderStyle maybePseudo
26072612 (class ++ wrappedRow ++ " > " ++ any)
2608− [ Property "margin" ("0 " ++ xPx ++ " " ++ yPx ++ " 0")
2609− ]
2610− , renderStyle maybePseudo
2611− (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2612− [ Property "margin-right" "0"
2613+ [ Property "margin" (halfY ++ " " ++ halfX)
26132614 ]
26142615
2616+ -- , renderStyle maybePseudo
2617+ -- (class ++ wrappedRow ++ " > " ++ any ++ ":last-child")
2618+ -- [ Property "margin-right" "0"
2619+ -- ]
26152620 -- columns
26162621 , renderStyle maybePseudo (class ++ column ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]
26172622 , renderStyle maybePseudo (class ++ page ++ " > " ++ any ++ " + " ++ any) [ Property "margin-top" yPx ]