Navigation Menu

Skip to content

Commit

Permalink
Preliminary integration of material icon support
Browse files Browse the repository at this point in the history
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 52732fe
Show file tree
Hide file tree
Showing 11 changed files with 5,743 additions and 3,682 deletions.
15 changes: 5 additions & 10 deletions build.sbt
Expand Up @@ -231,16 +231,12 @@ lazy val app = crossProject(JSPlatform, JVMPlatform).in(file("app"))
lazy val appJS = app.js lazy val appJS = app.js
lazy val appJVM = app.jvm.dependsOn(server) lazy val appJVM = app.jvm.dependsOn(server)


lazy val example = crossProject(JSPlatform, JVMPlatform).in(file("example")) lazy val example = crossApplication.in(file("example"))
.settings( .settings(
name := "youi-example" name := "youi-example",
youiVersion := version.value
) )
.jsSettings( .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 jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
) )
.jvmSettings( .jvmSettings(
Expand All @@ -250,10 +246,9 @@ lazy val example = crossProject(JSPlatform, JVMPlatform).in(file("example"))
"org.scala-lang.modules" %% "scala-xml" % scalaXMLVersion "org.scala-lang.modules" %% "scala-xml" % scalaXMLVersion
) )
) )
.dependsOn(app)


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


lazy val utilities = project.in(file("utilities")) lazy val utilities = project.in(file("utilities"))
.settings( .settings(
Expand Down
Expand Up @@ -46,6 +46,7 @@ object ClientExampleApplication extends ExampleApplication with ClientApplicatio
val hit: HitTestExample = new HitTestExample val hit: HitTestExample = new HitTestExample
val image: ImageExample = new ImageExample val image: ImageExample = new ImageExample
val imageChange: ImageChangeExample = new ImageChangeExample val imageChange: ImageChangeExample = new ImageChangeExample
val materialIcons: MaterialIconsExample = new MaterialIconsExample
val measured: MeasuredExample = new MeasuredExample val measured: MeasuredExample = new MeasuredExample
val parallax: ParallaxExample = new ParallaxExample val parallax: ParallaxExample = new ParallaxExample
val scale9: Scale9Example = new Scale9Example val scale9: Scale9Example = new Scale9Example
Expand Down
@@ -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
}
}
Expand Up @@ -21,9 +21,6 @@ object ServerExampleApplication extends ExampleApplication with ServerApplicatio
classOf[SimpleCommunication] -> "simple" 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) case class Greeting(message: String, name: String)


override protected def init(): Future[Unit] = super.init().map { _ => override protected def init(): Future[Unit] = super.init().map { _ =>
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Expand Up @@ -9,4 +9,6 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.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")
27 changes: 27 additions & 0 deletions ui/js/src/main/scala/io/youi/font/MaterialIconView.scala
@@ -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)
}
}
14 changes: 14 additions & 0 deletions ui/js/src/main/scala/io/youi/theme/MaterialIconViewTheme.scala
@@ -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)
}
11 changes: 9 additions & 2 deletions ui/js/src/main/scala/io/youi/youi.scala
@@ -1,9 +1,8 @@
package io package io


import io.youi.event.KeyEvent 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.paint.Paint
import io.youi.style.{FontFamily, FontWeight}
import io.youi.task.PartialAnimate import io.youi.task.PartialAnimate
import io.youi.theme.StyleProp import io.youi.theme.StyleProp
import org.scalajs.dom.html.Div import org.scalajs.dom.html.Div
Expand All @@ -30,6 +29,14 @@ package object youi {


implicit def color2Paint(color: Color): Paint = Paint.color(color) 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) { implicit class ExtendedGoogleFont(font: GoogleFont) {
def load(): Future[GoogleFont] = { def load(): Future[GoogleFont] = {
val promise = Promise[GoogleFont] val promise = Promise[GoogleFont]
Expand Down

0 comments on commit 52732fe

Please sign in to comment.