aboutsummaryrefslogtreecommitdiff
path: root/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2015-03-27 12:48:24 +0100
committerJakob Odersky <jodersky@gmail.com>2015-03-27 12:48:24 +0100
commitbd174539d8bb2921bef94cccd994a61e334a3dd7 (patch)
treefa89d47f97779c16d3a54b62518b8c83fc907d3c /vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala
parentf7f157cea1afd3386e46938a110c5a2ed72933fb (diff)
parentc2b0a3de4dca16cb9143acffdcc7a9ad1a730b50 (diff)
downloadmavigator-bd174539d8bb2921bef94cccd994a61e334a3dd7.tar.gz
mavigator-bd174539d8bb2921bef94cccd994a61e334a3dd7.tar.bz2
mavigator-bd174539d8bb2921bef94cccd994a61e334a3dd7.zip
Merge pull request #12 from jodersky/design/cleanupconcise-dialect
Clean up internal structure of dashboard ui
Diffstat (limited to 'vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala')
-rw-r--r--vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala54
1 files changed, 54 insertions, 0 deletions
diff --git a/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala
new file mode 100644
index 0000000..c639cec
--- /dev/null
+++ b/vfd-dashboard/src/main/scala/vfd/dashboard/ui/instruments/SvgInstrument.scala
@@ -0,0 +1,54 @@
+package vfd.dashboard.ui.instruments
+
+
+import org.scalajs.dom
+import org.scalajs.dom.html
+
+import scalatags.JsDom.all._
+
+import vfd.dashboard.Environment
+
+/** An instrument backed by an SVG image. */
+trait SvgInstrument[A] extends Instrument[A] {
+
+ /** SVG object element that contains the rendered instrument */
+ val element: html.Object
+
+ /** Retrieves an element of the underlying SVG document by ID. */
+ protected def part(id: String) = element.contentDocument.getElementById(id).asInstanceOf[html.Element]
+
+ /** Movable parts of the instrument */
+ protected def moveable: Seq[html.Element]
+
+ /** Called when element has been loaded. */
+ protected def load(event: dom.Event): Unit = {
+ for (part <- moveable) {
+ part.style.transition = "transform 250ms ease-out"
+ }
+ ready()
+ }
+
+ element.addEventListener("load", (e: dom.Event) => load(e))
+}
+
+/** Contains helpers for SVG instruments. */
+object SvgInstrument {
+
+ /** Retrieves an SVG object element by its instrument's name. */
+ def svgObject(name: String)(implicit app: Environment): html.Object = {
+ val path = app.asset("images/instruments/" + name + ".svg")
+ `object`(`type` := "image/svg+xml", "data".attr := path, width := 100.pct)(
+ "Error loading instrument " + name).render
+ }
+
+ /** Applies translation styling to an element. */
+ def translate(elem: html.Element, x: Int, y: Int): Unit = {
+ elem.style.transform = "translate(" + x + "px, " + y + "px)";
+ }
+
+ /** Applies rotation styling to an element. */
+ def rotate(elem: html.Element, deg: Int): Unit = {
+ elem.style.transform = "rotateZ(" + deg + "deg)";
+ }
+
+} \ No newline at end of file