Skip to content

Commit 4c7eaff

Browse files
arpandazeadil192
authored andcommitted
feat: background line thickness settings created
1 parent e81fab0 commit 4c7eaff

File tree

9 files changed

+56
-1
lines changed

9 files changed

+56
-1
lines changed

lib/components/canvas/_canvas_background_painter.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class CanvasBackgroundPainter extends CustomPainter {
99
required this.backgroundColor,
1010
this.backgroundPattern = CanvasBackgroundPattern.none,
1111
required this.lineHeight,
12+
required this.lineThickness,
1213
this.primaryColor = Colors.blue,
1314
this.secondaryColor = Colors.red,
1415
this.preview = false,
@@ -22,6 +23,7 @@ class CanvasBackgroundPainter extends CustomPainter {
2223

2324
/// The height between each line in the background pattern
2425
final int lineHeight;
26+
final int lineThickness;
2527
final Color primaryColor, secondaryColor;
2628

2729
/// Whether to draw the background pattern in a preview mode (more opaque).
@@ -35,7 +37,7 @@ class CanvasBackgroundPainter extends CustomPainter {
3537
paint.color = backgroundColor.withInversion(invert);
3638
canvas.drawRect(canvasRect, paint);
3739

38-
paint.strokeWidth = 3;
40+
paint.strokeWidth = lineThickness.toDouble();
3941
for (PatternElement element in getPatternElements(
4042
pattern: backgroundPattern,
4143
size: size,

lib/components/canvas/canvas_background_preview.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CanvasBackgroundPreview extends StatelessWidget {
1616
this.overrideBoxFit,
1717
required this.pageSize,
1818
required this.lineHeight,
19+
required this.lineThickness,
1920
});
2021

2122
final bool selected;
@@ -26,6 +27,7 @@ class CanvasBackgroundPreview extends StatelessWidget {
2627
final BoxFit? overrideBoxFit;
2728
final Size pageSize;
2829
final int lineHeight;
30+
final int lineThickness;
2931

3032
static const double fixedWidth = 150;
3133

@@ -74,6 +76,7 @@ class CanvasBackgroundPreview extends StatelessWidget {
7476
}
7577
}(),
7678
lineHeight: lineHeight,
79+
lineThickness: lineThickness,
7780
primaryColor: colorScheme.primary
7881
.withSaturation(selected ? 1 : 0)
7982
.withValues(alpha: selected ? 1 : 0.5),

lib/components/canvas/inner_canvas.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class _InnerCanvasState extends State<InnerCanvas> {
128128
}
129129
}(),
130130
lineHeight: widget.coreInfo.lineHeight,
131+
lineThickness: widget.coreInfo.lineThickness,
131132
primaryColor: colorScheme.primary,
132133
secondaryColor: colorScheme.secondary,
133134
),

lib/components/toolbar/editor_bottom_sheet.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class EditorBottomSheet extends StatefulWidget {
1919
required this.currentPageIndex,
2020
required this.setBackgroundPattern,
2121
required this.setLineHeight,
22+
required this.setLineThickness,
2223
required this.removeBackgroundImage,
2324
required this.redrawImage,
2425
required this.clearPage,
@@ -36,6 +37,7 @@ class EditorBottomSheet extends StatefulWidget {
3637
final int? currentPageIndex;
3738
final void Function(CanvasBackgroundPattern) setBackgroundPattern;
3839
final void Function(int) setLineHeight;
40+
final void Function(int) setLineThickness;
3941
final VoidCallback removeBackgroundImage;
4042
final VoidCallback redrawImage;
4143
final VoidCallback clearPage;
@@ -160,6 +162,7 @@ class _EditorBottomSheetState extends State<EditorBottomSheet> {
160162
overrideBoxFit: boxFit,
161163
pageSize: pageSize,
162164
lineHeight: widget.coreInfo.lineHeight,
165+
lineThickness: widget.coreInfo.lineThickness,
163166
),
164167
Positioned(
165168
bottom: previewSize.height * 0.1,
@@ -220,6 +223,7 @@ class _EditorBottomSheetState extends State<EditorBottomSheet> {
220223
backgroundImage: null, // focus on background pattern
221224
pageSize: pageSize,
222225
lineHeight: widget.coreInfo.lineHeight,
226+
lineThickness: widget.coreInfo.lineThickness,
223227
),
224228
Positioned(
225229
bottom: previewSize.height * 0.1,
@@ -263,6 +267,30 @@ class _EditorBottomSheetState extends State<EditorBottomSheet> {
263267
),
264268
],
265269
),
270+
Text(
271+
t.editor.menu.lineThickness,
272+
style: Theme.of(context).textTheme.titleMedium,
273+
),
274+
Text(
275+
t.editor.menu.lineThicknessDescription,
276+
style: Theme.of(context).textTheme.bodyMedium,
277+
),
278+
Row(
279+
children: [
280+
Text(widget.coreInfo.lineThickness.toString()),
281+
Expanded(
282+
child: Slider(
283+
value: widget.coreInfo.lineThickness.toDouble(),
284+
min: 1,
285+
max: 5,
286+
divisions: 4,
287+
onChanged: (double value) => setState(() {
288+
widget.setLineThickness(value.toInt());
289+
}),
290+
),
291+
),
292+
],
293+
),
266294
const SizedBox(height: 16),
267295
Text(
268296
t.editor.menu.import,

lib/data/editor/editor_core_info.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class EditorCoreInfo {
6161
Color? backgroundColor;
6262
CanvasBackgroundPattern backgroundPattern;
6363
int lineHeight;
64+
int lineThickness;
6465
List<EditorPage> pages;
6566

6667
/// Stores the current page index so that it can be restored when the file is reloaded.
@@ -74,6 +75,7 @@ class EditorCoreInfo {
7475
backgroundColor: null,
7576
backgroundPattern: CanvasBackgroundPattern.none,
7677
lineHeight: Prefs.lastLineHeight.value,
78+
lineThickness: Prefs.lastLineThickness.value,
7779
pages: [],
7880
initialPageIndex: null,
7981
assetCache: null,
@@ -95,6 +97,7 @@ class EditorCoreInfo {
9597
}) : nextImageId = 0,
9698
backgroundPattern = Prefs.lastBackgroundPattern.value,
9799
lineHeight = Prefs.lastLineHeight.value,
100+
lineThickness = Prefs.lastLineThickness.value,
98101
pages = [],
99102
assetCache = AssetCache();
100103

@@ -106,6 +109,7 @@ class EditorCoreInfo {
106109
this.backgroundColor,
107110
required this.backgroundPattern,
108111
required this.lineHeight,
112+
required this.lineThickness,
109113
required this.pages,
110114
required this.initialPageIndex,
111115
required AssetCache? assetCache,
@@ -168,6 +172,7 @@ class EditorCoreInfo {
168172
return CanvasBackgroundPattern.none;
169173
}(),
170174
lineHeight: json['l'] as int? ?? Prefs.lastLineHeight.value,
175+
lineThickness: json['lt'] as int? ?? Prefs.lastLineThickness.value,
171176
pages: _parsePagesJson(
172177
json['z'] as List?,
173178
inlineAssets: inlineAssets,
@@ -202,6 +207,7 @@ class EditorCoreInfo {
202207
}) : nextImageId = 0,
203208
backgroundPattern = CanvasBackgroundPattern.none,
204209
lineHeight = Prefs.lastLineHeight.value,
210+
lineThickness = Prefs.lastLineThickness.value,
205211
pages = [],
206212
assetCache = AssetCache() {
207213
_migrateOldStrokesAndImages(
@@ -468,6 +474,7 @@ class EditorCoreInfo {
468474
'b': backgroundColor?.toARGB32(),
469475
'p': backgroundPattern.name,
470476
'l': lineHeight,
477+
'lt': lineThickness,
471478
'z': pages.map((EditorPage page) => page.toJson(assets)).toList(),
472479
'c': initialPageIndex,
473480
};
@@ -536,6 +543,7 @@ class EditorCoreInfo {
536543
Color? backgroundColor,
537544
CanvasBackgroundPattern? backgroundPattern,
538545
int? lineHeight,
546+
int? lineThickness,
539547
QuillController? quillController,
540548
List<EditorPage>? pages,
541549
}) {
@@ -548,6 +556,7 @@ class EditorCoreInfo {
548556
backgroundColor: backgroundColor ?? this.backgroundColor,
549557
backgroundPattern: backgroundPattern ?? this.backgroundPattern,
550558
lineHeight: lineHeight ?? this.lineHeight,
559+
lineThickness: lineThickness ?? this.lineThickness,
551560
pages: pages ?? this.pages,
552561
initialPageIndex: initialPageIndex,
553562
assetCache: assetCache,

lib/data/prefs.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ abstract class Prefs {
119119
lastShapePenColor;
120120
static late final PlainPref<CanvasBackgroundPattern> lastBackgroundPattern;
121121
static late final PlainPref<int> lastLineHeight;
122+
static late final PlainPref<int> lastLineThickness;
122123
static late final PlainPref<bool> lastZoomLock,
123124
lastSingleFingerPanLock,
124125
lastAxisAlignedPanLock;
@@ -247,6 +248,7 @@ abstract class Prefs {
247248
lastBackgroundPattern =
248249
PlainPref('lastBackgroundPattern', CanvasBackgroundPattern.none);
249250
lastLineHeight = PlainPref('lastLineHeight', 40);
251+
lastLineThickness = PlainPref('lastLineThickness', 3);
250252
lastZoomLock = PlainPref('lastZoomLock', false);
251253
lastSingleFingerPanLock = PlainPref('lastSingleFingerPanLock', false,
252254
historicalKeys: const ['lastPanLock']);

lib/i18n/strings.i18n.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ editor:
300300
deletePage: Delete page
301301
lineHeight: Line height
302302
lineHeightDescription: Also controls the text size for typed notes
303+
lineThickness: Line thickness
304+
lineThicknessDescription: Background line thickness
303305
backgroundImageFit: Background image fit
304306
backgroundPattern: Background pattern
305307
import: Import

lib/i18n/strings_en.g.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ class TranslationsEditorMenuEn {
710710
String get deletePage => 'Delete page';
711711
String get lineHeight => 'Line height';
712712
String get lineHeightDescription => 'Also controls the text size for typed notes';
713+
String get lineThickness => 'Line thickness';
714+
String get lineThicknessDescription => 'Background line thickness';
713715
String get backgroundImageFit => 'Background image fit';
714716
String get backgroundPattern => 'Background pattern';
715717
String get import => 'Import';

lib/pages/editor/editor.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,12 @@ class EditorState extends State<Editor> {
17681768
Prefs.lastLineHeight.value = lineHeight;
17691769
autosaveAfterDelay();
17701770
}),
1771+
setLineThickness: (lineThickness) => setState(() {
1772+
if (coreInfo.readOnly) return;
1773+
coreInfo.lineThickness = lineThickness;
1774+
Prefs.lastLineThickness.value = lineThickness;
1775+
autosaveAfterDelay();
1776+
}),
17711777
removeBackgroundImage: () => setState(() {
17721778
if (coreInfo.readOnly) return;
17731779

0 commit comments

Comments
 (0)