浏览代码

Add strut style (framework part).

/main
Yuncong Zhang 5 年前
当前提交
c5a05438
共有 13 个文件被更改,包括 413 次插入35 次删除
  1. 6
      Runtime/material/text_field.cs
  2. 2
      Runtime/material/text_form_field.cs
  3. 22
      Runtime/painting/text_painter.cs
  4. 22
      Runtime/painting/text_style.cs
  5. 15
      Runtime/rendering/editable.cs
  6. 16
      Runtime/rendering/paragraph.cs
  7. 6
      Runtime/ui/text.cs
  8. 6
      Runtime/widgets/basic.cs
  9. 77
      Runtime/widgets/editable_text.cs
  10. 9
      Runtime/widgets/text.cs
  11. 36
      Samples/UIWidgetSample/TextInputSample.cs
  12. 220
      Runtime/painting/strut_style.cs
  13. 11
      Runtime/painting/strut_style.cs.meta

6
Runtime/material/text_field.cs


using System.Collections.Generic;
using System.Text;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;

InputDecoration decoration = null, bool noDecoration = false, TextInputType keyboardType = null,
TextInputAction? textInputAction = null,
TextCapitalization textCapitalization = TextCapitalization.none, TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign textAlign = TextAlign.left, TextDirection textDirection = TextDirection.ltr,
bool autofocus = false, bool obscureText = false, bool autocorrect = false, int? maxLines = 1,
int? maxLength = null, bool maxLengthEnforced = true, ValueChanged<string> onChanged = null,

this.textInputAction = textInputAction;
this.textCapitalization = textCapitalization;
this.style = style;
this.strutStyle = strutStyle;
this.textAlign = textAlign;
this.textDirection = textDirection;
this.autofocus = autofocus;

public readonly TextCapitalization textCapitalization;
public readonly TextStyle style;
public readonly StrutStyle strutStyle;
public readonly TextAlign textAlign;

textInputAction: this.widget.textInputAction,
textCapitalization: this.widget.textCapitalization,
style: style,
strutStyle: this.widget.strutStyle,
textAlign: this.widget.textAlign,
textDirection: this.widget.textDirection,
autofocus: this.widget.autofocus,

2
Runtime/material/text_form_field.cs


TextCapitalization textCapitalization = TextCapitalization.none,
TextInputAction? textInputAction = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextDirection? textDirection = null,
TextAlign textAlign = TextAlign.left,
bool autofocus = false,

keyboardType: keyboardType,
textInputAction: textInputAction,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection ?? TextDirection.ltr,
textCapitalization: textCapitalization,

22
Runtime/painting/text_painter.cs


TextDirection textDirection = TextDirection.ltr,
float textScaleFactor = 1.0f,
int? maxLines = null,
string ellipsis = "") {
string ellipsis = "",
StrutStyle strutStyle = null) {
this._text = text;
this._textAlign = textAlign;
this._textDirection = textDirection;

this._strutStyle = strutStyle;
}

this._needsLayout = true;
}
}
public StrutStyle strutStyle {
get { return this._strutStyle; }
set {
if (this._strutStyle == value) {
return;
}
this._strutStyle = value;
this._paragraph = null;
this._needsLayout = true;
}
}
StrutStyle _strutStyle;
public float minIntrinsicWidth {
get {

textAlign: this.textAlign,
textDirection: this.textDirection ?? defaultTextDirection,
maxLines: this.maxLines,
ellipsis: this.ellipsis
ellipsis: this.ellipsis,
strutStyle: this._strutStyle
);
}

22
Runtime/painting/text_style.cs


public readonly TextDecorationStyle? decorationStyle;
public readonly Paint background;
public readonly string fontFamily;
public List<string> fontFamilyFallback {
get { return this._fontFamilyFallback; }
}
readonly List<string> _fontFamilyFallback;
public readonly string debugLabel;
const string _kDefaultDebugLabel = "unknown";

