1module Internal.Grid exposing (Around, Layout(..), PositionedElement, RelativePosition(..), build, createGrid, getWidth, relative)
3{-| Relative positioning within a grid.
5A relatively positioned grid, means a 3x3 grid with the primary element in the center.
10import Internal.Flag as Flag
11import Internal.Model as Internal
28type alias Around alignment msg =
29 { right : Maybe (PositionedElement alignment msg)
30 , left : Maybe (PositionedElement alignment msg)
31 , primary : ( Maybe String, List (Internal.Attribute alignment msg), List (Internal.Element msg) )
33 -- , primaryWidth : Internal.Length
34 , defaultWidth : Internal.Length
35 , below : Maybe (PositionedElement alignment msg)
36 , above : Maybe (PositionedElement alignment msg)
37 , inFront : Maybe (PositionedElement alignment msg)
41type alias PositionedElement alignment msg =
43 , child : List (Internal.Element msg)
44 , attrs : List (Internal.Attribute alignment msg)
50relative : Maybe String -> List (Internal.Attribute alignment msg) -> Around alignment msg -> Internal.Element msg
51relative node attributes around =
54 Internal.getSpacing attributes ( 7, 7 )
57 Internal.element Internal.noStyleSheet
61 (Internal.Unkeyed positioned.child)
63 ( template, children ) =
64 createGrid ( sX, sY ) around
66 Internal.element Internal.noStyleSheet
69 (template ++ attributes)
75createGrid : ( Int, Int ) -> Around alignment msg -> ( List (Internal.Attribute alignment msg1), List (Element.Element msg) )
76createGrid ( spacingX, spacingY ) nearby =
81 , if Nothing == nearby.above then
86 , if Nothing == nearby.below then
96 , if Nothing == nearby.left then
101 , if Nothing == nearby.right then
109 if nearby.above == Nothing then
122 if Nothing == nearby.left then
169 build (rowCoord pos) (colCoord pos) spacingX spacingY el
171 ( [ Internal.StyleClass Flag.gridTemplate
172 (Internal.GridTemplateStyle
173 { spacing = ( Internal.Px spacingX, Internal.Px spacingY )
175 List.filterMap identity
177 |> Maybe.map (\el -> Maybe.withDefault nearby.defaultWidth (getWidth el.attrs))
179 |> (\( node, attrs, el ) -> getWidth attrs)
180 |> Maybe.withDefault nearby.defaultWidth
183 |> Maybe.map (\el -> Maybe.withDefault nearby.defaultWidth (getWidth el.attrs))
185 , rows = List.map (always Internal.Content) (List.range 1 rowCount)
189 , List.filterMap identity
191 case nearby.primary of
192 ( primaryNode, primaryAttrs, primaryChildren ) ->
193 Internal.element Internal.noStyleSheet
196 (Internal.StyleClass Flag.gridPosition
197 (Internal.GridPosition
199 , col = columns.primary
206 (Internal.Unkeyed primaryChildren)
207 , Maybe.map (place OnLeft) nearby.left
208 , Maybe.map (place OnRight) nearby.right
209 , Maybe.map (place Above) nearby.above
210 , Maybe.map (place Below) nearby.below
211 , Maybe.map (place InFront) nearby.inFront
216build : Int -> Int -> Int -> Int -> { a | attrs : List (Internal.Attribute alignment msg), height : Int, layout : Layout, width : Int, child : List (Internal.Element msg) } -> Internal.Element msg
217build rowCoord colCoord spacingX spacingY positioned =
220 Internal.StyleClass Flag.gridPosition
221 (Internal.GridPosition
224 , width = positioned.width
225 , height = positioned.height
228 :: Internal.StyleClass Flag.spacing (Internal.SpacingStyle spacingX spacingY)
231 case positioned.layout of
233 Internal.element Internal.noStyleSheet
237 (Internal.Unkeyed <| positioned.child)
240 Internal.element Internal.noStyleSheet
244 (Internal.Unkeyed positioned.child)
247 Internal.element Internal.noStyleSheet
251 (Internal.Unkeyed positioned.child)
254getWidth : List (Internal.Attribute align msg) -> Maybe Internal.Length
257 widthPlease attr found =
270 List.foldr widthPlease Nothing attrs
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list