From 7a8c528561ca82a56a3ab0c002eb26501a82c401 Mon Sep 17 00:00:00 2001 From: Noel Welsh Date: Thu, 16 May 2024 22:13:41 +0100 Subject: [PATCH] Start implementing Canvas backend - Implement first POC Drawing type - Start documenting process - Update dependencies - Formatting --- .github/workflows/ci.yml | 2 +- build.sbt | 6 ++++- .../scala/doodle/canvas/algebra/Drawing.scala | 27 +++++++++++++++++++ docs/src/pages/README.md | 1 + docs/src/pages/development/backend.md | 8 ++++++ docs/src/pages/development/directory.conf | 4 +++ project/Dependencies.scala | 2 ++ project/plugins.sbt | 4 +-- 8 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 canvas/src/main/scala/doodle/canvas/algebra/Drawing.scala create mode 100644 docs/src/pages/development/backend.md create mode 100644 docs/src/pages/development/directory.conf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13f71dde..0169ea18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -223,7 +223,7 @@ jobs: - name: Publish site if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' - uses: peaceiris/actions-gh-pages@v3.9.3 + uses: peaceiris/actions-gh-pages@v4.0.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: docs/target/docs/site diff --git a/build.sbt b/build.sbt index eb6c01eb..579889da 100644 --- a/build.sbt +++ b/build.sbt @@ -263,7 +263,11 @@ lazy val svg = crossProject(JSPlatform, JVMPlatform) lazy val canvas = project .in(file("canvas")) - .settings(commonSettings, moduleName := "doode-canvas") + .settings( + commonSettings, + libraryDependencies += Dependencies.scalajsDom.value, + moduleName := "doode-canvas" + ) .dependsOn(core.js) .enablePlugins(ScalaJSPlugin) diff --git a/canvas/src/main/scala/doodle/canvas/algebra/Drawing.scala b/canvas/src/main/scala/doodle/canvas/algebra/Drawing.scala new file mode 100644 index 00000000..196a3688 --- /dev/null +++ b/canvas/src/main/scala/doodle/canvas/algebra/Drawing.scala @@ -0,0 +1,27 @@ +/* + * Copyright 2015 Creative Scala + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package doodle.canvas.algebra + +import org.scalajs.dom.CanvasRenderingContext2D + +/** A canvas `Drawing` is a function that, when applied, produces a value of + * type `A` and has the side-effect of drawing on the canvas. + */ +opaque type Drawing[A] = Function[CanvasRenderingContext2D, A] +object Drawing { + def apply[A](f: CanvasRenderingContext2D => A): Drawing[A] = f +} diff --git a/docs/src/pages/README.md b/docs/src/pages/README.md index 19530c48..61ad5573 100644 --- a/docs/src/pages/README.md +++ b/docs/src/pages/README.md @@ -20,6 +20,7 @@ See the ScalaDoc @:api(doodle.index) for API documentation. ## Community Join the [Creative Scala Discord][discord]. + [discord]: https://discord.gg/rRhcFbJxVG diff --git a/docs/src/pages/development/backend.md b/docs/src/pages/development/backend.md new file mode 100644 index 00000000..ed951e57 --- /dev/null +++ b/docs/src/pages/development/backend.md @@ -0,0 +1,8 @@ +# Implementing a Backend + +This is a quick guide to implementing a backend. It assume familiarity with the major [concepts](../concepts/README.md) of Doodle. + + +## Drawing Type + +Deciding on the `Drawing` type is the first step in implementing a backend. It must have the shape `Drawing[A]`, where `A` is the value produced when drawing the drawing. diff --git a/docs/src/pages/development/directory.conf b/docs/src/pages/development/directory.conf new file mode 100644 index 00000000..2993a209 --- /dev/null +++ b/docs/src/pages/development/directory.conf @@ -0,0 +1,4 @@ +laika.navigationOrder = [ + README.md + backend.md +] diff --git a/project/Dependencies.scala b/project/Dependencies.scala index da623899..630e583c 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -10,6 +10,7 @@ object Dependencies { val fs2Version = "3.10.0" val scalatagsVersion = "0.12.0" + val scalajsDomVersion = "2.2.0" val batikVersion = "1.17" @@ -25,6 +26,7 @@ object Dependencies { val fs2 = Def.setting("co.fs2" %%% "fs2-core" % fs2Version) val scalatags = Def.setting("com.lihaoyi" %%% "scalatags" % scalatagsVersion) + val scalajsDom = Def.setting("org.scala-js" %%% "scalajs-dom" % scalajsDomVersion) val batik = Def.setting("org.apache.xmlgraphics" % "batik-transcoder" % batikVersion) diff --git a/project/plugins.sbt b/project/plugins.sbt index a4447605..1b32523f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,5 +3,5 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0") -addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.7") -addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.7") +addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.7.1") +addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.7.1")