Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 35d2dcc

Browse files
committedMar 12, 2025·
Update All Paints Update Function
1 parent 0eb0cf5 commit 35d2dcc

File tree

2 files changed

+88
-17
lines changed

2 files changed

+88
-17
lines changed
 

‎handwriting-compose/src/commonMain/kotlin/com/henni/handwriting/HandWritingNote.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fun HandWritingNote(
244244
},
245245
) {
246246
drawIntoCanvas { canvas ->
247-
drawRect(controller.contentBackground)
247+
drawRect(controller.contentBackgroundColor)
248248

249249
canvasImageBitmap?.let { bitmap ->
250250
canvas.drawImage(bitmap, Offset.Zero, Paint())

‎handwriting-compose/src/commonMain/kotlin/com/henni/handwriting/HandwritingController.kt

+87-16
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fun rememberHandwritingController(
7373
lassoBoundBoxColor: Color = Color.Black,
7474
lassoBoundBoxPadding: Padding = Padding(20, 20, 20, 20),
7575
laserColor: Color = Color.Black,
76-
contentBackground: Color = Color.Transparent,
76+
contentBackgroundColor: Color = Color.Transparent,
7777
contentBackgroundImage: ImageBitmap? = null,
7878
contentBackgroundImageColor: Color = Color.Transparent,
7979
contentBackgroundImageContentScale: ContentScale = ContentScale.None,
@@ -88,7 +88,7 @@ fun rememberHandwritingController(
8888
lassoBoundBoxColor,
8989
lassoBoundBoxPadding,
9090
laserColor,
91-
contentBackground,
91+
contentBackgroundColor,
9292
contentBackgroundImage,
9393
) {
9494
HandwritingController(
@@ -102,7 +102,7 @@ fun rememberHandwritingController(
102102
defaultLassoBoundBoxColor = lassoBoundBoxColor,
103103
defaultLassoBoundBoxPadding = lassoBoundBoxPadding,
104104
defaultLaserColor = laserColor,
105-
defaultContentBackground = contentBackground,
105+
defaultContentBackgroundColor = contentBackgroundColor,
106106
defaultContentBackgroundImage = contentBackgroundImage,
107107
defaultContentBackgroundImageColor = contentBackgroundImageColor,
108108
defaultContentBackgroundContentScale = contentBackgroundImageContentScale,
@@ -127,7 +127,7 @@ class HandwritingController internal constructor(
127127
defaultLassoBoundBoxColor: Color,
128128
defaultLassoBoundBoxPadding: Padding,
129129
defaultLaserColor: Color,
130-
defaultContentBackground: Color,
130+
defaultContentBackgroundColor: Color,
131131
defaultContentBackgroundImage: ImageBitmap?,
132132
defaultContentBackgroundImageColor: Color,
133133
defaultContentBackgroundContentScale: ContentScale,
@@ -145,12 +145,20 @@ class HandwritingController internal constructor(
145145
/**
146146
* A [Paint] object representing the pen's settings.
147147
*/
148-
internal val penPaint: Paint = defaultPenPaint()
148+
internal var penPaint by mutableStateOf(defaultPenPaint())
149149

150150
/**
151-
* A mutable state for the pen color, initially set to black.
151+
* Updates the pen paint.
152+
*
153+
* @param paint The new paint to set for the pen.
152154
*/
155+
fun updatePenPaint(paint: Paint) {
156+
penPaint = paint
157+
}
153158

159+
/**
160+
* A mutable state for the pen color, initially set to black.
161+
*/
154162
private var _penColor = mutableStateOf(defaultPenColor)
155163

156164
/**
@@ -197,7 +205,16 @@ class HandwritingController internal constructor(
197205
/**
198206
* A [Paint] object representing the eraser's settings.
199207
*/
200-
internal val eraserPointPaint: Paint = defaultStrokeEraserPaint()
208+
internal var eraserPointPaint by mutableStateOf(defaultStrokeEraserPaint())
209+
210+
/**
211+
* Updates the eraser point paint.
212+
*
213+
* @param paint The new paint to set for the eraser point.
214+
*/
215+
fun updateEraserPointPaint(paint: Paint) {
216+
eraserPointPaint = paint
217+
}
201218

202219
/**
203220
* A mutable state for the eraser point color, initially set to light gray.
@@ -224,29 +241,41 @@ class HandwritingController internal constructor(
224241
/**
225242
* A mutable state for the eraser point radius, initially set to 20f.
226243
*/
227-
var eraserPointRadius by mutableStateOf(defaultEraserPointRadius)
244+
private var _eraserPointRadius = mutableStateOf(defaultEraserPointRadius)
245+
246+
/**
247+
* Public property for retrieving the current eraser point radius.
248+
*/
249+
val eraserPointRadius: Float
250+
get() = _eraserPointRadius.value
228251

229252
/**
230253
* Updates the eraser point radius.
231254
*
232255
* @param radius The new radius to set for the eraser point.
233256
*/
234257
fun updateEraserPointRadius(radius: Float) {
235-
eraserPointRadius = radius
258+
_eraserPointRadius.value = radius
236259
}
237260

238261
/**
239262
* Determines whether the eraser point is visible.
240263
*/
241-
var isEraserPointShowed by mutableStateOf(defaultIsEraserPointShowed)
264+
private var _isEraserPointShowed by mutableStateOf(defaultIsEraserPointShowed)
265+
266+
/**
267+
* Public property for retrieving whether the eraser point is visible.
268+
*/
269+
val isEraserPointShowed: Boolean
270+
get() = _isEraserPointShowed
242271

243272
/**
244273
* Updates the visibility of the eraser point.
245274
*
246275
* @param isShowed A boolean indicating whether the eraser point should be visible.
247276
*/
248277
fun updateIsEraserPointShowed(isShowed: Boolean) {
249-
isEraserPointShowed = isShowed
278+
_isEraserPointShowed = isShowed
250279
}
251280

252281
// ==============================
@@ -256,7 +285,16 @@ class HandwritingController internal constructor(
256285
/**
257286
* A [Paint] object representing the lasso's settings.
258287
*/
259-
internal val lassoPaint: Paint = defaultLassoPaint()
288+
internal var lassoPaint: Paint by mutableStateOf(defaultLassoPaint())
289+
290+
/**
291+
* Updates the lasso paint.
292+
*
293+
* @param paint The new paint to set for the lasso.
294+
*/
295+
fun updateLassoPaint(paint: Paint) {
296+
lassoPaint = paint
297+
}
260298

261299
/**
262300
* A mutable state for the lasso color, initially set to black.
@@ -282,7 +320,16 @@ class HandwritingController internal constructor(
282320
/**
283321
* A [Paint] object representing the lasso bound box's settings.
284322
*/
285-
internal val lassoBoundBoxPaint: Paint = defaultLassoPaint()
323+
internal var lassoBoundBoxPaint by mutableStateOf(defaultLassoPaint())
324+
325+
/**
326+
* Updates the lasso bound box paint.
327+
*
328+
* @param paint The new paint to set for the lasso bound box.
329+
*/
330+
fun updateLassoBoundBoxPaint(paint: Paint) {
331+
lassoBoundBoxPaint = paint
332+
}
286333

287334
/**
288335
* A mutable state for the lasso bound box color, initially set to black.
@@ -335,7 +382,16 @@ class HandwritingController internal constructor(
335382
/**
336383
* A [Paint] object representing the laser's settings.
337384
*/
338-
internal val laserPaint: Paint = defaultLaserPaint()
385+
private var laserPaint by mutableStateOf(defaultLaserPaint())
386+
387+
/**
388+
* Updates the laser paint.
389+
*
390+
* @param paint The new paint to set for the laser.
391+
*/
392+
fun updateLaserPaint(paint: Paint) {
393+
laserPaint = paint
394+
}
339395

340396
/**
341397
* A mutable state for the laser color, initially set to black.
@@ -394,9 +450,24 @@ class HandwritingController internal constructor(
394450
// ==============================
395451

396452
/**
397-
* The background color of the handwriting canvas.
453+
* A mutable state holding the background color of the handwriting canvas.
454+
*/
455+
private var _contentBackgroundColor by mutableStateOf(defaultContentBackgroundColor)
456+
457+
/**
458+
* The public property to retrieve the current background color.
398459
*/
399-
val contentBackground by mutableStateOf(defaultContentBackground)
460+
val contentBackgroundColor: Color
461+
get() = _contentBackgroundColor
462+
463+
/**
464+
* Updates the background color of the handwriting canvas.
465+
*
466+
* @param color The new color to set as the background.
467+
*/
468+
fun updateContentBackgroundColor(color: Color) {
469+
_contentBackgroundColor = color
470+
}
400471

401472
/**
402473
* A mutable state holding the background image of the handwriting canvas.

0 commit comments

Comments
 (0)
Please sign in to comment.