Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Add text editing to the image editor

r4khulf080f6770402
diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_main_bottom_bar.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_main_bottom_bar.dart
index f39a6afb10..192fc5cbdc 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_main_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_main_bottom_bar.dart
@@ -113,6 +113,13 @@ class ImageEditorMainBottomBarState extends State<ImageEditorMainBottomBar>
widget.editor.openPaintEditor();
},
),
+ CircularIconButton(
+ hugeIcon: HugeIcons.strokeRoundedText,
+ label: context.strings.imageEditorText,
+ onTap: () {
+ widget.editor.openTextEditor();
+ },
+ ),
CircularIconButton(
hugeIcon: HugeIcons.strokeRoundedSticker,
label: context.strings.sticker,
diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
index a825f17572..0220f5fa6d 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart
@@ -59,6 +59,7 @@ class ImageEditorPage extends StatefulWidget {
class _ImageEditorPageState extends State<ImageEditorPage> {
final _mainEditorBarKey = GlobalKey<ImageEditorMainBottomBarState>();
final editorKey = GlobalKey<ProImageEditorState>();
+ SubEditor? _activeSubEditor;
final _logger = Logger("ImageEditor");
Future<Uint8List> compressImage(Uint8List bytes) async {
@@ -244,6 +245,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
_showExitConfirmationDialog(context);
},
mainEditorCallbacks: MainEditorCallbacks(
+ onOpenSubEditor: (editor) => _activeSubEditor = editor,
onStartCloseSubEditor: (value) {
_mainEditorBarKey.currentState?.setState(() {});
},
@@ -254,6 +256,14 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
),
configs: ProImageEditorConfigs(
i18n: I18n(
+ textEditor: I18nTextEditor(
+ inputHintText: context.strings.imageEditorEnterText,
+ bottomNavigationBarText: context.strings.imageEditorText,
+ back: context.strings.cancel,
+ done: context.strings.done,
+ textAlign: context.strings.align,
+ backgroundMode: context.strings.background,
+ ),
tuneEditor: I18nTuneEditor(
brightness: context.strings.imageEditorBrightness,
contrast: context.strings.imageEditorContrast,
@@ -294,9 +304,13 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
SubEditorMode.filter,
SubEditorMode.tune,
SubEditorMode.paint,
+ SubEditorMode.text,
SubEditorMode.emoji,
],
style: MainEditorStyle(
+ subEditorPage: imageEditorSubEditorPageStyle(
+ () => _activeSubEditor,
+ ),
uiOverlayStyle: SystemUiOverlayStyle(
systemNavigationBarContrastEnforced: true,
systemNavigationBarColor: Colors.transparent,
@@ -439,56 +453,7 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
},
),
),
- textEditor: TextEditorConfigs(
- showBackgroundModeButton: true,
- showTextAlignButton: true,
- style: const TextEditorStyle(
- background: Colors.transparent,
- textFieldMargin: EdgeInsets.only(top: kToolbarHeight),
- ),
- widgets: TextEditorWidgets(
- appBar: (textEditor, rebuildStream) => ReactiveAppbar(
- builder: (context) {
- return ImageEditorAppBar(
- key: const Key('image_editor_app_bar'),
- configs: textEditor.configs,
- done: () => textEditor.done(),
- close: () => textEditor.close(),
- );
- },
- stream: rebuildStream,
- ),
- bodyItems: (editor, rebuildStream) {
- return [
- ReactiveWidget(
- builder: (context) {
- return Positioned.fill(
- child: GestureDetector(
- onTap: () {},
- child: Container(color: Colors.transparent),
- ),
- );
- },
- stream: rebuildStream,
- ),
- ];
- },
- colorPicker:
- (textEditor, rebuildStream, currentColor, setColor) => null,
- bottomBar: (editorState, rebuildStream) {
- return ReactiveWidget(
- builder: (context) {
- return ImageEditorTextBar(
- configs: editorState.configs,
- callbacks: editorState.callbacks,
- editor: editorState,
- );
- },
- stream: rebuildStream,
- );
- },
- ),
- ),
+ textEditor: imageEditorTextConfigs(context),
cropRotateEditor: CropRotateEditorConfigs(
style: CropRotateEditorStyle(
background: colors.backgroundBase,
diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart
index fde18279a4..30bcdf6ab2 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_text_bar.dart
@@ -1,360 +1,448 @@
+import "dart:math";
+
import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
-import 'package:flutter/material.dart';
+import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:photos/ui/tools/editor/image_editor/circular_icon_button.dart";
+import "package:photos/ui/tools/editor/image_editor/image_editor_app_bar.dart";
import "package:photos/ui/tools/editor/image_editor/image_editor_color_picker.dart";
-import "package:photos/ui/tools/editor/image_editor/image_editor_configs_mixin.dart";
import "package:photos/ui/tools/editor/image_editor/image_editor_constants.dart";
-import 'package:pro_image_editor/core/mixins/converted_configs.dart';
-import 'package:pro_image_editor/pro_image_editor.dart';
+import "package:pro_image_editor/core/models/styles/sub_editor_page_style.dart";
+import "package:pro_image_editor/pro_image_editor.dart";
-class ImageEditorTextBar extends StatefulWidget with SimpleConfigsAccess {
- const ImageEditorTextBar({
- super.key,
- required this.configs,
- required this.callbacks,
- required this.editor,
- });
+SubEditorPageStyle imageEditorSubEditorPageStyle(
+ ValueGetter<SubEditor?> activeEditor,
+) {
+ return SubEditorPageStyle(
+ transitionsBuilder: (context, animation, secondaryAnimation, child) =>
+ FadeTransition(
+ opacity: animation,
+ child: activeEditor() == SubEditor.text
+ ? MediaQuery.withNoTextScaling(child: child)
+ : child,
+ ),
+ );
+}
- final TextEditorState editor;
+TextEditorConfigs imageEditorTextConfigs(BuildContext context) {
+ final colors = context.componentColors;
+ final textScaler = MediaQuery.textScalerOf(context);
+ return TextEditorConfigs(
+ enableTapOutsideToSave: false,
+ initialPrimaryColor: Colors.white,
+ initialSecondaryColor: Colors.black,
+ initialBackgroundColorMode: LayerBackgroundMode.backgroundAndColor,
+ customTextStyles: const [
+ TextStyle(
+ fontFamily:
+ "packages/${TextStyles.fontPackage}/${TextStyles.fontFamily}",
+ ),
+ TextStyle(
+ fontFamily:
+ "packages/${TextStyles.fontPackage}/${TextStyles.outfitFontFamily}",
+ fontWeight: FontWeight.w600,
+ ),
+ TextStyle(fontFamily: "packages/${TextStyles.fontPackage}/Gochi Hand"),
+ ],
+ style: TextEditorStyle(
+ background: colors.specialScrim,
+ inputCursorColor: colors.primary,
+ inputHintColor: Colors.white70,
+ textFieldMargin: EdgeInsets.zero,
+ ),
+ widgets: TextEditorWidgets(
+ appBar: (editor, rebuildStream) => ReactiveAppbar(
+ stream: rebuildStream,
+ builder: (context) => PreferredSize(
+ preferredSize: const Size.fromHeight(kToolbarHeight),
+ child: MediaQuery(
+ data: MediaQuery.of(context).copyWith(textScaler: textScaler),
+ child: ImageEditorAppBar(
+ configs: editor.configs,
+ done: editor.done,
+ close: editor.close,
+ ),
+ ),
+ ),
+ ),
+ colorPicker: (_, _, _, _) => null,
+ bottomBar: (editor, rebuildStream) => ReactiveWidget(
+ stream: rebuildStream,
+ builder: (context) => MediaQuery(
+ data: MediaQuery.of(context).copyWith(textScaler: textScaler),
+ child: ImageEditorTextBar(editor: editor),
+ ),
+ ),
+ ),
+ );
+}
- @override
- final ProImageEditorConfigs configs;
- @override
- final ProImageEditorCallbacks callbacks;
+enum _TextAction { color, font, background, align }
+
+class ImageEditorTextBar extends StatefulWidget {
+ const ImageEditorTextBar({super.key, required this.editor});
+
+ final TextEditorState editor;
@override
State<ImageEditorTextBar> createState() => _ImageEditorTextBarState();
}
-class _ImageEditorTextBarState extends State<ImageEditorTextBar>
- with ImageEditorConvertedConfigs, SimpleConfigsAccessState {
- int selectedActionIndex = -1;
- double colorSliderValue = 0.5;
+class _ImageEditorTextBarState extends State<ImageEditorTextBar> {
+ _TextAction? _selectedAction;
+ late double _textColorHue = _initialHue(widget.editor.primaryColor);
+ late double _backgroundColorHue = _initialHue(widget.editor.secondaryColor);
+
+ double _initialHue(Color color) {
+ final hsv = HSVColor.fromColor(color);
+ return hsv.saturation == 0 ? 0.5 : hsv.hue / 360;
+ }
- void _selectAction(int index) {
+ void _selectAction(_TextAction action) {
+ widget.editor.focusNode.unfocus();
setState(() {
- selectedActionIndex = selectedActionIndex == index ? -1 : index;
+ _selectedAction = _selectedAction == action ? null : action;
});
}
@override
Widget build(BuildContext context) {
- return LayoutBuilder(
- builder: (context, constraints) {
- return Column(
- mainAxisSize: MainAxisSize.min,
- children: [_buildFunctions(constraints)],
- );
- },
+ final strings = context.strings;
+ final editor = widget.editor;
+ final mediaQuery = MediaQuery.of(editor.context);
+ final keyboardHeight = mediaQuery.viewInsets.bottom;
+ final maxToolbarHeight = max(
+ 0.0,
+ mediaQuery.size.height -
+ mediaQuery.viewPadding.vertical -
+ keyboardHeight -
+ kToolbarHeight -
+ 64,
);
- }
-
- Widget _buildFunctions(BoxConstraints constraints) {
- return BottomAppBar(
- padding: EdgeInsets.zero,
- height: editorBottomBarHeight,
- child: FadeInUp(
- duration: fadeInDuration,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: <Widget>[_buildMainActionButtons(), _buildHelperWidget()],
+ return Padding(
+ padding: EdgeInsets.only(bottom: keyboardHeight),
+ child: Material(
+ color: context.componentColors.backgroundBase,
+ child: SafeArea(
+ top: false,
+ child: ConstrainedBox(
+ constraints: BoxConstraints(maxHeight: maxToolbarHeight),
+ child: SingleChildScrollView(
+ primary: false,
+ child: Container(
+ constraints: BoxConstraints(
+ minHeight: keyboardHeight > 0
+ ? 0
+ : min(editorBottomBarHeight, maxToolbarHeight),
+ ),
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ LayoutBuilder(
+ builder: (context, constraints) => SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ child: ConstrainedBox(
+ constraints: BoxConstraints(
+ minWidth: constraints.maxWidth,
+ ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+ children: [
+ _action(
+ _TextAction.color,
+ strings.color,
+ HugeIcons.strokeRoundedTextColor,
+ ),
+ _action(
+ _TextAction.font,
+ strings.font,
+ HugeIcons.strokeRoundedTextFont,
+ ),
+ _action(
+ _TextAction.background,
+ strings.background,
+ HugeIcons.strokeRoundedTextSquare,
+ ),
+ _action(
+ _TextAction.align,
+ strings.align,
+ switch (editor.align) {
+ TextAlign.left =>
+ HugeIcons.strokeRoundedTextAlignLeft,
+ TextAlign.right =>
+ HugeIcons.strokeRoundedTextAlignRight,
+ _ => HugeIcons.strokeRoundedTextAlignCenter,
+ },
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ if (_selectedAction != null && keyboardHeight == 0) ...[
+ const SizedBox(height: 12),
+ switch (_selectedAction!) {
+ _TextAction.color => _buildColorPicker(),
+ _TextAction.font => _buildFontPicker(),
+ _TextAction.background => _buildBackgroundPicker(),
+ _TextAction.align => _buildAlignPicker(),
+ },
+ ],
+ ],
+ ),
+ ),
+ ),
+ ),
),
),
);
}
- Widget _buildMainActionButtons() {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- CircularIconButton(
- hugeIcon: HugeIcons.strokeRoundedTextColor,
- label: context.strings.color,
- isSelected: selectedActionIndex == 0,
- onTap: () {
- _selectAction(0);
- },
- ),
- CircularIconButton(
- hugeIcon: HugeIcons.strokeRoundedTextFont,
- label: context.strings.font,
- isSelected: selectedActionIndex == 1,
- onTap: () {
- _selectAction(1);
- },
- ),
- CircularIconButton(
- hugeIcon: HugeIcons.strokeRoundedTextSquare,
- label: context.strings.background,
- isSelected: selectedActionIndex == 2,
- onTap: () {
- setState(() {
- selectedActionIndex = 2;
- });
- },
- ),
- CircularIconButton(
- hugeIcon: HugeIcons.strokeRoundedTextAlignLeft,
- label: context.strings.align,
- isSelected: selectedActionIndex == 3,
- onTap: () {
- setState(() {
- selectedActionIndex = 3;
- });
- },
- ),
- ],
- );
- }
-
- Widget _buildHelperWidget() {
- return AnimatedSwitcher(
- duration: const Duration(milliseconds: 300),
- switchInCurve: Curves.easeInOut,
- switchOutCurve: Curves.easeInOut,
- child: switch (selectedActionIndex) {
- 0 => ImageEditorColorPicker(
- value: colorSliderValue,
- onChanged: (value) {
- setState(() {
- colorSliderValue = value;
- });
- final hue = value * 360;
- final color = HSVColor.fromAHSV(1.0, hue, 1.0, 1.0).toColor();
- widget.editor.primaryColor = color;
- },
- ),
- 1 => _FontPickerWidget(editor: widget.editor),
- 2 => _BackgroundPickerWidget(editor: widget.editor),
- 3 => _AlignPickerWidget(editor: widget.editor),
- _ => const SizedBox.shrink(),
- },
+ Widget _action(_TextAction action, String label, List<List<dynamic>> icon) {
+ return CircularIconButton(
+ label: label,
+ hugeIcon: icon,
+ size: 40,
+ width: 90 * max(1, MediaQuery.textScalerOf(context).scale(14) / 14),
+ isSelected: _selectedAction == action,
+ onTap: () => _selectAction(action),
);
}
-}
-
-class _FontPickerWidget extends StatelessWidget {
- final TextEditorState editor;
- const _FontPickerWidget({required this.editor});
+ Widget _buildColorPicker({bool forBackground = false}) {
+ final editor = widget.editor;
+ final color = (forBackground ? editor.secondaryColor : editor.primaryColor)
+ .withValues(alpha: 1);
+ final label = forBackground
+ ? context.strings.imageEditorBackgroundColor
+ : context.strings.imageEditorTextColor;
- @override
- Widget build(BuildContext context) {
- final colors = context.componentColors;
- final selectedBackground = colors.fillBase.withValues(alpha: 0.9);
- if (editor.textEditorConfigs.customTextStyles == null) {
- return const SizedBox.shrink();
+ void selectColor(Color value) {
+ if (forBackground) {
+ editor.secondaryColor = value.withValues(
+ alpha: editor.secondaryColor.a,
+ );
+ } else {
+ editor.primaryColor = value;
+ }
}
- return Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: editor.textEditorConfigs.customTextStyles!.asMap().entries.map((
- entry,
- ) {
- final item = entry.value;
- final selected = editor.selectedTextStyle;
- final bool isSelected = selected.hashCode == item.hashCode;
+ void selectHue(double value) {
+ setState(() {
+ if (forBackground) {
+ _backgroundColorHue = value;
+ } else {
+ _textColorHue = value;
+ }
+ });
+ selectColor(HSVColor.fromAHSV(1, value * 360, 1, 1).toColor());
+ }
- return Padding(
- padding: const EdgeInsets.only(right: 12),
- child: GestureDetector(
- onTap: () {
- editor.setTextStyle(item);
- },
- child: Container(
- height: 40,
- width: 48,
- decoration: BoxDecoration(
- color: isSelected ? selectedBackground : colors.fillLight,
- borderRadius: BorderRadius.circular(25),
- ),
- child: Center(
- child: Text(
- 'Aa',
- style: item.copyWith(
- color: isSelected ? colors.textReverse : colors.iconColor,
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 20),
+ child: Text(
+ label,
+ style: TextStyles.mini.copyWith(
+ color: context.componentColors.textLight,
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ Row(
+ children: [
+ const SizedBox(width: 12),
+ for (final (swatch, swatchLabel) in [
+ (Colors.white, context.strings.imageEditorWhite),
+ (Colors.black, context.strings.black),
+ ])
+ _option(
+ label: swatchLabel,
+ isSelected: color == swatch,
+ onTap: () => selectColor(swatch),
+ child: Container(
+ width: 24,
+ height: 24,
+ decoration: BoxDecoration(
+ color: swatch,
+ shape: BoxShape.circle,
+ border: Border.all(
+ color: context.componentColors.strokeFaint,
+ ),
),
),
),
+ Expanded(
+ child: ImageEditorColorPicker(
+ value: forBackground ? _backgroundColorHue : _textColorHue,
+ semanticLabel: label,
+ onChangeStart: selectHue,
+ onChanged: selectHue,
+ ),
),
- ),
- );
- }).toList(),
+ ],
+ ),
+ ],
);
}
-}
-
-class _BackgroundPickerWidget extends StatelessWidget {
- final TextEditorState editor;
- const _BackgroundPickerWidget({required this.editor});
+ Widget _buildFontPicker() {
+ final editor = widget.editor;
+ return _optionsRow([
+ for (final style in editor.textEditorConfigs.customTextStyles!)
+ _option(
+ label: style.fontFamily!.split('/').last,
+ isSelected: editor.selectedTextStyle == style,
+ onTap: () => editor.setTextStyle(style),
+ child: Text(
+ style.fontFamily!.split('/').last,
+ style: style.copyWith(
+ fontSize: 16,
+ color: context.componentColors.textBase,
+ ),
+ ),
+ ),
+ ]);
+ }
- @override
- Widget build(BuildContext context) {
+ Widget _buildBackgroundPicker() {
+ final strings = context.strings;
+ final editor = widget.editor;
final colors = context.componentColors;
- final isLightMode = Theme.of(context).brightness == Brightness.light;
- final faintFill = colors.fillBase.withValues(
- alpha: isLightMode ? 0.04 : 0.12,
- );
- final backgroundStyles = {
- LayerBackgroundMode.background: {
- 'text': 'Aa',
- 'selectedBackgroundColor': isLightMode ? faintFill : Colors.white,
- 'backgroundColor': colors.fillLight,
- 'border': null,
- 'textColor': Colors.white,
- 'selectedInnerBackgroundColor': Colors.black,
- 'innerBackgroundColor': Colors.transparent,
- },
- LayerBackgroundMode.backgroundAndColor: {
- 'text': 'Aa',
- 'selectedBackgroundColor': isLightMode ? faintFill : Colors.white,
- 'backgroundColor': colors.fillLight,
- 'border': null,
- 'textColor': Colors.black,
- 'selectedInnerBackgroundColor': Colors.transparent,
- 'innerBackgroundColor': Colors.transparent,
- },
- LayerBackgroundMode.backgroundAndColorWithOpacity: {
- 'text': 'Aa',
- 'selectedBackgroundColor': isLightMode ? faintFill : Colors.white,
- 'backgroundColor': colors.fillLight,
- 'border': null,
- 'textColor': Colors.black,
- 'selectedInnerBackgroundColor': Colors.black.withValues(alpha: 0.11),
- 'innerBackgroundColor': isLightMode
- ? Colors.black.withValues(alpha: 0.11)
- : Colors.white.withValues(alpha: 0.11),
- },
- LayerBackgroundMode.onlyColor: {
- 'text': 'Aa',
- 'selectedBackgroundColor': isLightMode ? faintFill : Colors.black,
- 'backgroundColor': colors.fillLight,
- 'border': isLightMode
- ? null
- : Border.all(color: Colors.white, width: 2),
- 'textColor': Colors.black,
- 'selectedInnerBackgroundColor': Colors.white,
- 'innerBackgroundColor': Colors.white.withValues(alpha: 0.6),
- },
- };
-
- return Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: backgroundStyles.entries.map((entry) {
- final mode = entry.key;
- final style = entry.value;
- final isSelected = editor.backgroundColorMode == mode;
-
- return Padding(
- padding: const EdgeInsets.only(right: 12),
- child: GestureDetector(
- onTap: () {
- editor.setState(() {
- editor.backgroundColorMode = mode;
- });
- },
- child: SizedBox(
- height: 40,
- width: 48,
+ final alpha = editor.secondaryColor.a;
+ final selectedOpacity = alpha == 0 || alpha == 1 ? alpha : 0.5;
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _optionsRow([
+ for (final (opacity, label) in [
+ (0.0, strings.imageEditorNoBackground),
+ (1.0, strings.imageEditorSolidBackground),
+ (0.5, strings.imageEditorTranslucentBackground),
+ ])
+ _option(
+ label: label,
+ isSelected: selectedOpacity == opacity,
+ onTap: () => editor.secondaryColor = editor.secondaryColor
+ .withValues(alpha: opacity),
child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
decoration: BoxDecoration(
- color: isSelected
- ? style['selectedBackgroundColor'] as Color
- : style['backgroundColor'] as Color,
- borderRadius: BorderRadius.circular(25),
- border: isSelected ? style['border'] as Border? : null,
+ borderRadius: BorderRadius.circular(4),
+ color: colors.textBase.withValues(alpha: opacity),
),
- child: Stack(
- alignment: Alignment.center,
- children: [
- Center(
- child: Container(
- height: 20,
- width: 22,
- decoration: ShapeDecoration(
- color: isSelected
- ? style['selectedInnerBackgroundColor'] as Color
- : style['innerBackgroundColor'] as Color,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(4),
- ),
- ),
- ),
- ),
- Center(
- child: Text(
- style['text'] as String,
- style: TextStyle(
- color: isSelected
- ? style['textColor'] as Color
- : colors.iconColor,
- ),
- ),
- ),
- ],
+ child: Text(
+ 'Aa',
+ style: TextStyles.large.copyWith(
+ color: opacity == 0 ? colors.textBase : colors.textReverse,
+ ),
),
),
),
- ),
- );
- }).toList(),
+ ]),
+ if (alpha > 0) ...[
+ const SizedBox(height: 12),
+ _buildColorPicker(forBackground: true),
+ ],
+ ],
);
}
-}
-class _AlignPickerWidget extends StatelessWidget {
- final TextEditorState editor;
+ Widget _buildAlignPicker() {
+ final strings = context.strings;
+ final editor = widget.editor;
+ return _optionsRow([
+ for (final (alignment, icon, label) in [
+ (
+ TextAlign.left,
+ HugeIcons.strokeRoundedTextAlignLeft,
+ strings.imageEditorAlignLeft,
+ ),
+ (
+ TextAlign.center,
+ HugeIcons.strokeRoundedTextAlignCenter,
+ strings.imageEditorAlignCenter,
+ ),
+ (
+ TextAlign.right,
+ HugeIcons.strokeRoundedTextAlignRight,
+ strings.imageEditorAlignRight,
+ ),
+ ])
+ _option(
+ label: label,
+ isSelected: editor.align == alignment,
+ onTap: () => editor.setState(() => editor.align = alignment),
+ child: HugeIcon(
+ icon: icon,
+ size: 22,
+ color: context.componentColors.iconColor,
+ ),
+ ),
+ ]);
+ }
- const _AlignPickerWidget({required this.editor});
+ Widget _optionsRow(List<Widget> children) {
+ return LayoutBuilder(
+ builder: (context, constraints) => SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ child: ConstrainedBox(
+ constraints: BoxConstraints(
+ minWidth: max(0, constraints.maxWidth - 24),
+ ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: children,
+ ),
+ ),
+ ),
+ );
+ }
- @override
- Widget build(BuildContext context) {
+ Widget _option({
+ required String label,
+ required bool isSelected,
+ required VoidCallback onTap,
+ required Widget child,
+ }) {
final colors = context.componentColors;
- final selectedBackground = colors.fillBase.withValues(alpha: 0.9);
- final alignments = <(TextAlign, List<List<dynamic>>)>[
- (TextAlign.left, HugeIcons.strokeRoundedTextAlignLeft),
- (TextAlign.center, HugeIcons.strokeRoundedTextAlignCenter),
- (TextAlign.right, HugeIcons.strokeRoundedTextAlignRight),
- ];
-
- return Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: alignments.map((alignmentData) {
- final (alignment, hugeIcon) = alignmentData;
- final isSelected = editor.align == alignment;
-
- return Padding(
- padding: const EdgeInsets.only(right: 12.0),
- child: GestureDetector(
- onTap: () {
- editor.setState(() {
- editor.align = alignment;
- });
- },
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: Semantics(
+ button: true,
+ selected: isSelected,
+ label: label,
+ child: Tooltip(
+ message: label,
+ excludeFromSemantics: true,
+ child: InkWell(
+ onTap: onTap,
+ borderRadius: BorderRadius.circular(24),
child: Container(
- height: 40,
- width: 48,
+ constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
+ padding: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
- color: isSelected ? selectedBackground : colors.fillLight,
- borderRadius: BorderRadius.circular(25),
- border: isSelected
- ? Border.all(color: Colors.black, width: 2)
- : null,
- ),
- child: Center(
- child: HugeIcon(
- icon: hugeIcon,
- size: 22,
- color: isSelected ? colors.textReverse : colors.iconColor,
+ color: isSelected
+ ? colors.primary.withValues(alpha: 0.24)
+ : colors.fillLight,
+ borderRadius: BorderRadius.circular(24),
+ border: Border.all(
+ color: isSelected ? colors.primary : colors.fillLight,
+ width: 2,
),
),
+ alignment: Alignment.center,
+ child: ExcludeSemantics(child: child),
),
),
- );
- }).toList(),
+ ),
+ ),
);
}
}
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 9cbfb6e6b2..d6183188de 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -1951,15 +1951,38 @@
"ignore": "Ignore",
"ignored": "ignored",
"ignorePerson": "Ignore person",
+ "imageEditorAlignCenter": "Align center",
+ "imageEditorAlignLeft": "Align left",
+ "imageEditorAlignRight": "Align right",
+ "imageEditorBackgroundColor": "Background color",
"imageEditorBrightness": "Brightness",
"imageEditorContrast": "Contrast",
+ "imageEditorEnterText": "Enter text",
"imageEditorExposure": "Exposure",
"imageEditorFade": "Fade",
"imageEditorHue": "Hue",
"imageEditorLuminance": "Luminance",
+ "imageEditorNoBackground": "No background",
+ "@imageEditorNoBackground": {
+ "description": "Text background style with no visible background"
+ },
"imageEditorSaturation": "Saturation",
"imageEditorSharpness": "Sharpness",
+ "imageEditorSolidBackground": "Solid background",
+ "@imageEditorSolidBackground": {
+ "description": "Text background style with a fully opaque color"
+ },
"imageEditorTemperature": "Temperature",
+ "imageEditorText": "Text",
+ "@imageEditorText": {
+ "description": "Tool for adding text to a photo"
+ },
+ "imageEditorTextColor": "Text color",
+ "imageEditorTranslucentBackground": "Translucent background",
+ "@imageEditorTranslucentBackground": {
+ "description": "Text background style with a half-transparent color"
+ },
+ "imageEditorWhite": "White",
"imageNotAnalyzed": "Image not analyzed",
"immediate": "Immediate",
"immediately": "Immediately",