Skip to content

Commit

Permalink
feat: add empty renderable
Browse files Browse the repository at this point in the history
  • Loading branch information
linsyking committed May 7, 2023
1 parent be16be0 commit 82cec90
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "linsyking/elm-canvas",
"summary": "2D drawing API based on DOM Canvas, but nicer",
"license": "BSD-3-Clause",
"version": "3.0.0",
"version": "3.1.0",
"exposed-modules": {
"Main module": [
"Canvas"
Expand Down
18 changes: 16 additions & 2 deletions src/Canvas.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Canvas exposing
( toHtml, toHtmlWith
, Renderable, Point
, clear, shapes, text, texture, group
, clear, shapes, text, texture, group, empty
, Shape
, rect, roundRect, circle, arc, path
, PathSegment, arcTo, bezierCurveTo, lineTo, moveTo, quadraticCurveTo
Expand All @@ -23,7 +23,7 @@ requires the `elm-canvas` web component to work.
@docs Renderable, Point
@docs clear, shapes, text, texture, group
@docs clear, shapes, text, texture, group, empty
# Drawing shapes
Expand Down Expand Up @@ -582,6 +582,17 @@ group settings entities =
)


{-| Empty renderable. Useful for creating an empty renderable instead of writing `group [] []`
-}
empty : Renderable
empty =
Renderable
{ commands = []
, drawOp = NotSpecified
, drawable = DrawableEmpty
}



-- Rendering internals

Expand Down Expand Up @@ -619,6 +630,9 @@ renderDrawable drawable drawOp cmds =
DrawableGroup renderables ->
renderGroup drawOp renderables cmds

DrawableEmpty ->
cmds


renderShape : Shape -> Commands -> Commands
renderShape shape cmds =
Expand Down
1 change: 1 addition & 0 deletions src/Canvas/Internal/Canvas.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Drawable
| DrawableTexture Point Texture
| DrawableClear Point Float Float
| DrawableGroup (List Renderable)
| DrawableEmpty


type Renderable
Expand Down
4 changes: 4 additions & 0 deletions src/Canvas/Settings/Text.elm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type TextAlign
| End


textAlignToString : TextAlign -> String
textAlignToString alignment =
case alignment of
Left ->
Expand Down Expand Up @@ -182,4 +183,7 @@ maxWidth width =

DrawableGroup _ ->
d

DrawableEmpty ->
d
)

0 comments on commit 82cec90

Please sign in to comment.