This is a reminiscence from the Elm Render library's ShapeStyle. Note that styled in Elm Collage is more similar to styledShape than to filledAndBordered. I tried to simplify things and merge these to ways to add fill and outline to a shape. It is a hard one to design properly. ShapeStyle was a record, I made Style a tuple. Take a look at these two simple fills and outlines:
As for parentheses, it doesn't matter that much. You'll need them anyway in option 1 and option 2. I think option 3 is way to verbose and contains unnecessary information.
Now comes the deliberation: How does it look like when using predefined styles?
--
-- Option 1: separate arguments => create styling functions
--
outlinedAndFilled thickness fillColor =
styled (uniform fillColor) (solid thickness (uniform black))
thinOutlinedAndFilled =
outlinedAndFilled thin
thickOutlinedAndFilled =
outlinedAndFilled thick
triangle 30
|> thickOutlinedAndFilled green
--
-- Option 2: tuple => create new `Style` tuple
--
thinOutlinedAndFilled fillColor =
( uniform fillColor, solid thin (uniform black) )
thickOutlinedAndFilled fillColor =
let
(fill, line) =
thinOutlinedAndFilled fillColor
in
( fill, {line | thickness = thick} )
triangle 30
|> styled (thickOutlinedAndFilled green)
--
-- Option 3: record => create new `Style` record
--
thinOutlinedAndFilled fillColor =
{ fill = uniform fillColor, line = solid thin (uniform black) }
thickOutlinedAndFilled fillColor =
let
old =
thinOutlinedAndFilled fillColor
-- Elm doesn't accept an expression before the bar in records...
old_line =
old.line
in
{ old | line = {old_line | thickness = thick} }
triangle 30
|> styled (thickOutlinedAndFilled green)
I'm not sure any more if using a type alias for a shape style consisting of a tuple or a record is a good idea. Probably good old currying and abstraction are indeed our biggest friends here!
This is a reminiscence from the Elm Render library's
ShapeStyle
. Note thatstyled
in Elm Collage is more similar tostyledShape
than tofilledAndBordered
. I tried to simplify things and merge these to ways to add fill and outline to a shape. It is a hard one to design properly.ShapeStyle
was a record, I madeStyle
a tuple. Take a look at these two simple fills and outlines:and the three possible options to use
styled
with undefined styles:As for parentheses, it doesn't matter that much. You'll need them anyway in option 1 and option 2. I think option 3 is way to verbose and contains unnecessary information.
Now comes the deliberation: How does it look like when using predefined styles?
I'm not sure any more if using a type alias for a shape style consisting of a tuple or a record is a good idea. Probably good old currying and abstraction are indeed our biggest friends here!
This was brought up in #4.