adds fill for draw shapes

This commit is contained in:
Steve Ruiz 2021-06-20 09:29:46 +01:00
parent 9de38aa9da
commit 3cd30869a3
2 changed files with 16 additions and 6 deletions

View file

@ -40,7 +40,6 @@ const draw = registerShapeUtils<DrawShape>({
style: { style: {
...defaultStyle, ...defaultStyle,
...props.style, ...props.style,
isFilled: false,
}, },
} }
}, },
@ -60,7 +59,20 @@ const draw = registerShapeUtils<DrawShape>({
) )
} }
return <path id={id} d={pathCache.get(points)} fill={styles.stroke} /> return (
<g id={id}>
{points.length > 3 &&
vec.dist(points[0], points[points.length - 1]) < 8 && (
<polyline
points={points.map((pt) => pt.slice(0, 2)).join(',')}
fill={styles.fill}
stroke="none"
strokeWidth={0}
/>
)}
<path d={pathCache.get(points)} fill={styles.stroke} />
</g>
)
}, },
getBounds(shape) { getBounds(shape) {
@ -151,7 +163,6 @@ const draw = registerShapeUtils<DrawShape>({
applyStyles(shape, style) { applyStyles(shape, style) {
const styles = { ...shape.style, ...style } const styles = { ...shape.style, ...style }
styles.isFilled = false
styles.dash = DashStyle.Solid styles.dash = DashStyle.Solid
shape.style = styles shape.style = styles
shape.points = [...shape.points] shape.points = [...shape.points]
@ -170,7 +181,7 @@ const draw = registerShapeUtils<DrawShape>({
return this return this
}, },
canStyleFill: false, canStyleFill: true,
}) })
export default draw export default draw

View file

@ -1,6 +1,5 @@
import Head from 'next/head' import Head from 'next/head'
import { signIn, signOut, getSession, useSession } from 'next-auth/client' import { signIn, signOut, useSession } from 'next-auth/client'
import { GetServerSidePropsContext } from 'next'
export default function Home() { export default function Home() {
const [session, loading] = useSession() const [session, loading] = useSession()