From 82cec909a6120c5f2fb4de8c56486a14f1071392 Mon Sep 17 00:00:00 2001 From: linsy king Date: Sun, 7 May 2023 22:35:53 +0800 Subject: [PATCH] feat: add empty renderable --- elm.json | 2 +- src/Canvas.elm | 18 ++++++++++++++++-- src/Canvas/Internal/Canvas.elm | 1 + src/Canvas/Settings/Text.elm | 4 ++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/elm.json b/elm.json index ce776f2..4dcfe07 100644 --- a/elm.json +++ b/elm.json @@ -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" diff --git a/src/Canvas.elm b/src/Canvas.elm index 52d3e3a..67fb4a8 100755 --- a/src/Canvas.elm +++ b/src/Canvas.elm @@ -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 @@ -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 @@ -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 @@ -619,6 +630,9 @@ renderDrawable drawable drawOp cmds = DrawableGroup renderables -> renderGroup drawOp renderables cmds + DrawableEmpty -> + cmds + renderShape : Shape -> Commands -> Commands renderShape shape cmds = diff --git a/src/Canvas/Internal/Canvas.elm b/src/Canvas/Internal/Canvas.elm index 8f5416a..e447b72 100755 --- a/src/Canvas/Internal/Canvas.elm +++ b/src/Canvas/Internal/Canvas.elm @@ -37,6 +37,7 @@ type Drawable | DrawableTexture Point Texture | DrawableClear Point Float Float | DrawableGroup (List Renderable) + | DrawableEmpty type Renderable diff --git a/src/Canvas/Settings/Text.elm b/src/Canvas/Settings/Text.elm index 9546317..b31979b 100755 --- a/src/Canvas/Settings/Text.elm +++ b/src/Canvas/Settings/Text.elm @@ -50,6 +50,7 @@ type TextAlign | End +textAlignToString : TextAlign -> String textAlignToString alignment = case alignment of Left -> @@ -182,4 +183,7 @@ maxWidth width = DrawableGroup _ -> d + + DrawableEmpty -> + d )