Skip to content

Commit

Permalink
Merge pull request #90 from Fbada006/emmanuelmuturia/task/disable-era…
Browse files Browse the repository at this point in the history
…se-button-without-drawing

Toggle Eraser Button Based On Drawing Presence
  • Loading branch information
emmanuelmuturia authored Sep 19, 2024
2 parents 1faefe9 + 59df959 commit b0929d9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions artmaker/src/main/java/io/artmaker/ArtMaker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ fun ArtMaker(
finishedImage?.let { onFinishDrawing(it) }
}

LaunchedEffect(key1 = state.canErase) {
if (!state.canErase) {
isEraserActive = false
}
}

Scaffold(
floatingActionButton = {
AnimatedVisibility(
Expand Down
1 change: 1 addition & 0 deletions artmaker/src/main/java/io/artmaker/ArtMakerUIState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data class ArtMakerUIState(
val canRedo: Boolean = false,
val canUndo: Boolean = false,
val canClear: Boolean = false,
val canErase: Boolean = false,
val shouldUseStylusOnly: Boolean = false,
val shouldDetectPressure: Boolean = false,
val canShowEnableStylusDialog: Boolean = true,
Expand Down
1 change: 1 addition & 0 deletions artmaker/src/main/java/io/artmaker/ArtMakerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ internal class ArtMakerViewModel(
canRedo = state.canRedo,
canUndo = state.canUndo,
canClear = state.canClear,
canErase = state.canErase,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ internal fun ArtMakerControlMenu(
)
},
onItemClicked = onActivateEraser,
enabled = state.canErase,
)
MenuItem(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_undo),
Expand Down
8 changes: 5 additions & 3 deletions artmaker/src/main/java/io/artmaker/drawing/DrawingManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ internal class DrawingManager {
}

private fun updateCurrentShape(offset: Offset, pressure: Float) {
val idx = _pathList.lastIndex
_pathList[idx].points.add(offset)
_pathList[idx].alphas.add(pressure)
if (pathList.isNotEmpty()) {
val idx = _pathList.lastIndex
_pathList[idx].points.add(offset)
_pathList[idx].alphas.add(pressure)
}
}

private fun undoLastShapePoint() {
Expand Down

0 comments on commit b0929d9

Please sign in to comment.