TextBaseline? textBaseline = null, float? height = null, Paint background = null,
TextDecoration decoration = null,
Color decorationColor = null, TextDecorationStyle? decorationStyle = null,
string fontFamily = null, string debugLabel = null) {
string fontFamily = null, List<string> fontFamilyFallback = null, string debugLabel = null) {
this.inherit = inherit;
this.color = color;
this.fontSize = fontSize;

this.decorationColor = decorationColor;
this.decorationStyle = decorationStyle;
this.fontFamily = fontFamily;
this._fontFamilyFallback = fontFamilyFallback;
this.debugLabel = debugLabel;
this.background = background;
}

Color decorationColor = null,
TextDecorationStyle? decorationStyle = null,
string fontFamily = null,
List<string> fontFamilyFallback = null,
float fontSizeFactor = 1.0f,
float fontSizeDelta = 0.0f,
int fontWeightDelta = 0,

inherit: this.inherit,
color: color ?? this.color,
fontFamily: fontFamily ?? this.fontFamily,
fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback,
fontSize: this.fontSize == null ? null : this.fontSize * fontSizeFactor + fontSizeDelta,
fontWeight: this.fontWeight == null ? null : this.fontWeight,
fontStyle: this.fontStyle,

return this.copyWith(
color: other.color,
fontFamily: other.fontFamily,
fontFamilyFallback: other.fontFamilyFallback,
fontSize: other.fontSize,
fontWeight: other.fontWeight,
fontStyle: other.fontStyle,

public TextStyle copyWith(Color color = null,
string fontFamily = null,
List<string> fontFamilyFallback = null,
float? fontSize = null,
FontWeight fontWeight = null,
FontStyle? fontStyle = null,

inherit: this.inherit,
color: color ?? this.color,
fontFamily: fontFamily ?? this.fontFamily,
fontFamilyFallback: fontFamilyFallback ?? this.fontFamilyFallback,
fontSize: fontSize ?? this.fontSize,
fontWeight: fontWeight ?? this.fontWeight,
fontStyle: fontStyle ?? this.fontStyle,

inherit: b.inherit,
color: Color.lerp(null, b.color, t),
fontFamily: t < 0.5 ? null : b.fontFamily,
fontFamilyFallback: t < 0.5 ? null : b.fontFamilyFallback,
fontSize: t < 0.5 ? null : b.fontSize,
fontWeight: t < 0.5 ? null : b.fontWeight,
fontStyle: t < 0.5 ? null : b.fontStyle,

inherit: a.inherit,
color: Color.lerp(a.color, null, t),
fontFamily: t < 0.5 ? a.fontFamily : null,
fontFamilyFallback: t < 0.5 ? a.fontFamilyFallback : null,
fontSize: t < 0.5 ? a.fontSize : null,
fontWeight: t < 0.5 ? a.fontWeight : null,
fontStyle: t < 0.5 ? a.fontStyle : null,

inherit: b.inherit,
color: Color.lerp(a.color, b.color, t),
fontFamily: t < 0.5 ? a.fontFamily : b.fontFamily,
fontFamilyFallback: t < 0.5 ? a.fontFamilyFallback : b.fontFamilyFallback,
fontSize: MathUtils.lerpNullableFloat(a.fontSize ?? b.fontSize, b.fontSize ?? a.fontSize, t),
fontWeight: t < 0.5 ? a.fontWeight : b.fontWeight,
fontStyle: t < 0.5 ? a.fontStyle : b.fontStyle,

defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new StringProperty("family", this.fontFamily, defaultValue: Diagnostics.kNullDefaultValue,
quoted: false));
styles.Add(new EnumerableProperty<string>("familyFallback", this.fontFamilyFallback,
defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<float?>("size", this.fontSize,
defaultValue: Diagnostics.kNullDefaultValue));
string weightDescription = "";

Equals(this.decoration, other.decoration) &&
Equals(this.decorationColor, other.decorationColor) &&
this.decorationStyle == other.decorationStyle && Equals(this.background, other.background) &&
CollectionUtils.equalsList(this.fontFamilyFallback, other.fontFamilyFallback) &&
string.Equals(this.fontFamily, other.fontFamily);
}

hashCode = (hashCode * 397) ^ this.decorationStyle.GetHashCode();
hashCode = (hashCode * 397) ^ (this.background != null ? this.background.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.fontFamily != null ? this.fontFamily.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(this.fontFamilyFallback != null ? this.fontFamilyFallback.GetHashCode() : 0);
return hashCode;
}
}

