Skip to content

Commit

Permalink
refactor: use the current thickness of the shape while dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafacagri committed Oct 18, 2024
1 parent 55c01ca commit 8d2042d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const Canvas: React.FC = () => {
const g = this.graphics
g.clear()
.beginStroke(props.strokeColor)
.setStrokeStyle(pathThickness)
.setStrokeStyle(props?.thickness ?? pathThickness)
.moveTo(0, 0)
.lineTo(props.endX - props.x, props.endY - props.y)
} else if (props.type === 'path' && props.points) {
Expand Down Expand Up @@ -165,6 +165,11 @@ const Canvas: React.FC = () => {
g.clear()

const { x: startX, y: startY } = startPoint
let thickness = pathThickness

if (['line', 'path'].includes(shapeType) && currentShape?.graphics?._strokeStyle?.width) {
thickness = currentShape?.graphics?._strokeStyle?.width
}

switch (shapeType) {
case 'rectangle':
Expand All @@ -178,10 +183,10 @@ const Canvas: React.FC = () => {
break
}
case 'line':
g.beginStroke(pathColor.current).setStrokeStyle(pathThickness).moveTo(startX, startY).lineTo(x, y)
g.beginStroke(pathColor.current).setStrokeStyle(thickness).moveTo(startX, startY).lineTo(x, y)
break
case 'path': {
const newPoints = g.beginStroke(pathColor.current).setStrokeStyle(pathThickness)
const newPoints = g.beginStroke(pathColor.current).setStrokeStyle(thickness)

if (isEmpty(pathPointsRef.current)) {
newPoints.moveTo(startX, startY)
Expand Down
1 change: 1 addition & 0 deletions src/utils/exportimport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const getUpdatedShapeData = (shape: Shape) => {
points: shape.points ? [...shape.points] : undefined,
endX: shape.endX,
endY: shape.endY,
thickness: shape.thickness,
}

switch (shape.type) {
Expand Down

0 comments on commit 8d2042d

Please sign in to comment.