com-lihaoyi / scalatags

ScalaTags is a small XML/HTML construction library for Scala.
https://com-lihaoyi.github.io/scalatags/
MIT License
758 stars 117 forks source link

canvas dimensions #99

Closed Sciss closed 9 years ago

Sciss commented 9 years ago

Hi,

is the behaviour correct?

canvas(cls := "cables", width := 400, height := 400)

gives me <canvas class="cables" style="width: 400px; height: 400px"></canvas>. But I want <canvas class="cables" width=400 height=400></canvas>. All I can see as a workaround is

val elem = canvas(cls := "cables").render
elem.width = 400; elem.height = 400

which kind of defeats the purpose of using ScalaTags here...

lihaoyi commented 9 years ago
canvas(cls := "cables", "width".attr := 400, "height".attr := 400)

Does what you want.

It's an unfortunate consequence of stuffing everything into the same namespace: tags, styles and attributes, so of course we end up with collisions.

If you don't like that, it's relatively straightforward to re-package all the attributes/styles/tags into your own styles attrs tags namespaces (named however you want) using the stuff described in

http://lihaoyi.github.io/scalatags/#CustomBundles

and flesh out the currently-absent members (I'm only aware of height/width right now) so you can use them qualified without resorting to strings.

Sciss commented 9 years ago

Ok, thanks