Add shape fills for ellipse, rectangle (#145)
This commit is contained in:
parent
aae43884ca
commit
2722d81dbd
4 changed files with 13 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { Renderer } from '@tldraw/core'
|
import { Renderer } from '@tldraw/core'
|
||||||
import { Rectangle } from './rectangle'
|
import { Rectangle } from './box'
|
||||||
import { Label } from './label'
|
import { Label } from './label'
|
||||||
import { appState } from './state'
|
import { appState } from './state'
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,8 @@ export const Ellipse = new ShapeUtil<EllipseShape, SVGSVGElement, TLDrawMeta>(()
|
||||||
ry={ry + 2}
|
ry={ry + 2}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<ellipse
|
<path
|
||||||
cx={radiusX}
|
d={getEllipseIndicatorPathData(shape, this.getCenter(shape))}
|
||||||
cy={radiusY}
|
|
||||||
rx={rx}
|
|
||||||
ry={ry}
|
|
||||||
stroke="none"
|
stroke="none"
|
||||||
fill={style.isFilled ? styles.fill : 'none'}
|
fill={style.isFilled ? styles.fill : 'none'}
|
||||||
pointerEvents="all"
|
pointerEvents="all"
|
||||||
|
@ -124,17 +121,7 @@ export const Ellipse = new ShapeUtil<EllipseShape, SVGSVGElement, TLDrawMeta>(()
|
||||||
},
|
},
|
||||||
|
|
||||||
Indicator({ shape }) {
|
Indicator({ shape }) {
|
||||||
const {
|
return <path d={getEllipseIndicatorPathData(shape, this.getCenter(shape))} />
|
||||||
style,
|
|
||||||
radius: [rx, ry],
|
|
||||||
} = shape
|
|
||||||
|
|
||||||
const styles = getShapeStyle(style, false)
|
|
||||||
const strokeWidth = +styles.strokeWidth
|
|
||||||
|
|
||||||
const sw = strokeWidth
|
|
||||||
|
|
||||||
return <ellipse cx={rx} cy={ry} rx={rx - sw / 2} ry={ry - sw / 2} />
|
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldRender(prev, next) {
|
shouldRender(prev, next) {
|
||||||
|
@ -381,3 +368,10 @@ function getEllipsePath(shape: EllipseShape, boundsCenter: number[]) {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEllipseIndicatorPathData(shape: EllipseShape, boundsCenter: number[]) {
|
||||||
|
return Utils.getSvgPathFromStroke(
|
||||||
|
getEllipseStrokePoints(shape, boundsCenter).map((pt) => pt.point.slice(0, 2)),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -51,11 +51,8 @@ export const Rectangle = new ShapeUtil<RectangleShape, SVGSVGElement, TLDrawMeta
|
||||||
height={Math.max(0, size[1] - strokeWidth / 2) + 64}
|
height={Math.max(0, size[1] - strokeWidth / 2) + 64}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<rect
|
<path
|
||||||
x={styles.strokeWidth / 2}
|
d={getRectangleIndicatorPathData(shape)}
|
||||||
y={styles.strokeWidth / 2}
|
|
||||||
width={Math.max(0, size[0] - strokeWidth)}
|
|
||||||
height={Math.max(0, size[1] - strokeWidth)}
|
|
||||||
fill={style.isFilled ? styles.fill : 'none'}
|
fill={style.isFilled ? styles.fill : 'none'}
|
||||||
radius={strokeWidth}
|
radius={strokeWidth}
|
||||||
stroke="none"
|
stroke="none"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue