timjs / elm-collage

Create interactive vector graphics and position them relative to each other
BSD 3-Clause "New" or "Revised" License
58 stars 19 forks source link

at impose #17

Open gitLabor8 opened 6 years ago

gitLabor8 commented 6 years ago

The current "at" function changes the center of the collage to the center of the added collage. This would mean in the following code that the center of the total is the center of label

shape
  |> at topLeft label

However, for things as labels, I would prefer to keep te center of the shape, therefore I would like an addition to your Lay-out functions: the imposeAt, shown below. This would mean that "at" would need a new name for clarity. I haven't thought of anything except "stackAt", which isn't quite descriptive in my opinion.

-- fore is used for further calcs
at : Anchor msg -> Collage msg -> Collage msg -> Collage msg
at anchor collage host =
    stack
        [ fore
            |> shift (anchor back)
        , back
        ]

-- back is used for further calcs
imposeAt : Anchor msg -> Collage msg -> Collage msg -> Collage msg
imposeAt anchor fore back =
    impose
        (fore
            |> shift (anchor back)
        )
        back
timjs commented 6 years ago

This is actually a bug. As the documentation of at states, the operation should not change the origin of the collage!

timjs commented 6 years ago

In the next major version at will have the semantics as described by your imposeAt function.