Bläddra i källkod

Account for textScaleFactor when computing size of widest word in lableText

ashilkn 2 år sedan
förälder
incheckning
344fce0a02

+ 7 - 7
lib/ui/components/bottom_action_bar/selection_action_button_widget.dart

@@ -5,13 +5,11 @@ class SelectionActionButton extends StatefulWidget {
   final String labelText;
   final IconData icon;
   final VoidCallback? onTap;
-  final TextStyle textStyle;
 
   const SelectionActionButton({
     required this.labelText,
     required this.icon,
     required this.onTap,
-    required this.textStyle,
     super.key,
   });
 
@@ -27,13 +25,12 @@ class _SelectionActionButtonState extends State<SelectionActionButton> {
   @override
   void initState() {
     super.initState();
-    widthOfButton = getWidthOfButton();
+    // widthOfButton = getWidthOfButton();
   }
 
   getWidthOfButton() {
     final widthOfWidestWord = getWidthOfLongestWord(
       widget.labelText,
-      widget.textStyle,
     );
     if (widthOfWidestWord > minWidth) return widthOfWidestWord;
     return minWidth;
@@ -41,6 +38,7 @@ class _SelectionActionButtonState extends State<SelectionActionButton> {
 
   @override
   Widget build(BuildContext context) {
+    widthOfButton = getWidthOfButton();
     final colorScheme = getEnteColorScheme(context);
     return GestureDetector(
       onTap: widget.onTap,
@@ -81,7 +79,8 @@ class _SelectionActionButtonState extends State<SelectionActionButton> {
                 Text(
                   widget.labelText,
                   textAlign: TextAlign.center,
-                  style: widget.textStyle,
+                  //textTheme in [getWidthOfLongestWord] should be same as this
+                  style: getEnteTextTheme(context).miniMuted,
                 ),
               ],
             ),
@@ -96,18 +95,19 @@ class _SelectionActionButtonState extends State<SelectionActionButton> {
       text: TextSpan(text: text, style: style),
       maxLines: 1,
       textDirection: TextDirection.ltr,
+      textScaleFactor: MediaQuery.of(context).textScaleFactor,
     )..layout();
 
     return textPainter.size.width;
   }
 
-  double getWidthOfLongestWord(String labelText, TextStyle style) {
+  double getWidthOfLongestWord(String labelText) {
     final words = labelText.split(RegExp(r'\s+'));
     if (words.isEmpty) return 0.0;
 
     double maxWidth = 0.0;
     for (String word in words) {
-      final width = getWidthOfText(word, style);
+      final width = getWidthOfText(word, getEnteTextTheme(context).miniMuted);
       if (width > maxWidth) {
         maxWidth = width;
       }

+ 0 - 17
lib/ui/viewer/actions/file_selection_actions_widget.dart

@@ -13,7 +13,6 @@ import "package:photos/models/metadata/common_keys.dart";
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/hidden_service.dart';
-import "package:photos/theme/ente_theme.dart";
 import 'package:photos/ui/actions/collection/collection_file_actions.dart';
 import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
 import 'package:photos/ui/collections/collection_action_sheet.dart';
@@ -88,7 +87,6 @@ class _FileSelectionActionsWidgetState
 
   @override
   Widget build(BuildContext context) {
-    final labelTextStyle = getEnteTextTheme(context).miniMuted;
     final bool showPrefix =
         split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty;
     final String suffix = showPrefix
@@ -120,7 +118,6 @@ class _FileSelectionActionsWidgetState
             icon: Icons.copy_outlined,
             labelText: S.of(context).copyLink,
             onTap: anyUploadedFiles ? _copyLink : null,
-            textStyle: labelTextStyle,
           ),
         );
       } else {
@@ -129,7 +126,6 @@ class _FileSelectionActionsWidgetState
             icon: Icons.link_outlined,
             labelText: S.of(context).shareLink + suffix,
             onTap: anyUploadedFiles ? _onCreatedSharedLinkClicked : null,
-            textStyle: labelTextStyle,
           ),
         );
       }
@@ -152,7 +148,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.grid_view_outlined,
           labelText: S.of(context).createCollage,
           onTap: _onCreateCollageClicked,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -168,7 +163,6 @@ class _FileSelectionActionsWidgetState
               ? S.of(context).addToEnte
               : S.of(context).addToAlbum + suffixInPending,
           onTap: anyOwnedFiles ? _addToAlbum : null,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -178,7 +172,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.arrow_forward_outlined,
           labelText: S.of(context).moveToAlbum + suffix,
           onTap: anyUploadedFiles ? _moveFiles : null,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -189,7 +182,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.remove_outlined,
           labelText: "${S.of(context).removeFromAlbum}$removeSuffix",
           onTap: removeCount > 0 ? _removeFilesFromAlbum : null,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -200,7 +192,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.delete_outline,
           labelText: S.of(context).delete + suffixInPending,
           onTap: anyOwnedFiles ? _onDeleteClick : null,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -211,7 +202,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.visibility_off_outlined,
           labelText: S.of(context).hide + suffix,
           onTap: anyUploadedFiles ? _onHideClick : null,
-          textStyle: labelTextStyle,
         ),
       );
     } else if (widget.type.showUnHideOption()) {
@@ -220,7 +210,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.visibility_off_outlined,
           labelText: S.of(context).unhide + suffix,
           onTap: _onUnhideClick,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -230,7 +219,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.archive_outlined,
           labelText: S.of(context).archive + suffix,
           onTap: anyUploadedFiles ? _onArchiveClick : null,
-          textStyle: labelTextStyle,
         ),
       );
     } else if (widget.type.showUnArchiveOption()) {
@@ -239,7 +227,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.unarchive,
           labelText: S.of(context).unarchive + suffix,
           onTap: _onUnArchiveClick,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -250,7 +237,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.favorite_border_rounded,
           labelText: S.of(context).favorite + suffix,
           onTap: anyUploadedFiles ? _onFavoriteClick : null,
-          textStyle: labelTextStyle,
         ),
       );
     } else if (widget.type.showUnFavoriteOption()) {
@@ -259,7 +245,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.favorite,
           labelText: S.of(context).removeFromFavorite + suffix,
           onTap: _onUnFavoriteClick,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -270,7 +255,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.restore_outlined,
           labelText: S.of(context).restore,
           onTap: _restore,
-          textStyle: labelTextStyle,
         ),
       );
     }
@@ -281,7 +265,6 @@ class _FileSelectionActionsWidgetState
           icon: Icons.delete_forever_outlined,
           labelText: S.of(context).permanentlyDelete,
           onTap: _permanentlyDelete,
-          textStyle: labelTextStyle,
         ),
       );
     }