Skip to content

Commit

Permalink
Fix label cursor if not editing element
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 2, 2024
1 parent b9e9d6f commit 01d17ab
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/lib/handlers/eraser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ class EraserHandler extends Handler<EraserTool> {

// 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;
}
2 changes: 1 addition & 1 deletion app/lib/handlers/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -770,5 +770,5 @@ class LabelHandler extends Handler<LabelTool>
}

@override
MouseCursor get cursor => SystemMouseCursors.text;
MouseCursor get cursor => SystemMouseCursors.none;
}
3 changes: 3 additions & 0 deletions app/lib/handlers/path_eraser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ class PathEraserHandler extends Handler<PathEraserTool> {
context.getDocumentBloc().add(ElementsRemoved(_erased.toList()));
}
}

@override
MouseCursor? get cursor => SystemMouseCursors.none;
}
30 changes: 17 additions & 13 deletions app/lib/models/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -108,30 +108,32 @@ 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) {
final index = selection.start;
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();
Expand All @@ -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();
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/lib/renderers/cursors/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class LabelCursor extends Renderer<LabelCursorData> {
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(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/views/toolbar/label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _LabelToolbarViewState extends State<LabelToolbarView> {
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();
Expand Down
2 changes: 2 additions & 0 deletions metadata/en-US/changelogs/121.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 01d17ab

Please sign in to comment.