Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immediate Mode in Doodle Canvas #168

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b46b037
Something
VOSID8 Jun 23, 2024
ac31aad
Formatting and undoing experimental changes
VOSID8 Jun 23, 2024
0deaf63
Edited name of the file
VOSID8 Jun 23, 2024
ed749d3
Implemeting dummy
VOSID8 Jun 23, 2024
6a95f8d
Removed junk code
VOSID8 Jun 25, 2024
739b907
Fixing Reified file
VOSID8 Jun 25, 2024
c52c5b6
Removing junk files
VOSID8 Jun 25, 2024
5418467
Removing junk files
VOSID8 Jun 25, 2024
9e05dcf
Changed type parameter to raster[A] to trait[A]
VOSID8 Jun 26, 2024
b22fabd
Changed type parameter to raster[A] to trait[A]
VOSID8 Jun 26, 2024
d882c6e
Removed junk file
VOSID8 Jun 26, 2024
d9c5745
Removed Raster from Image and added an experiment example
VOSID8 Jun 27, 2024
f4deb93
Removed Raster from Image and added an experiment example
VOSID8 Jun 27, 2024
879be92
Added Headers to 2 files
VOSID8 Jun 27, 2024
ce43de1
Adding 2nd parameter in example
VOSID8 Jun 27, 2024
7d53610
prePR formatted the code
VOSID8 Jun 27, 2024
4c4c4a6
Fix ScalaFix configuration
noelwelsh Jun 27, 2024
5b51b48
Fix raster syntax
noelwelsh Jun 27, 2024
300f5fa
Add raster syntax to JVM syntax
noelwelsh Jun 27, 2024
635298d
Organize imports
noelwelsh Jun 27, 2024
cab9c2f
Update workflows
noelwelsh Jun 27, 2024
57aa401
Merge pull request #1 from noelwelsh/canvasRaster
VOSID8 Jun 28, 2024
dada964
Changing Algrabra to something of combinator
VOSID8 Jun 30, 2024
5ab7c2c
Raster as constructor
VOSID8 Jul 1, 2024
eddca62
Added transformation to the Raster
VOSID8 Jul 3, 2024
a8be38b
Replacing Canvas Methods with Doodle's
VOSID8 Jul 10, 2024
4a1268a
Replacing Canvas Methods with Doodle's
VOSID8 Jul 10, 2024
8b9d0a3
Passing canvasContext as implicit
VOSID8 Jul 12, 2024
176c370
First working Immediate model
VOSID8 Jul 13, 2024
18c6a84
meh5
VOSID8 Jul 17, 2024
1fbc41f
Implemented few Immediate methods
VOSID8 Jul 18, 2024
826e35f
Added Methods for Immediate
VOSID8 Jul 24, 2024
52ddb09
fillColor to fill
VOSID8 Aug 2, 2024
acc8921
Methods added
VOSID8 Aug 7, 2024
7906eeb
Added text method
VOSID8 Aug 14, 2024
ad31840
Added dash Shapes and text
VOSID8 Aug 16, 2024
167b572
Added star
VOSID8 Aug 17, 2024
66ca336
Added canvasImmediate Landscape example and few fixes
VOSID8 Aug 17, 2024
ec3054a
Formatted the code
VOSID8 Aug 18, 2024
69b6150
GitWorkflowGenerate
VOSID8 Aug 18, 2024
30f91b4
Removed warnings
VOSID8 Aug 18, 2024
ced2f8e
Removed cmd /c from sbt file
VOSID8 Aug 18, 2024
24bc8c5
Few changes and example setup
VOSID8 Aug 20, 2024
37f2618
Fixed methods"
VOSID8 Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
rules = [
OrganizeImports
]
OrganizeImports.removeUnused = false
OrganizeImports.coalesceToWildcardImportThreshold = 5
10 changes: 9 additions & 1 deletion canvas/src/main/scala/doodle/canvas/algebra/CanvasAlgebra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ final case class CanvasAlgebra(
applyDrawing: Apply[CanvasDrawing] = Apply.apply[CanvasDrawing],
functorDrawing: Functor[CanvasDrawing] = Apply.apply[CanvasDrawing]
) extends Path,
Raster,
Shape,
GenericDebug[CanvasDrawing],
GenericLayout[CanvasDrawing],
GenericRaster[CanvasDrawing, Immediate],
GenericShape[CanvasDrawing],
GenericSize[CanvasDrawing],
GenericStyle[CanvasDrawing],
GenericTransform[CanvasDrawing],
GivenApply[CanvasDrawing],
GivenFunctor[CanvasDrawing],
doodle.algebra.Algebra {
type Drawing[A] = doodle.canvas.Drawing[A]

override def empty: Finalized[CanvasDrawing, Unit] =
Finalized.leaf(_ =>
(BoundingBox.empty, Renderable.unit(CanvasDrawing.unit))
)

implicit val drawingInstance: Monad[Drawing] =
new Monad[Drawing] {
def pure[A](x: A): Drawing[A] =
Expand Down Expand Up @@ -67,5 +76,4 @@ final case class CanvasAlgebra(
)
}
}

}
19 changes: 19 additions & 0 deletions canvas/src/main/scala/doodle/canvas/algebra/CanvasDrawing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package doodle.canvas.algebra

import doodle.algebra.generic.*

import cats.Apply
import doodle.algebra.generic.Fill
import doodle.algebra.generic.Fill.ColorFill
Expand All @@ -36,6 +38,7 @@ import doodle.core.font.FontSize
import doodle.core.font.FontStyle
import doodle.core.font.FontWeight
import org.scalajs.dom.CanvasRenderingContext2D
import org.scalajs.dom.Path2D

import scala.scalajs.js
import scala.scalajs.js.JSConverters.*
Expand All @@ -44,6 +47,7 @@ import scala.scalajs.js.JSConverters.*
* type `A` and has the side-effect of drawing on the canvas.
*/
opaque type CanvasDrawing[A] = Function[CanvasRenderingContext2D, A]

object CanvasDrawing {
given Apply[CanvasDrawing] with {
def ap[A, B](ff: CanvasDrawing[A => B])(
Expand Down Expand Up @@ -121,6 +125,21 @@ object CanvasDrawing {
}
}

def raster(width: Int, height: Int)(
f: Immediate => Unit
): CanvasDrawing[Unit] = {
CanvasDrawing { ctx =>
val path = new Path2D()
val immediate = new ImmediateImpl(width, height, ctx, path)
f(immediate)
}
}

def text(text: String, x: Double, y: Double): CanvasDrawing[Unit] =
CanvasDrawing { ctx =>
ctx.fillText(text, x, y)
}

def setFill(fill: Option[Fill]): CanvasDrawing[Unit] =
fill.map(setFill).getOrElse(unit)

Expand Down
Loading