Unverified Commit bb35bc36 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Add a background paint property to TextStyle (#17586)

See https://github.com/flutter/flutter/issues/11961
parent a3e71bf1
...@@ -14,6 +14,7 @@ export 'dart:ui' show ...@@ -14,6 +14,7 @@ export 'dart:ui' show
FontStyle, FontStyle,
FontWeight, FontWeight,
ImageShader, ImageShader,
Locale,
MaskFilter, MaskFilter,
Offset, Offset,
Paint, Paint,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble, Locale; import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -230,6 +230,7 @@ class TextStyle extends Diagnosticable { ...@@ -230,6 +230,7 @@ class TextStyle extends Diagnosticable {
this.textBaseline, this.textBaseline,
this.height, this.height,
this.locale, this.locale,
this.background,
this.decoration, this.decoration,
this.decorationColor, this.decorationColor,
this.decorationStyle, this.decorationStyle,
...@@ -298,7 +299,15 @@ class TextStyle extends Diagnosticable { ...@@ -298,7 +299,15 @@ class TextStyle extends Diagnosticable {
final double height; final double height;
/// The locale used to select region-specific glyphs. /// The locale used to select region-specific glyphs.
final ui.Locale locale; final Locale locale;
/// The paint drawn as a background for the text.
///
/// The value should ideally be cached and reused each time if multiple text
/// styles are created with the same paint settings. Otherwise, each time it
/// will appear like the style changed, which will result in unnecessary
/// updates all the way through the framework.
final Paint background;
/// The decorations to paint near the text (e.g., an underline). /// The decorations to paint near the text (e.g., an underline).
final TextDecoration decoration; final TextDecoration decoration;
...@@ -334,7 +343,8 @@ class TextStyle extends Diagnosticable { ...@@ -334,7 +343,8 @@ class TextStyle extends Diagnosticable {
double wordSpacing, double wordSpacing,
TextBaseline textBaseline, TextBaseline textBaseline,
double height, double height,
ui.Locale locale, Locale locale,
Paint background,
TextDecoration decoration, TextDecoration decoration,
Color decorationColor, Color decorationColor,
TextDecorationStyle decorationStyle, TextDecorationStyle decorationStyle,
...@@ -358,6 +368,7 @@ class TextStyle extends Diagnosticable { ...@@ -358,6 +368,7 @@ class TextStyle extends Diagnosticable {
textBaseline: textBaseline ?? this.textBaseline, textBaseline: textBaseline ?? this.textBaseline,
height: height ?? this.height, height: height ?? this.height,
locale: locale ?? this.locale, locale: locale ?? this.locale,
background: background ?? this.background,
decoration: decoration ?? this.decoration, decoration: decoration ?? this.decoration,
decorationColor: decorationColor ?? this.decorationColor, decorationColor: decorationColor ?? this.decorationColor,
decorationStyle: decorationStyle ?? this.decorationStyle, decorationStyle: decorationStyle ?? this.decorationStyle,
...@@ -436,6 +447,7 @@ class TextStyle extends Diagnosticable { ...@@ -436,6 +447,7 @@ class TextStyle extends Diagnosticable {
textBaseline: textBaseline, textBaseline: textBaseline,
height: height == null ? null : height * heightFactor + heightDelta, height: height == null ? null : height * heightFactor + heightDelta,
locale: locale, locale: locale,
background: background,
decoration: decoration ?? this.decoration, decoration: decoration ?? this.decoration,
decorationColor: decorationColor ?? this.decorationColor, decorationColor: decorationColor ?? this.decorationColor,
decorationStyle: decorationStyle ?? this.decorationStyle, decorationStyle: decorationStyle ?? this.decorationStyle,
...@@ -481,6 +493,7 @@ class TextStyle extends Diagnosticable { ...@@ -481,6 +493,7 @@ class TextStyle extends Diagnosticable {
textBaseline: other.textBaseline, textBaseline: other.textBaseline,
height: other.height, height: other.height,
locale: other.locale, locale: other.locale,
background: other.background,
decoration: other.decoration, decoration: other.decoration,
decorationColor: other.decorationColor, decorationColor: other.decorationColor,
decorationStyle: other.decorationStyle, decorationStyle: other.decorationStyle,
...@@ -529,6 +542,7 @@ class TextStyle extends Diagnosticable { ...@@ -529,6 +542,7 @@ class TextStyle extends Diagnosticable {
textBaseline: t < 0.5 ? null : b.textBaseline, textBaseline: t < 0.5 ? null : b.textBaseline,
height: t < 0.5 ? null : b.height, height: t < 0.5 ? null : b.height,
locale: t < 0.5 ? null : b.locale, locale: t < 0.5 ? null : b.locale,
background: t < 0.5 ? null : b.background,
decoration: t < 0.5 ? null : b.decoration, decoration: t < 0.5 ? null : b.decoration,
decorationColor: Color.lerp(null, b.decorationColor, t), decorationColor: Color.lerp(null, b.decorationColor, t),
decorationStyle: t < 0.5 ? null : b.decorationStyle, decorationStyle: t < 0.5 ? null : b.decorationStyle,
...@@ -549,6 +563,7 @@ class TextStyle extends Diagnosticable { ...@@ -549,6 +563,7 @@ class TextStyle extends Diagnosticable {
textBaseline: t < 0.5 ? a.textBaseline : null, textBaseline: t < 0.5 ? a.textBaseline : null,
height: t < 0.5 ? a.height : null, height: t < 0.5 ? a.height : null,
locale: t < 0.5 ? a.locale : null, locale: t < 0.5 ? a.locale : null,
background: t < 0.5 ? a.background : null,
decoration: t < 0.5 ? a.decoration : null, decoration: t < 0.5 ? a.decoration : null,
decorationColor: Color.lerp(a.decorationColor, null, t), decorationColor: Color.lerp(a.decorationColor, null, t),
decorationStyle: t < 0.5 ? a.decorationStyle : null, decorationStyle: t < 0.5 ? a.decorationStyle : null,
...@@ -568,6 +583,7 @@ class TextStyle extends Diagnosticable { ...@@ -568,6 +583,7 @@ class TextStyle extends Diagnosticable {
textBaseline: t < 0.5 ? a.textBaseline : b.textBaseline, textBaseline: t < 0.5 ? a.textBaseline : b.textBaseline,
height: ui.lerpDouble(a.height ?? b.height, b.height ?? a.height, t), height: ui.lerpDouble(a.height ?? b.height, b.height ?? a.height, t),
locale: t < 0.5 ? a.locale : b.locale, locale: t < 0.5 ? a.locale : b.locale,
background: t < 0.5 ? a.background : b.background,
decoration: t < 0.5 ? a.decoration : b.decoration, decoration: t < 0.5 ? a.decoration : b.decoration,
decorationColor: Color.lerp(a.decorationColor, b.decorationColor, t), decorationColor: Color.lerp(a.decorationColor, b.decorationColor, t),
decorationStyle: t < 0.5 ? a.decorationStyle : b.decorationStyle, decorationStyle: t < 0.5 ? a.decorationStyle : b.decorationStyle,
...@@ -591,6 +607,7 @@ class TextStyle extends Diagnosticable { ...@@ -591,6 +607,7 @@ class TextStyle extends Diagnosticable {
wordSpacing: wordSpacing, wordSpacing: wordSpacing,
height: height, height: height,
locale: locale, locale: locale,
background: background,
); );
} }
...@@ -608,7 +625,7 @@ class TextStyle extends Diagnosticable { ...@@ -608,7 +625,7 @@ class TextStyle extends Diagnosticable {
double textScaleFactor: 1.0, double textScaleFactor: 1.0,
String ellipsis, String ellipsis,
int maxLines, int maxLines,
ui.Locale locale, Locale locale,
}) { }) {
assert(textScaleFactor != null); assert(textScaleFactor != null);
assert(maxLines == null || maxLines > 0); assert(maxLines == null || maxLines > 0);
...@@ -644,7 +661,8 @@ class TextStyle extends Diagnosticable { ...@@ -644,7 +661,8 @@ class TextStyle extends Diagnosticable {
wordSpacing != other.wordSpacing || wordSpacing != other.wordSpacing ||
textBaseline != other.textBaseline || textBaseline != other.textBaseline ||
height != other.height || height != other.height ||
locale != other.locale) locale != other.locale ||
background != other.background)
return RenderComparison.layout; return RenderComparison.layout;
if (color != other.color || if (color != other.color ||
decoration != other.decoration || decoration != other.decoration ||
...@@ -672,6 +690,7 @@ class TextStyle extends Diagnosticable { ...@@ -672,6 +690,7 @@ class TextStyle extends Diagnosticable {
textBaseline == typedOther.textBaseline && textBaseline == typedOther.textBaseline &&
height == typedOther.height && height == typedOther.height &&
locale == typedOther.locale && locale == typedOther.locale &&
background == typedOther.background &&
decoration == typedOther.decoration && decoration == typedOther.decoration &&
decorationColor == typedOther.decorationColor && decorationColor == typedOther.decorationColor &&
decorationStyle == typedOther.decorationStyle; decorationStyle == typedOther.decorationStyle;
...@@ -691,6 +710,7 @@ class TextStyle extends Diagnosticable { ...@@ -691,6 +710,7 @@ class TextStyle extends Diagnosticable {
textBaseline, textBaseline,
height, height,
locale, locale,
background,
decoration, decoration,
decorationColor, decorationColor,
decorationStyle decorationStyle
...@@ -757,6 +777,7 @@ class TextStyle extends Diagnosticable { ...@@ -757,6 +777,7 @@ class TextStyle extends Diagnosticable {
styles.add(new EnumProperty<TextBaseline>('${prefix}baseline', textBaseline, defaultValue: null)); styles.add(new EnumProperty<TextBaseline>('${prefix}baseline', textBaseline, defaultValue: null));
styles.add(new DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null)); styles.add(new DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null));
styles.add(new StringProperty('${prefix}locale', locale?.toString(), defaultValue: null, quoted: false)); styles.add(new StringProperty('${prefix}locale', locale?.toString(), defaultValue: null, quoted: false));
styles.add(new StringProperty('${prefix}background', background?.toString(), defaultValue: null, quoted: false));
if (decoration != null || decorationColor != null || decorationStyle != null) { if (decoration != null || decorationColor != null || decorationStyle != null) {
final List<String> decorationDescription = <String>[]; final List<String> decorationDescription = <String>[];
if (decorationStyle != null) if (decorationStyle != null)
......
...@@ -403,6 +403,8 @@ void main() { ...@@ -403,6 +403,8 @@ void main() {
expect(style.decorationColor, null); expect(style.decorationColor, null);
expect(style.decorationStyle, null); expect(style.decorationStyle, null);
expect(style.debugLabel, isNotNull); expect(style.debugLabel, isNotNull);
expect(style.locale, null);
expect(style.background, null);
} }
} }
...@@ -450,6 +452,7 @@ class _TextStyleProxy implements TextStyle { ...@@ -450,6 +452,7 @@ class _TextStyleProxy implements TextStyle {
@override FontWeight get fontWeight => _delegate.fontWeight; @override FontWeight get fontWeight => _delegate.fontWeight;
@override double get height => _delegate.height; @override double get height => _delegate.height;
@override ui.Locale get locale => _delegate.locale; @override ui.Locale get locale => _delegate.locale;
@override ui.Paint get background => _delegate.background;
@override bool get inherit => _delegate.inherit; @override bool get inherit => _delegate.inherit;
@override double get letterSpacing => _delegate.letterSpacing; @override double get letterSpacing => _delegate.letterSpacing;
@override TextBaseline get textBaseline => _delegate.textBaseline; @override TextBaseline get textBaseline => _delegate.textBaseline;
...@@ -476,7 +479,7 @@ class _TextStyleProxy implements TextStyle { ...@@ -476,7 +479,7 @@ class _TextStyleProxy implements TextStyle {
} }
@override @override
TextStyle copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, ui.Locale locale, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel}) { TextStyle copyWith({Color color, String fontFamily, double fontSize, FontWeight fontWeight, FontStyle fontStyle, double letterSpacing, double wordSpacing, TextBaseline textBaseline, double height, ui.Locale locale, ui.Paint background, TextDecoration decoration, Color decorationColor, TextDecorationStyle decorationStyle, String debugLabel}) {
throw new UnimplementedError(); throw new UnimplementedError();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment