highlight title review

This commit is contained in:
Thibault Deckers 2022-11-28 16:30:05 +01:00
parent f9c2156fed
commit 07abd4091c
6 changed files with 50 additions and 32 deletions

View file

@ -8,6 +8,9 @@ class OutlinedText extends StatelessWidget {
final Color outlineColor;
final double outlineBlurSigma;
final TextAlign? textAlign;
final bool? softWrap;
final TextOverflow? overflow;
final int? maxLines;
static const widgetSpanAlignment = PlaceholderAlignment.middle;
@ -18,6 +21,9 @@ class OutlinedText extends StatelessWidget {
Color? outlineColor,
double? outlineBlurSigma,
this.textAlign,
this.softWrap,
this.overflow,
this.maxLines,
}) : outlineWidth = outlineWidth ?? 1,
outlineColor = outlineColor ?? Colors.black,
outlineBlurSigma = outlineBlurSigma ?? 0;
@ -49,6 +55,9 @@ class OutlinedText extends StatelessWidget {
children: textSpans.map(_toStrokeSpan).toList(),
),
textAlign: textAlign,
softWrap: softWrap,
overflow: overflow,
maxLines: maxLines,
),
),
Text.rich(
@ -56,6 +65,9 @@ class OutlinedText extends StatelessWidget {
children: hasOutline ? textSpans.map(_toFillSpan).toList() : textSpans,
),
textAlign: textAlign,
softWrap: softWrap,
overflow: overflow,
maxLines: maxLines,
),
],
);

View file

@ -24,7 +24,8 @@ class _HighlightDecorationPainter extends BoxPainter {
final confHeight = size.height;
final paintHeight = confHeight * .4;
final rect = Rect.fromLTWH(offset.dx, offset.dy + confHeight - paintHeight, size.width, paintHeight);
final rrect = RRect.fromRectAndRadius(rect, Radius.circular(paintHeight));
final paint = Paint()..color = decoration.color;
canvas.drawRect(rect, paint);
canvas.drawRRect(rrect, paint);
}
}

View file

@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:aves/model/settings/enums/enums.dart';
import 'package:aves/model/settings/settings.dart';
import 'package:aves/theme/colors.dart';
import 'package:aves/widgets/common/basic/outlined_text.dart';
import 'package:aves/widgets/common/fx/highlight_decoration.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@ -11,7 +12,7 @@ class HighlightTitle extends StatelessWidget {
final String title;
final Color? color;
final double fontSize;
final bool enabled, selectable;
final bool enabled;
final bool showHighlight;
const HighlightTitle({
@ -20,24 +21,23 @@ class HighlightTitle extends StatelessWidget {
this.color,
this.fontSize = 18,
this.enabled = true,
this.selectable = false,
this.showHighlight = true,
});
static const disabledColor = Colors.grey;
static const shadows = [
Shadow(
color: Colors.black,
offset: Offset(1, 1),
blurRadius: 2,
)
];
static List<Shadow> shadows(BuildContext context) => [
Shadow(
color: Theme.of(context).brightness == Brightness.dark ? Colors.black : Colors.white,
offset: const Offset(0, 1),
blurRadius: 2,
)
];
@override
Widget build(BuildContext context) {
final style = TextStyle(
shadows: Theme.of(context).brightness == Brightness.dark ? shadows : null,
shadows: shadows(context),
fontSize: fontSize,
letterSpacing: 1.0,
fontFeatures: const [FontFeature.enable('smcp')],
@ -47,25 +47,25 @@ class HighlightTitle extends StatelessWidget {
return Align(
alignment: AlignmentDirectional.centerStart,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 2),
decoration: showHighlight && context.select<Settings, bool>((v) => v.themeColorMode == AvesThemeColorMode.polychrome)
? HighlightDecoration(
color: enabled ? color ?? colors.fromString(title) : disabledColor,
)
: null,
margin: const EdgeInsets.symmetric(vertical: 4.0),
child: selectable
? SelectableText(
title,
style: style,
maxLines: 1,
)
: Text(
title,
style: style,
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
),
child: OutlinedText(
textSpans: [
TextSpan(
text: title,
style: style,
),
],
outlineColor: Theme.of(context).scaffoldBackgroundColor,
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 1,
),
),
);
}

View file

@ -5,6 +5,7 @@ import 'package:aves/model/settings/settings.dart';
import 'package:aves/ref/brand_colors.dart';
import 'package:aves/theme/colors.dart';
import 'package:aves/theme/durations.dart';
import 'package:aves/widgets/common/basic/outlined_text.dart';
import 'package:aves/widgets/common/extensions/build_context.dart';
import 'package:aves/widgets/common/fx/highlight_decoration.dart';
import 'package:aves/widgets/common/identity/highlight_title.dart';
@ -100,15 +101,21 @@ class _RemoveEntryMetadataDialogState extends State<RemoveEntryMetadataDialog> {
Widget _toTile(MetadataType type) {
final text = type.getText();
Widget child = Text(
text,
style: TextStyle(
shadows: Theme.of(context).brightness == Brightness.dark ? HighlightTitle.shadows : null,
),
Widget child = OutlinedText(
textSpans: [
TextSpan(
text: text,
style: TextStyle(
shadows: HighlightTitle.shadows(context),
),
),
],
outlineColor: Theme.of(context).scaffoldBackgroundColor,
);
if (context.select<Settings, bool>((v) => v.themeColorMode == AvesThemeColorMode.polychrome)) {
final colors = context.watch<AvesColorsData>();
child = DecoratedBox(
child = Container(
padding: const EdgeInsets.symmetric(horizontal: 2),
decoration: HighlightDecoration(
color: colors.fromBrandColor(BrandColors.get(text)) ?? colors.fromString(text),
),

View file

@ -92,7 +92,6 @@ class _XmpCardState extends State<XmpCard> {
Expanded(
child: HighlightTitle(
title: widget.title,
selectable: true,
showHighlight: false,
),
),

View file

@ -116,7 +116,6 @@ class XmpNamespace extends Equatable {
child: HighlightTitle(
title: displayTitle,
color: context.select<AvesColorsData, Color?>((v) => v.fromBrandColor(BrandColors.get(displayTitle))),
selectable: true,
),
),
...content