1) I don't really get for what purpose Element
and Form
are different classes. Probably, it causes the following problem.
2)
My main
function maps all signals to a assemble
function, which assembles view on each update
assemble: Float -> Float -> Element
assemble screen_w screen_h =
[
background screen_w screen_h,
header screen_w screen_h,
info screen_w screen_h
]
|> collage (round screen_w) (round screen_h)
main: Signal Element
main =
assemble
<~ (toFloat <~ Window.width)
~ (toFloat <~ Window.height)
This architecture requires header
to return Form
3)
header
uses one form for text and two other forms to decorate it.
I need to position them one above other and merge into one form.
stripe: Float -> Element
stripe w =
rect w 10
|> filled black
|> show
header: Float -> Float -> Form
header screen_w screen_h =
[
stripe screen_w,
fromString "My awesome header"
|> height 64
|> text
|> show
,
stripe screen_w
]
|> flow down
|> toForm
|> move (0, screen_h/2 - header_size/2 - header_shift)
4) The code above displays
<internal structure>
<internal structure>
<internal structure>
in place of header and stripes.
It seems that show
is unable to inverse toForm
because the following
main =
show 42
|> toForm
|> show
also displays
<internal structure>
Can I align three forms one above other, using Elm?
Difference between
Form
s andElement
sForm
s are free-form graphics that can be displayed in a collage.Element
s are rectangular things with a known width and height.Purpose of
Graphics.Element.show
The
show
function is more of a debugging tool than a function for turningForm
s intoElement
s. All data you define yourself can probably be displayed byshow
, but some internal data from libraries are not displayable, which is why you get the<internal structure>
output. To turnForm
s intoElement
s, use theGraphics.Collage.collage
function.Alignment of
Form
sAlignment and distribution of forms in an
Element
-like way is not well supported in the core libraries. You can try the 3rd party library align-distribute for it, which should make it easier. Another more powerful 3rd party library is diagrams, but I'm not sure it's as easy to use nor whether you need more power than the other lib I linked to.