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

Expose a way of adding styles to nodes #22

Open nikita-volkov opened 6 years ago

nikita-volkov commented 6 years ago

While trying to add a shadow to a collage I've discovered that the current API simply doesn't provide any gates for me to do that.

timjs commented 6 years ago

Hi @nikita-volkov!

It is true that there is no way to add styling to a collage. The only way to add style at the moment is when you convert a shape, path or text into a collage. This is intentional, it greatly simplifies the API.

What is it you'd like to do exactly? It seems to me that even Haskell Diagrams doesn't have a way to add shadow to a diagram automatically. Is copying a collage, shifting it and apply some grey colour what you'd like to do? If you've any suggestions how to change the API to accommodate such things, please share!

nikita-volkov commented 6 years ago

How about simply exposing the attributes of the node? E.g.,

styledWithAttributes : List (Attribute msg) -> (FillStyle, LineStyle) -> Shape -> Collage msg

This way not only will the user get a way of specifying the styles but also the event handlers.

timjs commented 6 years ago

I understand that you like to have more control in styling your shapes and the like. However, I like the frontend to be backend agnostic. Now there is only an SVG backend, but @Kwarrtz already proposed a Canvas backend (#5). Therefore I think it is not a good idea to expose SVG attributes in the main Collage module.

We could do two things:

  1. Add such a styledWithAttributes to Collage.Render (which is now an SVG only module)
  2. Add a general way to add shadows to shapes, expose that and internally translate it to SVG attributes (like all other filling and styling things are done)

I prefer option 2.

Do you like to access more more attributes than only shadows?

nikita-volkov commented 6 years ago

Do you like to access more more attributes than only shadows?

In my current project I only need to be able to apply CSS styles and to set handlers. However my gut feeling says that if I start using this library heavily I will soon discover more requirements.


Putting the mentioned aside, I believe that a good strategy for an evolving project is to expose gates to the low-level features until a full-featured higher-level API is implemented. Your project is clearly an evolving one since you've already mentioned such major plans for it.

An ideal solution would be to provide your own API for all the features of the lower-level abstractions that your users might require. However that solution will require a decent amount of design and implementation work. More so, it will require to implement all the backends first so that you'd be designing the public API with them in mind.

It already sound like it's not gonna happen in a day or a week, so it's best to just approach that gradually. Until it's fully done it's best to expose the lower-level gates so that your users are not limited in features.

IOW my vote is for both options with the second one being implemented iteratively.