From 01d17ab9be179ab67f25b2bfdf97842fd205a455 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Sat, 2 Nov 2024 19:38:32 +0100 Subject: [PATCH] Fix label cursor if not editing element --- app/lib/handlers/eraser.dart | 2 +- app/lib/handlers/label.dart | 2 +- app/lib/handlers/path_eraser.dart | 3 +++ app/lib/models/label.dart | 30 ++++++++++++++++------------ app/lib/renderers/cursors/label.dart | 12 +++++------ app/lib/views/toolbar/label.dart | 2 +- metadata/en-US/changelogs/121.txt | 2 ++ 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/app/lib/handlers/eraser.dart b/app/lib/handlers/eraser.dart index 92ff8f54d7e8..4aa2617df7bc 100644 --- a/app/lib/handlers/eraser.dart +++ b/app/lib/handlers/eraser.dart @@ -100,5 +100,5 @@ class EraserHandler extends Handler { // Returns the mouse cursor to be used when the user interacts with the eraser tool. @override - MouseCursor get cursor => SystemMouseCursors.precise; + MouseCursor get cursor => SystemMouseCursors.none; } diff --git a/app/lib/handlers/label.dart b/app/lib/handlers/label.dart index 18c712584746..dff553db8ade 100644 --- a/app/lib/handlers/label.dart +++ b/app/lib/handlers/label.dart @@ -770,5 +770,5 @@ class LabelHandler extends Handler } @override - MouseCursor get cursor => SystemMouseCursors.text; + MouseCursor get cursor => SystemMouseCursors.none; } diff --git a/app/lib/handlers/path_eraser.dart b/app/lib/handlers/path_eraser.dart index a712307e3a02..a0c25de78ec6 100644 --- a/app/lib/handlers/path_eraser.dart +++ b/app/lib/handlers/path_eraser.dart @@ -73,4 +73,7 @@ class PathEraserHandler extends Handler { context.getDocumentBloc().add(ElementsRemoved(_erased.toList())); } } + + @override + MouseCursor? get cursor => SystemMouseCursors.none; } diff --git a/app/lib/models/label.dart b/app/lib/models/label.dart index 405227ca86a4..949775319f92 100644 --- a/app/lib/models/label.dart +++ b/app/lib/models/label.dart @@ -36,8 +36,8 @@ sealed class LabelContext with _$LabelContext { LabelElement? get labelElement => element as LabelElement?; - PackAssetLocation get styleSheet => - labelElement?.styleSheet ?? tool.styleSheet; + PackAssetLocation getStyleSheet(NoteData document) => + labelElement?.styleSheet ?? tool.styleSheet.fixStyle(document); int get length => switch (this) { @@ -108,14 +108,15 @@ extension TextContextHelper on TextContext { const ParagraphProperty.undefined(); } - DefinedParagraphProperty? getDefinedProperty(NoteData document) { + DefinedParagraphProperty getDefinedProperty(NoteData document) { final property = getProperty(); if (property is DefinedParagraphProperty) { return property; } - return styleSheet - .resolveStyle(document) - ?.resolveParagraphProperty(property); + return getStyleSheet(document) + .resolveStyle(document) + ?.resolveParagraphProperty(property) ?? + DefinedParagraphProperty(); } SpanProperty? getSpanProperty(NoteData document) { @@ -123,15 +124,16 @@ extension TextContextHelper on TextContext { return switch (paragraph?.getSpan(index)?.property) { DefinedSpanProperty e => e, NamedSpanProperty e => e, - _ => getDefinedProperty(document)?.span, + _ => getDefinedProperty(document).span, }; } DefinedSpanProperty getDefinedSpanProperty(NoteData document) { return switch (getSpanProperty(document)) { DefinedSpanProperty e => e, - NamedSpanProperty e => - styleSheet.resolveStyle(document)?.resolveSpanProperty(e), + NamedSpanProperty e => getStyleSheet(document) + .resolveStyle(document) + ?.resolveSpanProperty(e), _ => null, } ?? const DefinedSpanProperty(); @@ -140,8 +142,9 @@ extension TextContextHelper on TextContext { DefinedParagraphProperty getDefinedForcedProperty(NoteData document) { return switch (forcedProperty) { DefinedParagraphProperty e => e, - NamedParagraphProperty e => - styleSheet.resolveStyle(document)?.resolveParagraphProperty(e), + NamedParagraphProperty e => getStyleSheet(document) + .resolveStyle(document) + ?.resolveParagraphProperty(e), _ => null, } ?? const DefinedParagraphProperty(); @@ -151,8 +154,9 @@ extension TextContextHelper on TextContext { [bool fallback = true]) { return switch (forcedSpanProperty) { DefinedSpanProperty e => e, - NamedSpanProperty e => - styleSheet.resolveStyle(document)?.resolveSpanProperty(e), + NamedSpanProperty e => getStyleSheet(document) + .resolveStyle(document) + ?.resolveSpanProperty(e), _ => null, } ?? (fallback diff --git a/app/lib/renderers/cursors/label.dart b/app/lib/renderers/cursors/label.dart index 00ea6ed5ae2f..7710a08ee8cb 100644 --- a/app/lib/renderers/cursors/label.dart +++ b/app/lib/renderers/cursors/label.dart @@ -25,13 +25,13 @@ class LabelCursor extends Renderer { const icon = PhosphorIconsLight.cursorText; final property = switch (element.context) { TextContext e => e.getDefinedProperty(document), - _ => null + _ => const text.DefinedParagraphProperty(), }; - final iconSize = - (property ?? const text.DefinedParagraphProperty()).span.getSize() * - (element.context?.labelElement?.scale ?? - (element.tool.zoomDependent ? 1 / transform.size : 1)); - final iconColor = Color(property?.span.color ?? + final iconSize = property.span.getSize() * + (element.context?.labelElement?.scale ?? + (element.tool.scale * + (element.tool.zoomDependent ? 1 / transform.size : 1))); + final iconColor = Color(property.span.color ?? colorScheme?.primary.value ?? Colors.black.value); final iconPainter = TextPainter( diff --git a/app/lib/views/toolbar/label.dart b/app/lib/views/toolbar/label.dart index 3b2d46b332ea..c3ba9034b3bd 100644 --- a/app/lib/views/toolbar/label.dart +++ b/app/lib/views/toolbar/label.dart @@ -99,7 +99,7 @@ class _LabelToolbarViewState extends State { TextContext e => e.getDefinedForcedSpanProperty(document), _ => null }; - final styleSheet = value.styleSheet; + final styleSheet = value.getStyleSheet(document); final style = styleSheet.resolveStyle(document); _scaleController.text = (value.labelElement?.scale ?? value.tool.scale).toString(); diff --git a/metadata/en-US/changelogs/121.txt b/metadata/en-US/changelogs/121.txt index 323c8a2a6156..c7148873f3e9 100644 --- a/metadata/en-US/changelogs/121.txt +++ b/metadata/en-US/changelogs/121.txt @@ -4,6 +4,8 @@ * Improve performance on large pages ([#667](https://github.com/LinwoodDev/Butterfly/issues/667) partially) * Improve property view * Fix changing page don't showing content ([#755](https://github.com/LinwoodDev/Butterfly/issues/755)) +* Fix label cursor if not editing element +* Remove cusor visibility on eraser, path eraser and label tool * Remove label tool can be changed tool to allow context menu Read more here: https://linwood.dev/butterfly/2.2.2-rc.1 \ No newline at end of file