15
Runtime/rendering/editable.cs


Color backgroundCursorColor = null,
bool? hasFocus = null,
int? maxLines = 1,
StrutStyle strutStyle = null,
Color selectionColor = null,
TextSelection selection = null,
bool obscureText = false,

floatingCursorAddedMargin = floatingCursorAddedMargin ?? EdgeInsets.fromLTRB(4, 4, 4, 5);
D.assert(textSelectionDelegate != null);
this._textPainter = new TextPainter(text: text, textAlign: textAlign, textDirection: textDirection,
textScaleFactor: textScaleFactor);
textScaleFactor: textScaleFactor, strutStyle: strutStyle);
this._cursorColor = cursorColor;
this._showCursor = showCursor ?? new ValueNotifier<bool>(false);

this._textPainter.textDirection = value;
this.markNeedsTextLayout();
this.markNeedsSemanticsUpdate();
}
}
public StrutStyle strutStyle {
get { return this._textPainter.strutStyle; }
set {
if (this._textPainter.strutStyle == value) {
return;
}
this._textPainter.strutStyle = value;
this.markNeedsTextLayout();
}
}

16
Runtime/rendering/paragraph.cs


TextOverflow overflow = TextOverflow.clip,
float textScaleFactor = 1.0f,
int? maxLines = null,
StrutStyle strutStyle = null,
Action onSelectionChanged = null,
Color selectionColor = null
) {

textDirection,
textScaleFactor,
maxLines,
overflow == TextOverflow.ellipsis ? _kEllipsis : ""
overflow == TextOverflow.ellipsis ? _kEllipsis : "",
strutStyle: strutStyle
);
this._selection = null;

}
canvas.drawPath(barPath, paint);
}
public StrutStyle strutStyle {
get { return this._textPainter.strutStyle; }
set {
if (this._textPainter.strutStyle == value) {
return;
}
this._textPainter.strutStyle = value;
this.markNeedsLayout();
}
}
void _layoutText(float minWidth = 0.0f, float maxWidth = float.PositiveInfinity) {

6
Runtime/ui/text.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.painting;
namespace Unity.UIWidgets.ui {
public enum FontStyle {

float? fontSize = null,
string fontFamily = null,
float? lineHeight = null, // todo
string ellipsis = null) {
string ellipsis = null,
StrutStyle strutStyle = null) {
this.textAlign = textAlign;
this.textDirection = textDirection;
this.fontWeight = fontWeight;

this.fontFamily = fontFamily;
this.lineHeight = lineHeight;
this.ellipsis = ellipsis;
this.strutStyle = strutStyle;
}
public bool Equals(ParagraphStyle other) {

public readonly string fontFamily;
public readonly float? lineHeight;
public readonly string ellipsis;
public readonly StrutStyle strutStyle;
public bool ellipsized() {
return !string.IsNullOrEmpty(this.ellipsis);

6
Runtime/widgets/basic.cs


float textScaleFactor = 1.0f,
int? maxLines = null,
Action onSelectionChanged = null,
Color selectionColor = null
Color selectionColor = null,
StrutStyle strutStyle = null
) : base(key: key) {
D.assert(text != null);
D.assert(maxLines == null || maxLines > 0);

this.maxLines = maxLines;
this.onSelectionChanged = onSelectionChanged;
this.selectionColor = selectionColor;
this.strutStyle = strutStyle;
}
public readonly TextSpan text;

public readonly int? maxLines;
public readonly Action onSelectionChanged;
public readonly Color selectionColor;
public readonly StrutStyle strutStyle;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderParagraph(

renderObject.maxLines = this.maxLines;
renderObject.onSelectionChanged = this.onSelectionChanged;
renderObject.selectionColor = this.selectionColor;
renderObject.strutStyle = this.strutStyle;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {

77
Runtime/widgets/editable_text.cs


public readonly TextStyle style;
public StrutStyle strutStyle {
get {
if (this._strutStyle == null) {
return this.style != null
? StrutStyle.fromTextStyle(this.style, forceStrutHeight: true)
: StrutStyle.disabled;
}
return this._strutStyle.inheritFromTextStyle(this.style);
}
}
readonly StrutStyle _strutStyle;
public readonly TextAlign textAlign;
public readonly TextDirection? textDirection;

public readonly bool unityTouchKeyboard;
public EditableText(TextEditingController controller, FocusNode focusNode, TextStyle style,
Color cursorColor, Color backgroundCursorColor = null, bool obscureText = false, bool autocorrect = false,
TextAlign textAlign = TextAlign.left, TextDirection? textDirection = null,
float? textScaleFactor = null, int? maxLines = 1,
bool autofocus = false, Color selectionColor = null, TextSelectionControls selectionControls = null,
TextInputType keyboardType = null, TextInputAction? textInputAction = null,
public EditableText(
TextEditingController controller = null,
FocusNode focusNode = null, TextStyle style = null,
StrutStyle strutStyle = null,
Color cursorColor = null,
Color backgroundCursorColor = null,
bool obscureText = false,
bool autocorrect = false,
TextAlign textAlign = TextAlign.left,
TextDirection? textDirection = null,
float? textScaleFactor = null,
int? maxLines = 1,
bool autofocus = false,
Color selectionColor = null,
TextSelectionControls selectionControls = null,
TextInputType keyboardType = null,
TextInputAction? textInputAction = null,
ValueChanged<string> onChanged = null, VoidCallback onEditingComplete = null,
ValueChanged<string> onSubmitted = null, SelectionChangedCallback onSelectionChanged = null,
List<TextInputFormatter> inputFormatters = null, bool rendererIgnoresPointer = false,
EdgeInsets scrollPadding = null, bool unityTouchKeyboard = false,
Key key = null, float? cursorWidth = 2.0f, Radius cursorRadius = null, bool cursorOpacityAnimates = false,
Offset cursorOffset = null, bool paintCursorAboveText = false,
ValueChanged<string> onChanged = null,
VoidCallback onEditingComplete = null,
ValueChanged<string> onSubmitted = null,
SelectionChangedCallback onSelectionChanged = null,
List<TextInputFormatter> inputFormatters = null,
bool rendererIgnoresPointer = false,
EdgeInsets scrollPadding = null,
bool unityTouchKeyboard = false,
Key key = null,
float? cursorWidth = 2.0f,
Radius cursorRadius = null,
bool cursorOpacityAnimates = false,
Offset cursorOffset = null,
bool paintCursorAboveText = false,
Brightness? keyboardAppearance = Brightness.light,
DragStartBehavior dragStartBehavior = DragStartBehavior.down,
bool? enableInteractiveSelection = null

this.obscureText = obscureText;
this.autocorrect = autocorrect;
this.style = style;
this._strutStyle = strutStyle;
this.textAlign = textAlign;
this.textDirection = textDirection;
this.textScaleFactor = textScaleFactor;

this._handleSelectionChanged(TextSelection.collapsed(offset: this._lastTextPosition.offset),
this.renderEditable, SelectionChangedCause.forcePress);
}
} else {
}
else {
float lerpValue = this._floatingCursorResetController.value;
float lerpX = MathUtils.lerpFloat(this._lastBoundedOffset.dx, finalPosition.dx, lerpValue);
float lerpY = MathUtils.lerpFloat(this._lastBoundedOffset.dy, finalPosition.dy, lerpValue);

public void requestKeyboard() {
if (this._hasFocus) {
this._openInputConnection();
} else {
}
else {
FocusScope.of(this.context).requestFocus(this.widget.focusNode);
}
}

get {
TextDirection? result = this.widget.textDirection ?? Directionality.of(this.context);
D.assert(result != null,
() => $"{this.GetType().FullName} created without a textDirection and with no ambient Directionality.");
() =>
$"{this.GetType().FullName} created without a textDirection and with no ambient Directionality.");
return result;
}
}

: this._cursorVisibilityNotifier,
hasFocus: this._hasFocus,
maxLines: this.widget.maxLines,
strutStyle: this.widget.strutStyle,
selectionColor: this.widget.selectionColor,
textScaleFactor: this.widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
textAlign: this.widget.textAlign,

public readonly ValueNotifier<bool> showCursor;
public readonly bool hasFocus;
public readonly int? maxLines;
public readonly StrutStyle strutStyle;
public readonly Color selectionColor;
public readonly float textScaleFactor;
public readonly TextAlign textAlign;

public _Editable(TextSpan textSpan = null, TextEditingValue value = null,
Color cursorColor = null, Color backgroundCursorColor = null, ValueNotifier<bool> showCursor = null,
bool hasFocus = false,
int? maxLines = null, Color selectionColor = null, float textScaleFactor = 1.0f,
int? maxLines = null, StrutStyle strutStyle = null, Color selectionColor = null,
float textScaleFactor = 1.0f,
TextDirection? textDirection = null, bool obscureText = false, TextAlign textAlign = TextAlign.left,
bool autocorrect = false, ViewportOffset offset = null, SelectionChangedHandler onSelectionChanged = null,
CaretChangedHandler onCaretChanged = null, bool rendererIgnoresPointer = false,

this.showCursor = showCursor;
this.hasFocus = hasFocus;
this.maxLines = maxLines;
this.strutStyle = strutStyle;
this.selectionColor = selectionColor;
this.textScaleFactor = textScaleFactor;
this.textAlign = textAlign;

backgroundCursorColor: this.backgroundCursorColor,
hasFocus: this.hasFocus,
maxLines: this.maxLines,
strutStyle: this.strutStyle,
selectionColor: this.selectionColor,
textScaleFactor: this.textScaleFactor,
textAlign: this.textAlign,

edit.showCursor = this.showCursor;
edit.hasFocus = this.hasFocus;
edit.maxLines = this.maxLines;
edit.strutStyle = this.strutStyle;
edit.selectionColor = this.selectionColor;
edit.textScaleFactor = this.textScaleFactor;
edit.textAlign = this.textAlign;

9
Runtime/widgets/text.cs


public Text(string data,
Key key = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,

this.textSpan = null;
this.data = data;
this.style = style;
this.strutStyle = strutStyle;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.overflow = overflow;

Text(TextSpan textSpan,
Key key = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,

this.textSpan = textSpan;
this.data = null;
this.style = style;
this.strutStyle = strutStyle;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.overflow = overflow;

public static Text rich(TextSpan textSpan,
Key key = null,
TextStyle style = null,
StrutStyle strutStyle = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,

textSpan, key,
style,
strutStyle,
textAlign,
softWrap,
overflow,

public readonly TextSpan textSpan;
public readonly TextStyle style;
public readonly StrutStyle strutStyle;
public readonly TextAlign? textAlign;

overflow: this.overflow ?? defaultTextStyle.overflow,
textScaleFactor: this.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
maxLines: this.maxLines ?? defaultTextStyle.maxLines,
strutStyle: this.strutStyle,
text: new TextSpan(
style: effectiveTextStyle,
text: this.data,

36
Samples/UIWidgetSample/TextInputSample.cs


protected override Widget createWidget() {
return new MaterialApp(
home: new EditableInputTypeWidget()
);
);
}

height: 80,
child: new Row(
children: new List<Widget> {
new Container(width: 100, child: new Text(title, style: new TextStyle(fontSize: 14, height: 2.0f, color: Colors.black, decoration: TextDecoration.none))),
new Container(width: 100,
child: new Text(title,
style: new TextStyle(fontSize: 14, height: 2.0f, color: Colors.black,
decoration: TextDecoration.none))),
new Flexible(child: new Container(child: widget, padding: EdgeInsets.all(4), decoration:
new BoxDecoration(border: Border.all(color: Color.black))))
}

var selectionColor = new Color(0xFF6F6F6F);
widgets.Add(this.rowWidgets("Default", new EditStateProvider(builder: ((buildContext, controller, node) =>
new EditableText(controller, node, style, cursorColor, Colors.blue,
new EditableText(controller, node, style, cursorColor: cursorColor, backgroundCursorColor: Colors.blue,
cursorWidth: 5.0f, cursorRadius: Radius.circular(2.5f), cursorOpacityAnimates: true, paintCursorAboveText: true)))));
cursorWidth: 5.0f, cursorRadius: Radius.circular(2.5f), cursorOpacityAnimates: true,
paintCursorAboveText: true)))));
new EditableText(controller, node, style, cursorColor, Colors.transparent,
new EditableText(controller, node, style, cursorColor: cursorColor,
backgroundCursorColor: Colors.transparent,
selectionColor: selectionColor, maxLines: 4,
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));

new EditableText(controller, node, style, cursorColor, Colors.transparent,
new EditableText(controller, node, style, cursorColor: cursorColor,
backgroundCursorColor: Colors.transparent,
new EditableText(controller, node, style, cursorColor, Colors.transparent,
new EditableText(controller, node, style, cursorColor: cursorColor,
backgroundCursorColor: Colors.transparent,
new EditableText(controller, node, style, cursorColor, Colors.transparent,
new EditableText(controller, node, style, cursorColor: cursorColor,
backgroundCursorColor: Colors.transparent,
new EditableText(controller, node, style, cursorColor, Colors.transparent,
new EditableText(controller, node, style, cursorColor: cursorColor,
backgroundCursorColor: Colors.transparent,
new EditableText(controller, node, style, cursorColor, Colors.transparent,
new EditableText(controller, node, style, cursorColor: cursorColor,
backgroundCursorColor: Colors.transparent,
selectionColor: selectionColor, keyboardType: TextInputType.url,
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));

public override Widget build(BuildContext context) {
List<Widget> widgets = new List<Widget>();
widgets.Add(new Text("UIWidgets Touch Keyboard", style: new TextStyle(fontSize: 20, height: 2.0f, color: Colors.black, decoration: TextDecoration.none),
widgets.Add(new Text("UIWidgets Touch Keyboard",
style: new TextStyle(fontSize: 20, height: 2.0f, color: Colors.black, decoration: TextDecoration.none),
widgets.Add(new Text("Unity Touch Keyboard", style: new TextStyle(fontSize: 20, height: 2.0f, color: Colors.black, decoration: TextDecoration.none),
widgets.Add(new Text("Unity Touch Keyboard",
style: new TextStyle(fontSize: 20, height: 2.0f, color: Colors.black, decoration: TextDecoration.none),
textAlign: TextAlign.center));
widgets.AddRange(this.buildInputs(true));

220
Runtime/painting/strut_style.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.painting {
public class StrutStyle : Diagnosticable {
public StrutStyle(
string fontFamily = null,
List<string> fontFamilyFallback = null,
float? fontSize = null,
float? height = null,
float? leading = null,
FontWeight fontWeight = null,
FontStyle? fontStyle = null,
bool forceStrutHeight = false,
string debugLabel = null
) {
D.assert(fontSize == null || fontSize > 0);
D.assert(leading == null || leading >= 0);
this.fontFamily = fontFamily;
this._fontFamilyFallback = fontFamilyFallback;
this.fontSize = fontSize;
this.height = height;
this.fontWeight = fontWeight;
this.fontStyle = fontStyle;
this.leading = leading;
this.forceStrutHeight = forceStrutHeight;
this.debugLabel = debugLabel;
}
public static StrutStyle fromTextStyle(
TextStyle textStyle,
string fontFamily = null,
List<string> fontFamilyFallback = null,
float? fontSize = null,
float? height = null,
float? leading = null,
FontWeight fontWeight = null,
FontStyle? fontStyle = null,
bool forceStrutHeight = false,
string debugLabel = null
) {
D.assert(textStyle != null);
D.assert(fontSize == null || fontSize > 0);
D.assert(leading == null || leading >= 0);
return new StrutStyle(
fontFamily: fontFamily ?? textStyle.fontFamily,
fontFamilyFallback: fontFamilyFallback ?? textStyle.fontFamilyFallback,
height: height ?? textStyle.height,
fontSize: fontSize ?? textStyle.fontSize,
fontWeight: fontWeight ?? textStyle.fontWeight,
fontStyle: fontStyle ?? textStyle.fontStyle,
debugLabel: debugLabel ?? textStyle.debugLabel
);
}
public static readonly StrutStyle disabled = new StrutStyle(
height: 0.0f,
leading: 0.0f
);
public readonly string fontFamily;
public List<string> fontFamilyFallback {
get { return this._fontFamilyFallback; }
}
readonly List<string> _fontFamilyFallback;
public readonly float? fontSize;
public readonly float? height;
public readonly FontWeight fontWeight;
public readonly FontStyle? fontStyle;
public readonly float? leading;
public readonly bool forceStrutHeight;
public readonly string debugLabel;
public RenderComparison compareTo(StrutStyle other) {
if (ReferenceEquals(this, other)) {
return RenderComparison.identical;
}
if (other == null) {
return RenderComparison.layout;
}
if (this.fontFamily != other.fontFamily ||
this.fontSize != other.fontSize ||
this.fontWeight != other.fontWeight ||
this.fontStyle != other.fontStyle ||
this.height != other.height ||
this.leading != other.leading ||
this.forceStrutHeight != other.forceStrutHeight ||
!CollectionUtils.equalsList(this.fontFamilyFallback, other.fontFamilyFallback)) {
return RenderComparison.layout;
}
return RenderComparison.identical;
}
public StrutStyle inheritFromTextStyle(TextStyle other) {
if (other == null) {
return this;
}
return new StrutStyle(
fontFamily: this.fontFamily ?? other.fontFamily,
fontFamilyFallback: this.fontFamilyFallback ?? other.fontFamilyFallback,
height: this.height ?? other.height,
leading: this.leading,
fontSize: this.fontSize ?? other.fontSize,
fontWeight: this.fontWeight ?? other.fontWeight,
fontStyle: this.fontStyle ?? other.fontStyle,
forceStrutHeight: this.forceStrutHeight,
debugLabel: this.debugLabel ?? other.debugLabel
);
}
public bool Equals(StrutStyle other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return this.fontFamily == other.fontFamily &&
this.fontSize == other.fontSize &&
this.fontWeight == other.fontWeight &&
this.fontStyle == other.fontStyle &&
this.height == other.height &&
this.leading == other.leading &&
this.forceStrutHeight == other.forceStrutHeight;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((StrutStyle) obj);
}
public static bool operator ==(StrutStyle left, StrutStyle right) {
return Equals(left, right);
}
public static bool operator !=(StrutStyle left, StrutStyle right) {
return !Equals(left, right);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.fontFamily?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (this.fontSize?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.fontWeight?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.fontStyle?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.height?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (this.leading?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ this.forceStrutHeight.GetHashCode();
return hashCode;
}
}
public override string toStringShort() {
return $"{this.GetType()}";
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
if (this.debugLabel != null) {
properties.add(new MessageProperty("debugLabel", this.debugLabel));
}
List<DiagnosticsNode> styles = new List<DiagnosticsNode>();
styles.Add(new StringProperty("family", this.fontFamily, defaultValue: Diagnostics.kNullDefaultValue,
quoted: false));
styles.Add(new EnumerableProperty<string>("familyFallback", this.fontFamilyFallback));
styles.Add(new DiagnosticsProperty<float?>("size", this.fontSize,
defaultValue: Diagnostics.kNullDefaultValue));
string weightDescription = "";
if (this.fontWeight != null) {
weightDescription = this.fontWeight.weightValue.ToString();
}
styles.Add(new DiagnosticsProperty<FontWeight>(
"weight", this.fontWeight,
description: weightDescription,
defaultValue: Diagnostics.kNullDefaultValue
));
styles.Add(new EnumProperty<FontStyle?>("style", this.fontStyle,
defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<float?>("height", this.height,
defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new FlagProperty("forceStrutHeight", value: this.forceStrutHeight,
defaultValue: Diagnostics.kNullDefaultValue));
bool styleSpecified = styles.Any((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info));
foreach (var style in styles) {
properties.add(style);
}
if (!styleSpecified) {
properties.add(new FlagProperty("forceStrutHeight", value: this.forceStrutHeight,
ifTrue: "<strut height forced>",
ifFalse: "<strut height normal>"));
}
}
}
}

11
Runtime/painting/strut_style.cs.meta


fileFormatVersion: 2
guid: 5ec5d77d67faf40bfaef77f14968228c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存