Skip to content

Commit e907f51

Browse files
committed
chore: prettify dart tool parametrization in canvas
1 parent 0c01bb4 commit e907f51

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

lib/components/canvas/canvas.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,40 @@ class Canvas extends StatelessWidget {
4747
final double currentScale;
4848
final bool placeholder;
4949

50-
int toolToOnyx(Tool currentTool) {
51-
if (placeholder) return 5;
50+
OnyxStrokeStyle getOnyxTool(Tool currentTool) {
51+
if (placeholder) return OnyxStrokeStyle.pen;
5252
if (currentTool is Pencil) {
53-
return 3;
53+
return OnyxStrokeStyle.pencil;
5454
} else if (currentTool is Highlighter) {
55-
return 4;
55+
return OnyxStrokeStyle.marker;
5656
} else if (currentTool is Eraser) {
57-
return 1;
57+
return OnyxStrokeStyle.disabled;
5858
} else if (currentTool is Select) {
59-
return 1;
59+
return OnyxStrokeStyle.pen;
6060
} else if (currentTool is LaserPointer) {
61-
return 1;
61+
return OnyxStrokeStyle.pen;
6262
} else if (currentTool is Pen) {
63-
if (currentTool.isPressureEnabled()) {
64-
return 2;
63+
if (currentTool.pressureEnabled) {
64+
return OnyxStrokeStyle.brush;
6565
} else {
66-
return 1;
66+
return OnyxStrokeStyle.pen;
6767
}
6868
} else {
69-
return 5;
69+
return OnyxStrokeStyle.pen;
7070
}
7171
}
7272

73-
int getColor() {
73+
int getOnyxColor() {
7474
if (currentTool is Pen) {
7575
return (currentTool as Pen).color.toARGB32();
7676
} else {
7777
return Colors.black.toARGB32();
7878
}
7979
}
80-
double getWidth() {
80+
double getOnyxWidth() {
8181
if (currentTool is Pen) {
82-
double baseSize = (currentTool as Pen).getSize() * currentScale;
83-
if ((currentTool as Pen).isPressureEnabled()) {
82+
double baseSize = (currentTool as Pen).options.size * currentScale;
83+
if ((currentTool as Pen).pressureEnabled) {
8484
return baseSize;
8585
} else {
8686
return baseSize * 2;
@@ -112,9 +112,9 @@ class Canvas extends StatelessWidget {
112112
height: page.size.height,
113113
child: OnyxSdkPenArea(
114114
refreshDelay: const Duration(seconds: 1),
115-
strokeStyle: toolToOnyx(currentTool),
116-
strokeColor: getColor(),
117-
strokeWidth: getWidth(),
115+
strokeStyle: getOnyxTool(currentTool),
116+
strokeColor: getOnyxColor(),
117+
strokeWidth: getOnyxWidth(),
118118
child: InnerCanvas(
119119
key: page.innerCanvasKey,
120120
pageIndex: pageIndex,

packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@ import 'package:flutter/services.dart';
77

88
import 'onyxsdk_pen_platform_interface.dart';
99

10+
enum OnyxStrokeStyle {
11+
fountainPen(0),
12+
pen(1),
13+
brush(2),
14+
pencil(3),
15+
marker(4),
16+
disabled(5);
17+
18+
const OnyxStrokeStyle(this.value);
19+
final int value;
20+
}
21+
1022
/// Renders a native Android view which uses the Onyx SDK to draw on the screen.
1123
class OnyxSdkPenArea extends StatefulWidget {
1224
const OnyxSdkPenArea({
1325
super.key,
1426
this.refreshDelay = const Duration(seconds: 1),
15-
this.strokeStyle = 0,
27+
this.strokeStyle = OnyxStrokeStyle.fountainPen,
1628
this.strokeColor = 0,
1729
this.strokeWidth = 3.0,
1830
required this.child,
@@ -24,7 +36,7 @@ class OnyxSdkPenArea extends StatefulWidget {
2436
/// is still writing, which will make the screen get stuck in a half-drawn
2537
/// state.
2638
final Duration refreshDelay;
27-
final int strokeStyle;
39+
final OnyxStrokeStyle strokeStyle;
2840
final int strokeColor;
2941
final double strokeWidth;
3042

@@ -71,7 +83,7 @@ class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> with WidgetsBindingObse
7183
/// Parameters to pass to the platform side
7284
late final creationParams = <String, dynamic>{
7385
"refreshDelayMs": widget.refreshDelay.inMilliseconds,
74-
"strokeStyle": widget.strokeStyle,
86+
"strokeStyle": widget.strokeStyle.value,
7587
"strokeColor": widget.strokeColor,
7688
"strokeWidth": widget.strokeWidth,
7789
};
@@ -85,7 +97,7 @@ class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> with WidgetsBindingObse
8597
super.didUpdateWidget(oldWidget);
8698

8799
creationParams['refreshDelayMs'] = widget.refreshDelay.inMilliseconds;
88-
creationParams['strokeStyle'] = widget.strokeStyle;
100+
creationParams['strokeStyle'] = widget.strokeStyle.value;
89101
creationParams['strokeColor'] = widget.strokeColor;
90102
creationParams['strokeWidth'] = widget.strokeWidth;
91103
channel.invokeMethod('updateStroke', creationParams).catchError((e) {});

0 commit comments

Comments
 (0)