From c34fc35c7ec1168eb36e590ebabdcdf99a3aec55 Mon Sep 17 00:00:00 2001 From: hm21 Date: Thu, 4 Jan 2024 10:33:32 +0100 Subject: [PATCH] Refactor computeLuminance in text_editor, improve hitbox for textlayer in layer_widget, and add keyboard shortcuts to pro_image_editor_main - Enhanced computeLuminance function in text_editor for better performance - Improved hitbox detection for text layers in layer_widget - Extended pro_image_editor_main with additional keyboard shortcuts for increased usability --- example/.flutter-plugins-dependencies | 2 +- lib/modules/text_editor.dart | 5 +-- lib/pro_image_editor_main.dart | 61 ++++++++++++++++++++++++--- lib/widgets/layer_widget.dart | 35 +++++++++++---- 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 7bd91736..b97c3591 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":true,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"file_picker","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-6.1.1\\\\","native_build":true,"dependencies":[]},{"name":"image_editor_common","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\image_editor_common-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.3.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"vibration","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\vibration-1.8.4\\\\","native_build":true,"dependencies":["device_info_plus"]}],"android":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":true,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"file_picker","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-6.1.1\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_plugin_android_lifecycle-2.0.17\\\\","native_build":true,"dependencies":[]},{"name":"image_editor_common","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\image_editor_common-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.2\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.2.1\\\\","native_build":true,"dependencies":[]},{"name":"vibration","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\vibration-1.8.4\\\\","native_build":true,"dependencies":["device_info_plus"]}],"macos":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":true,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"image_editor_common","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\image_editor_common-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.3.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":false,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.3.2\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":false,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.3.2\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","dependencies":[]},{"name":"file_picker","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-6.1.1\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.2.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"emoji_picker_flutter","dependencies":["shared_preferences"]},{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_editor","dependencies":["image_editor_common"]},{"name":"image_editor_common","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"vibration","dependencies":["device_info_plus"]}],"date_created":"2024-01-03 20:35:27.626990","version":"3.16.5"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":true,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"file_picker","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-6.1.1\\\\","native_build":true,"dependencies":[]},{"name":"image_editor_common","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\image_editor_common-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.3.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"vibration","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\vibration-1.8.4\\\\","native_build":true,"dependencies":["device_info_plus"]}],"android":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":true,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"file_picker","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-6.1.1\\\\","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_plugin_android_lifecycle-2.0.17\\\\","native_build":true,"dependencies":[]},{"name":"image_editor_common","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\image_editor_common-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.2\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.2.1\\\\","native_build":true,"dependencies":[]},{"name":"vibration","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\vibration-1.8.4\\\\","native_build":true,"dependencies":["device_info_plus"]}],"macos":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":true,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"image_editor_common","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\image_editor_common-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.3.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":false,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.3.2\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","native_build":false,"dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.3.2\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.1.1\\\\","dependencies":[]},{"name":"emoji_picker_flutter","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\emoji_picker_flutter-1.6.3\\\\","dependencies":[]},{"name":"file_picker","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\file_picker-6.1.1\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\Users\\\\AlexF\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.2.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"emoji_picker_flutter","dependencies":["shared_preferences"]},{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_editor","dependencies":["image_editor_common"]},{"name":"image_editor_common","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"vibration","dependencies":["device_info_plus"]}],"date_created":"2024-01-04 09:54:25.029279","version":"3.16.5"} \ No newline at end of file diff --git a/lib/modules/text_editor.dart b/lib/modules/text_editor.dart index 0e10d5fd..7fb7f5a5 100644 --- a/lib/modules/text_editor.dart +++ b/lib/modules/text_editor.dart @@ -116,10 +116,7 @@ class TextEditorState extends State { /// Calculates the contrast color for a given color. Color _getContrastColor(Color color) { - int d = 0; - double luminance = (0.299 * color.red + 0.587 * color.green + 0.114 * color.blue) / 255; - - d = luminance > 0.65 ? 0 : 255; + int d = color.computeLuminance() > 0.5 ? 0 : 255; return Color.fromARGB(color.alpha, d, d, d); } diff --git a/lib/pro_image_editor_main.dart b/lib/pro_image_editor_main.dart index c8bdee8d..7e88d416 100644 --- a/lib/pro_image_editor_main.dart +++ b/lib/pro_image_editor_main.dart @@ -424,14 +424,35 @@ class ProImageEditorState extends State { final key = event.logicalKey.keyLabel; if (mounted && event is KeyDownEvent) { - if (key == 'Escape') { - if (!_activeCrop && !_openDialog) { - if (_openEditor) { - Navigator.pop(context); - } else { - closeEditor(); + switch (key) { + case 'Escape': + if (!_activeCrop && !_openDialog) { + if (_openEditor) { + Navigator.pop(context); + } else { + closeEditor(); + } } - } + break; + + case 'Subtract': + case 'Numpad Subtract': + case 'Page Down': + case 'Arrow Down': + _keyboardZoom(true); + break; + case 'Add': + case 'Numpad Add': + case 'Page Up': + case 'Arrow Up': + _keyboardZoom(false); + break; + case 'Arrow Left': + _keyboardRotate(true); + break; + case 'Arrow Right': + _keyboardRotate(false); + break; } } @@ -1385,6 +1406,32 @@ class ProImageEditorState extends State { _openDialog = false; } + /// Handles Keyboard zoom event + void _keyboardRotate(bool left) { + if (left) { + _activeLayer.rotation -= 0.087266; + } else { + _activeLayer.rotation += 0.087266; + } + setState(() {}); + } + + /// Handles Keyboard zoom event + void _keyboardZoom(bool zoomIn) { + double factor = _activeLayer is PaintingLayerData + ? 0.1 + : _activeLayer is TextLayerData + ? 0.15 + : widget.configs.textEditorConfigs.initFontSize / 50; + if (zoomIn) { + _activeLayer.scale -= factor; + _activeLayer.scale = max(0.1, _activeLayer.scale); + } else { + _activeLayer.scale += factor; + } + setState(() {}); + } + /// Handles mouse scroll events. void _mouseScroll(PointerSignalEvent event) { bool shiftDown = RawKeyboard.instance.keysPressed.contains(LogicalKeyboardKey.shiftLeft) || diff --git a/lib/widgets/layer_widget.dart b/lib/widgets/layer_widget.dart index bfbaddd3..9ade729c 100644 --- a/lib/widgets/layer_widget.dart +++ b/lib/widgets/layer_widget.dart @@ -256,26 +256,43 @@ class _LayerWidgetState extends State { } } + double getLineHeight(TextStyle style) { + final span = TextSpan(text: 'X', style: style); + final painter = TextPainter( + text: span, + textAlign: TextAlign.left, + textDirection: TextDirection.ltr, + ); + + painter.layout(); + return painter.preferredLineHeight; + } + /// Build the text widget Widget _buildText() { + var fontSize = widget.textFontSize * _layer.scale; var layer = _layer as TextLayerData; - double horizontalHelper = 10 * layer.scale; + var style = TextStyle( + fontSize: fontSize, + fontWeight: FontWeight.w400, + color: layer.color, + ); + + double height = getLineHeight(style); + const horizontalPaddingFactor = 0.3; + return Container( // Fix Hit-Box padding: EdgeInsets.only( - left: horizontalHelper, - right: horizontalHelper, - bottom: widget.textFontSize * 1.3 * 0.175 * layer.scale, + left: height * horizontalPaddingFactor, + right: height * horizontalPaddingFactor, + bottom: height * 0.175 / 2, ), child: RoundedBackgroundText( layer.text.toString(), backgroundColor: layer.background, textAlign: layer.align, - style: TextStyle( - fontSize: widget.textFontSize * _layer.scale, - fontWeight: FontWeight.w400, - color: layer.color, - ), + style: style, ), ); }