Skip to content

Commit

Permalink
Start implementing Canvas backend
Browse files Browse the repository at this point in the history
- Implement first POC Drawing type

- Start documenting process

- Update dependencies

- Formatting
  • Loading branch information
noelwelsh committed May 16, 2024
1 parent 58032ce commit 7a8c528
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 27 additions & 0 deletions canvas/src/main/scala/doodle/canvas/algebra/Drawing.scala
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions docs/src/pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 8 additions & 0 deletions docs/src/pages/development/backend.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions docs/src/pages/development/directory.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
laika.navigationOrder = [
README.md
backend.md
]
2 changes: 2 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 7a8c528

Please sign in to comment.