diff --git a/api/lib/src/models/tool.dart b/api/lib/src/models/tool.dart index b7c4875ebf25..c6116175fb82 100644 --- a/api/lib/src/models/tool.dart +++ b/api/lib/src/models/tool.dart @@ -196,6 +196,7 @@ sealed class Tool with _$Tool { @Default('') String name, @Default('') String displayIcon, @ColorJsonConverter() SRGBColor? color, + @Default(100) int size, }) = RulerTool; factory Tool.grid({ diff --git a/api/lib/src/models/tool.freezed.dart b/api/lib/src/models/tool.freezed.dart index b7f09f735a68..e34fc9f55cea 100644 --- a/api/lib/src/models/tool.freezed.dart +++ b/api/lib/src/models/tool.freezed.dart @@ -2799,7 +2799,8 @@ abstract class _$$RulerToolImplCopyWith<$Res> implements $ToolCopyWith<$Res> { $Res call( {String name, String displayIcon, - @ColorJsonConverter() SRGBColor? color}); + @ColorJsonConverter() SRGBColor? color, + int size}); } /// @nodoc @@ -2818,6 +2819,7 @@ class __$$RulerToolImplCopyWithImpl<$Res> Object? name = null, Object? displayIcon = null, Object? color = freezed, + Object? size = null, }) { return _then(_$RulerToolImpl( name: null == name @@ -2832,6 +2834,10 @@ class __$$RulerToolImplCopyWithImpl<$Res> ? _value.color : color // ignore: cast_nullable_to_non_nullable as SRGBColor?, + size: null == size + ? _value.size + : size // ignore: cast_nullable_to_non_nullable + as int, )); } } @@ -2843,6 +2849,7 @@ class _$RulerToolImpl extends RulerTool { {this.name = '', this.displayIcon = '', @ColorJsonConverter() this.color, + this.size = 100, final String? $type}) : $type = $type ?? 'ruler', super._(); @@ -2859,13 +2866,16 @@ class _$RulerToolImpl extends RulerTool { @override @ColorJsonConverter() final SRGBColor? color; + @override + @JsonKey() + final int size; @JsonKey(name: 'type') final String $type; @override String toString() { - return 'Tool.ruler(name: $name, displayIcon: $displayIcon, color: $color)'; + return 'Tool.ruler(name: $name, displayIcon: $displayIcon, color: $color, size: $size)'; } /// Create a copy of Tool @@ -2888,7 +2898,8 @@ abstract class RulerTool extends Tool { factory RulerTool( {final String name, final String displayIcon, - @ColorJsonConverter() final SRGBColor? color}) = _$RulerToolImpl; + @ColorJsonConverter() final SRGBColor? color, + final int size}) = _$RulerToolImpl; RulerTool._() : super._(); factory RulerTool.fromJson(Map json) = @@ -2900,6 +2911,7 @@ abstract class RulerTool extends Tool { String get displayIcon; @ColorJsonConverter() SRGBColor? get color; + int get size; /// Create a copy of Tool /// with the given fields replaced by the non-null parameter values. diff --git a/api/lib/src/models/tool.g.dart b/api/lib/src/models/tool.g.dart index d8aca3cbe3fc..d53ab1358406 100644 --- a/api/lib/src/models/tool.g.dart +++ b/api/lib/src/models/tool.g.dart @@ -430,6 +430,7 @@ _$RulerToolImpl _$$RulerToolImplFromJson(Map json) => _$RulerToolImpl( displayIcon: json['displayIcon'] as String? ?? '', color: _$JsonConverterFromJson( json['color'], const ColorJsonConverter().fromJson), + size: (json['size'] as num?)?.toInt() ?? 100, $type: json['type'] as String?, ); @@ -439,6 +440,7 @@ Map _$$RulerToolImplToJson(_$RulerToolImpl instance) => 'displayIcon': instance.displayIcon, 'color': _$JsonConverterToJson( instance.color, const ColorJsonConverter().toJson), + 'size': instance.size, 'type': instance.$type, }; diff --git a/app/lib/handlers/ruler.dart b/app/lib/handlers/ruler.dart index 2021b1fdc747..898a31aff150 100644 --- a/app/lib/handlers/ruler.dart +++ b/app/lib/handlers/ruler.dart @@ -1,14 +1,13 @@ part of 'handler.dart'; -Rect _getRulerRect(Size size, Offset position, +Rect _getRulerRect(RulerTool ruler, Size size, Offset position, [CameraTransform transform = const CameraTransform()]) { - const rulerSize = 100.0; return Rect.fromLTWH( transform.position.dx + position.dx / transform.size, transform.position.dy + - (size.height / 2 + -rulerSize / 2 + position.dy) / transform.size, + (size.height / 2 + -ruler.size / 2 + position.dy) / transform.size, size.width * 2 / transform.size, - rulerSize / transform.size, + ruler.size / transform.size, ); } @@ -50,7 +49,7 @@ class RulerHandler extends Handler with PointerManipulationHandler { Rect getRect(Size size, [CameraTransform transform = const CameraTransform()]) { - return _getRulerRect(size, _position, transform); + return _getRulerRect(data, size, _position, transform); } bool isPointerInside(Offset position, Size viewportSize) { @@ -111,7 +110,7 @@ class RulerRenderer extends Renderer { canvas.save(); canvas.translate(transform.position.dx, transform.position.dy); canvas.scale(1 / transform.size, 1 / transform.size); - var rulerRect = _getRulerRect(size, position); + var rulerRect = _getRulerRect(element, size, position); final rulerCenter = rulerRect.center; canvas.translate(rulerCenter.dx, rulerCenter.dy); canvas.rotate(rulerRotation * pi / 180); diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index fdfd0819fb25..3c4397a1db5d 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -636,5 +636,5 @@ "confirmPassword": "Confirm password", "passwordMismatch": "The passwords do not match", "action": "Action", - "svgText": "SVG text" + "svgText": "SVG Text" } diff --git a/app/lib/selections/tools/ruler.dart b/app/lib/selections/tools/ruler.dart index dab240fac245..f56b46fe5751 100644 --- a/app/lib/selections/tools/ruler.dart +++ b/app/lib/selections/tools/ruler.dart @@ -28,6 +28,18 @@ class RulerToolSelection extends ToolSelection { selected.map((e) => e.copyWith(color: value)).toList(), ), ), + ExactSlider( + header: Text(AppLocalizations.of(context).size), + value: selected.first.size.toDouble(), + min: 1, + max: 500, + defaultValue: 100, + fractionDigits: 0, + onChangeEnd: (value) => update( + context, + selected.map((e) => e.copyWith(size: value.toInt())).toList(), + ), + ) ]; }