Skip to content
Permalink
Browse files

Preliminary integration of material icon support

Updates to GoogleFont to use latest version of fonts
Updated examples project to use youi-plugin
  • Loading branch information...
darkfrog26 committed Jul 3, 2019
1 parent 4472542 commit 52732fe0f60a48c74ba66ab6a8cec1579e124383
@@ -231,16 +231,12 @@ lazy val app = crossProject(JSPlatform, JVMPlatform).in(file("app"))
lazy val appJS = app.js
lazy val appJVM = app.jvm.dependsOn(server)

lazy val example = crossProject(JSPlatform, JVMPlatform).in(file("example"))
lazy val example = crossApplication.in(file("example"))
.settings(
name := "youi-example"
name := "youi-example",
youiVersion := version.value
)
.jsSettings(
crossTarget in fastOptJS := baseDirectory.value / ".." / "jvm" / "src" / "main" / "resources" / "app",
crossTarget in fullOptJS := baseDirectory.value / ".." / "jvm" / "src" / "main" / "resources" / "app",
crossTarget in packageJSDependencies := baseDirectory.value / ".." / "jvm" / "src" / "main" / "resources" / "app",
crossTarget in packageMinifiedJSDependencies := baseDirectory.value / ".." / "jvm" / "src" / "main" / "resources" / "app",
skip in packageJSDependencies := false,
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
)
.jvmSettings(
@@ -250,10 +246,9 @@ lazy val example = crossProject(JSPlatform, JVMPlatform).in(file("example"))
"org.scala-lang.modules" %% "scala-xml" % scalaXMLVersion
)
)
.dependsOn(app)

lazy val exampleJS = example.js
lazy val exampleJVM = example.jvm.dependsOn(serverUndertow)
lazy val exampleJS = example.js.dependsOn(appJS)
lazy val exampleJVM = example.jvm.dependsOn(serverUndertow, appJVM)

lazy val utilities = project.in(file("utilities"))
.settings(
@@ -46,6 +46,7 @@ object ClientExampleApplication extends ExampleApplication with ClientApplicatio
val hit: HitTestExample = new HitTestExample
val image: ImageExample = new ImageExample
val imageChange: ImageChangeExample = new ImageChangeExample
val materialIcons: MaterialIconsExample = new MaterialIconsExample
val measured: MeasuredExample = new MeasuredExample
val parallax: ParallaxExample = new ParallaxExample
val scale9: Scale9Example = new Scale9Example
@@ -0,0 +1,31 @@
package io.youi.example.ui

import io.youi.Color
import io.youi.example.screen.UIExampleScreen
import io.youi.font.{Material, MaterialIconView}
import io.youi.net._
import io.youi.style.FontWeight

import scala.concurrent.Future
import scribe.Execution.global

class MaterialIconsExample extends UIExampleScreen {
override def title: String = "Material Icons Example"

override def path: Path = path"/examples/material-icons.html"

override def createUI(): Future[Unit] = for {
material <- Material.load()
} yield {
val iconView = new MaterialIconView {
value := Material.Icons.Action.Alarm
font := material
font.weight := FontWeight("bold")
font.size := 128.0
color := Color.Blue
position.x := container.size.center
position.y := container.size.middle
}
container.children += iconView
}
}
@@ -21,9 +21,6 @@ object ServerExampleApplication extends ExampleApplication with ServerApplicatio
classOf[SimpleCommunication] -> "simple"
)

override protected def applicationBasePath = s"app/youi-example"
override protected def applicationJSBasePath = s"/app/example"

case class Greeting(message: String, name: String)

override protected def init(): Future[Unit] = super.init().map { _ =>
@@ -9,4 +9,6 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15")

addSbtPlugin("io.youi" % "youi-plugin" % "1.0.3")
@@ -0,0 +1,27 @@
package io.youi.font

import io.youi.component.extras.HTMLComponent
import io.youi.dom._
import io.youi.theme.{MaterialIconViewTheme, Theme}
import org.scalajs.dom._

class MaterialIconView(protected val element: html.Element,
val existing: Boolean = false) extends HTMLComponent[html.Element] with MaterialIconViewTheme {
def this() = {
this(create[html.Element]("i"))
}

element.classList.add("material-icons")

override protected def defaultParentTheme: Theme = MaterialIconView

override def componentType: String = "MaterialIconView"
}

object MaterialIconView extends MaterialIconViewTheme {
override protected def defaultParentTheme: Theme = HTMLComponent

def existing(id: String, in: html.Element = document.body): MaterialIconViewTheme = {
new MaterialIconView(in.byId[html.Element](id), existing = true)
}
}
@@ -0,0 +1,14 @@
package io.youi.theme

import io.youi.font.{Material, MaterialIcon}
import io.youi.theme.mixins.HTMLFontTheme

trait MaterialIconViewTheme extends HTMLComponentTheme with HTMLFontTheme {
private implicit val iconStringify: Stringify[MaterialIcon] = new Stringify[MaterialIcon] {
override def fromString(value: String): Option[MaterialIcon] = Some(MaterialIcon(value))

override def toString(value: MaterialIcon): Option[String] = Some(value.name)
}

lazy val value: StyleProp[MaterialIcon] = style[MaterialIcon]("value", Material.Icons.Action.Help, StyleConnect.content[MaterialIcon], updatesTransform = false)
}
@@ -1,9 +1,8 @@
package io

import io.youi.event.KeyEvent
import io.youi.font.{GoogleFont, GoogleFontWeight}
import io.youi.font.{GoogleFont, GoogleFontWeight, MaterialIcon, MaterialIconView}
import io.youi.paint.Paint
import io.youi.style.{FontFamily, FontWeight}
import io.youi.task.PartialAnimate
import io.youi.theme.StyleProp
import org.scalajs.dom.html.Div
@@ -30,6 +29,14 @@ package object youi {

implicit def color2Paint(color: Color): Paint = Paint.color(color)

implicit class ExtendedMaterialIcon(icon: MaterialIcon) {
def toView: MaterialIconView = {
val view = new MaterialIconView
view.value := icon
view
}
}

implicit class ExtendedGoogleFont(font: GoogleFont) {
def load(): Future[GoogleFont] = {
val promise = Promise[GoogleFont]

0 comments on commit 52732fe

Please sign in to comment.
You can’t perform that action at this time.