浏览代码

update text widgets.

/main
kg 6 年前
当前提交
dfc99075
共有 9 个文件被更改,包括 183 次插入144 次删除
  1. 13
      Assets/UIWidgets/Tests/Widgets.cs
  2. 19
      Assets/UIWidgets/foundation/diagnostics.cs
  3. 24
      Assets/UIWidgets/painting/text_style.cs
  4. 13
      Assets/UIWidgets/ui/text.cs
  5. 2
      Assets/UIWidgets/widgets/basic.cs
  6. 6
      Assets/UIWidgets/widgets/editable_text.cs
  7. 55
      Assets/UIWidgets/widgets/framework.cs
  8. 2
      Assets/UIWidgets/widgets/sliver.cs
  9. 193
      Assets/UIWidgets/widgets/text.cs

13
Assets/UIWidgets/Tests/Widgets.cs


double _offsetY = 0.0;
int _index = -1;
Widget _buildHeader(BuildContext context) {
return new Container(
padding: EdgeInsets.only(left: 16.0, right: 8.0),

)
);
}
setState(() => {
_offsetY = pixels / 2.0;
});
setState(() => { _offsetY = pixels / 2.0; });
setState(() => {
_offsetY = 0.0;
});
setState(() => { _offsetY = 0.0; });
return true;
}

19
Assets/UIWidgets/foundation/diagnostics.cs


}
}
public class FlagProperty : DiagnosticsProperty<bool> {
public FlagProperty(String name,
bool value,
public class FlagProperty : DiagnosticsProperty<bool?> {
public FlagProperty(string name,
bool? value,
string ifTrue = null,
string ifFalse = null,
bool showName = false,

public readonly string ifFalse;
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
if (this.value) {
if (this.value == true) {
} else if (!this.value) {
} else if (this.value == false) {
if (this.ifFalse != null) {
return this.ifFalse;
}

public override bool showName {
get {
if (this.value && this.ifTrue == null || !this.value == false && this.ifFalse == null) {
if (this.value == null || this.value == true && this.ifTrue == null || this.value == false && this.ifFalse == null) {
return true;
}

public override DiagnosticLevel level {
get {
if (this.value) {
if (this.value == true) {
if (!this.value) {
if (this.value == false) {
if (this.ifFalse == null) {
return DiagnosticLevel.hidden;
}

);
internal static readonly _NoDefaultValue kNoDefaultValue = new _NoDefaultValue();
internal static readonly _NullDefaultValue kNullDefaultValue = new _NullDefaultValue();
public static readonly object kNullDefaultValue = new _NullDefaultValue();
public static string shortHash(object o) {
return (o.GetHashCode() & 0xFFFFF).ToString("X").PadLeft(5, '0');

24
Assets/UIWidgets/painting/text_style.cs


base.debugFillProperties(properties);
List<DiagnosticsNode> styles = new List<DiagnosticsNode>();
styles.Add(new DiagnosticsProperty<Color>("color", color, defaultValue: null));
styles.Add(new StringProperty("family", fontFamily, defaultValue: null, quoted: false));
styles.Add(new DiagnosticsProperty<double?>("size", fontSize, defaultValue: null));
styles.Add(new DiagnosticsProperty<Color>("color", color, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new StringProperty("family", fontFamily, defaultValue: Diagnostics.kNullDefaultValue, quoted: false));
styles.Add(new DiagnosticsProperty<double?>("size", fontSize, defaultValue: Diagnostics.kNullDefaultValue));
string weightDescription = "";
if (fontWeight != null)
{

"weight",
fontWeight,
description: weightDescription,
defaultValue: null
defaultValue: Diagnostics.kNullDefaultValue
styles.Add(new EnumProperty<FontStyle?>("style", fontStyle, defaultValue: null));
styles.Add(new DiagnosticsProperty<double?>("letterSpacing", letterSpacing, defaultValue: null));
styles.Add(new DiagnosticsProperty<double?>("wordSpacing", wordSpacing, defaultValue: null));
styles.Add(new EnumProperty<TextBaseline?>("baseline", textBaseline, defaultValue: null));
styles.Add(new DiagnosticsProperty<double?>("height", height, defaultValue: null));
styles.Add(new StringProperty("background", background == null ? null : background.ToString(), defaultValue: null, quoted: false));
styles.Add(new EnumProperty<FontStyle?>("style", fontStyle, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<double?>("letterSpacing", letterSpacing, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<double?>("wordSpacing", wordSpacing, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new EnumProperty<TextBaseline?>("baseline", textBaseline, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<double?>("height", height, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new StringProperty("background", background == null ? null : background.ToString(), defaultValue: Diagnostics.kNullDefaultValue, quoted: false));
if (decoration != null)
{
List<string> decorationDescription = new List<string>();

}
styles.Add(new DiagnosticsProperty<Color>("decorationColor", decorationColor, defaultValue: null,
styles.Add(new DiagnosticsProperty<Color>("decorationColor", decorationColor, defaultValue: Diagnostics.kNullDefaultValue,
level: DiagnosticLevel.fine));
if (decorationColor != null)
{

styles.Add(new DiagnosticsProperty<TextDecoration>("decoration", decoration, defaultValue: null,
styles.Add(new DiagnosticsProperty<TextDecoration>("decoration", decoration, defaultValue: Diagnostics.kNullDefaultValue,
level: DiagnosticLevel.hidden));
if (decoration != null)
decorationDescription.Add("$decoration");

13
Assets/UIWidgets/ui/text.cs


{
public enum FontStyle
{
/// Use the upright glyphs
/// Use glyphs designed for slanting
italic,
}

public enum TextAlign
{
/// Align the text on the left edge of the container.
/// Align the text on the right edge of the container.
/// Align the text in the center of the container.
/// Stretch lines of text that end with a soft line break to fill the width of
/// the container.
///
/// Lines that end with hard line breaks are aligned towards the [start] edge.
justify,
}

2
Assets/UIWidgets/widgets/basic.cs


}
}
public class Flexible : ParentDataWidget {
public class Flexible : ParentDataWidget<Flex> {
public Flexible(
Key key = null,
int flex = 1,

6
Assets/UIWidgets/widgets/editable_text.cs


{
style.debugFillProperties(properties);
}
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: null));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: null));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor, defaultValue: null));
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<int>("maxLines", maxLines, defaultValue: 1));
properties.add(new DiagnosticsProperty<bool>("autofocus", autofocus, defaultValue: false));
}

55
Assets/UIWidgets/widgets/framework.cs


: base(key: key, child: child) {
}
public abstract bool debugIsValidAncestor(RenderObjectWidget ancestor);
public abstract string debugDescribeInvalidAncestorChain(
string description = null,
string ownershipChain = null,
bool foundValidAncestor = false,
IEnumerable<Widget> badAncestors = null
);
public abstract void applyParentData(RenderObject renderObject);
public virtual bool debugCanApplyOutOfTurn() {
return false;
}
}
public abstract class ParentDataWidget<T> : ParentDataWidget where T : RenderObjectWidget {
public ParentDataWidget(Key key = null, Widget child = null)
: base(key: key, child: child) {
}
public virtual bool debugIsValidAncestor(RenderObjectWidget ancestor) {
return ancestor is RenderObjectWidget;
public override bool debugIsValidAncestor(RenderObjectWidget ancestor) {
D.assert(typeof(T) != typeof(RenderObjectWidget));
return ancestor is T;
public virtual string debugDescribeInvalidAncestorChain(
String description = null, String ownershipChain = null, bool foundValidAncestor = false,
public override string debugDescribeInvalidAncestorChain(
string description = null,
string ownershipChain = null,
bool foundValidAncestor = false,
String result;
D.assert(typeof(T) != typeof(RenderObjectWidget));
string result;
result = string.Format("{0} widgets must be placed inside {1} widgets.\n" +
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(RenderObjectWidget), description);
result = string.Format(
"{0} widgets must be placed inside {1} widgets.\n" +
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(T), description);
result = string.Format("{0} widgets must be placed directly inside {1} widgets.\n" +
result = string.Format(
"{0} widgets must be placed directly inside {1} widgets.\n" +
this.GetType(), typeof(RenderObjectWidget), description);
this.GetType(), typeof(T), description);
foreach (Widget ancestor in badAncestors) {
if (ancestor.GetType() == this.GetType()) {

}
}
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(RenderObjectWidget) + ".\n";
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(T) + ".\n";
}
result += "The ownership chain for the parent of the offending "

public abstract void applyParentData(RenderObject renderObject);
public virtual bool debugCanApplyOutOfTurn() {
return false;
}
public abstract class InheritedWidget : ProxyWidget {
protected InheritedWidget(Key key = null, Widget child = null) : base(key, child) {

2
Assets/UIWidgets/widgets/sliver.cs


}
}
public class KeepAlive : ParentDataWidget{
public class KeepAlive : ParentDataWidget<SliverMultiBoxAdaptorWidget> {
public KeepAlive(
Key key = null,
bool keepAlive = true,

193
Assets/UIWidgets/widgets/text.cs


using UIWidgets.ui;
using TextStyle = UIWidgets.painting.TextStyle;
namespace UIWidgets.widgets
{
public class DefaultTextStyle : InheritedWidget
{
public DefaultTextStyle(TextStyle style, Widget child,
TextAlign textAlign, int maxLines = 0,
namespace UIWidgets.widgets {
public class DefaultTextStyle : InheritedWidget {
public DefaultTextStyle(
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
TextOverflow overflow = TextOverflow.clip, Key key = null) : base(key, child)
{
TextOverflow overflow = TextOverflow.clip,
int? maxLines = null,
Widget child = null
) : base(key, child) {
D.assert(maxLines == null || maxLines > 0);
this.overflow = overflow;
this.overflow = overflow;
}
private DefaultTextStyle() {
this.style = new TextStyle();
this.textAlign = null;
this.softWrap = true;
this.overflow = TextOverflow.clip;
this.maxLines = null;
public static DefaultTextStyle fallback()
{
return new DefaultTextStyle(new TextStyle(), null, TextAlign.left, 0, true,
TextOverflow.clip, null);
public static DefaultTextStyle fallback() {
return new DefaultTextStyle();
public static Widget merge(Key key, TextStyle style, TextAlign? textAlign,
bool? softWrap, TextOverflow? overflow, int? maxLines, Widget child)
{
public static Widget merge(
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
int? maxLines = null,
Widget child = null
) {
return new Builder(builder: (context =>
{
return new Builder(builder: (context => {
var parent = DefaultTextStyle.of(context);
return new DefaultTextStyle(
key: key,

}
public readonly TextStyle style;
public readonly TextAlign textAlign;
public readonly TextAlign? textAlign;
public readonly int maxLines;
public readonly int? maxLines;
public static DefaultTextStyle of(BuildContext context)
{
public static DefaultTextStyle of(BuildContext context) {
public override bool updateShouldNotify(InheritedWidget w)
{
public override bool updateShouldNotify(InheritedWidget w) {
return style != oldWidget.style ||
textAlign != oldWidget.textAlign ||
softWrap != oldWidget.softWrap ||
overflow != oldWidget.overflow ||
maxLines != oldWidget.maxLines;
return this.style != oldWidget.style ||
this.textAlign != oldWidget.textAlign ||
this.softWrap != oldWidget.softWrap ||
this.overflow != oldWidget.overflow ||
this.maxLines != oldWidget.maxLines;
public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
{
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
if (style != null)
{
style.debugFillProperties(properties);
if (this.style != null) {
this.style.debugFillProperties(properties);
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: null));
properties.add(new FlagProperty("softWrap", value: softWrap, ifTrue: "wrapping at box width",
properties.add(new EnumProperty<TextAlign?>("textAlign", this.textAlign,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new FlagProperty("softWrap", value: this.softWrap, ifTrue: "wrapping at box width",
properties.add(new EnumProperty<TextOverflow>("overflow", overflow, defaultValue: null));
properties.add(new IntProperty("maxLines", maxLines, defaultValue: null));
properties.add(new EnumProperty<TextOverflow>("overflow", this.overflow,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new IntProperty("maxLines", this.maxLines,
defaultValue: Diagnostics.kNullDefaultValue));
public class Text : StatelessWidget
{
public Text(string data, Key key = null, TextStyle style = null,
TextAlign? textAlign = null, bool? softWrap = null,
TextOverflow? overflow = null, double? textScaleFactor = null, int? maxLines = null) : base(key)
{
public class Text : StatelessWidget {
public Text(string data,
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
double? textScaleFactor = null,
int? maxLines = null) : base(key) {
D.assert(data != null);
this.textSpan = null;
this.data = data;

this.maxLines = maxLines;
}
public Text(TextSpan textSpan, Key key = null, TextStyle style = null,
TextAlign? textAlign = null, bool? softWrap = null,
TextOverflow? overflow = null, double? textScaleFactor = null, int? maxLines = null) : base(key)
{
private Text(TextSpan textSpan,
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
double? textScaleFactor = null,
int? maxLines = null) : base(key) {
D.assert(textSpan != null);
this.textSpan = textSpan;
this.data = null;

this.maxLines = maxLines;
}
public static Text rich(TextSpan textSpan,
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
double? textScaleFactor = null,
int? maxLines = null) {
return new Text(
textSpan, key,
style,
textAlign,
softWrap,
overflow,
textScaleFactor,
maxLines);
}
public readonly string data;
public readonly TextSpan textSpan;

public readonly TextAlign? textAlign;
public readonly TextDirection? textDirection;
public readonly bool? softWrap;
public readonly TextOverflow? overflow;

public readonly int? maxLines;
public override Widget build(BuildContext context)
{
public override Widget build(BuildContext context) {
TextStyle effectiveTextStyle = style;
if (style == null || style.inherit)
{
effectiveTextStyle = defaultTextStyle.style.merge(style);
TextStyle effectiveTextStyle = this.style;
if (this.style == null || this.style.inherit) {
effectiveTextStyle = defaultTextStyle.style.merge(this.style);
textAlign: textAlign ?? defaultTextStyle.textAlign,
softWrap: softWrap ?? defaultTextStyle.softWrap,
overflow: overflow ?? defaultTextStyle.overflow,
textScaleFactor: textScaleFactor ?? 1.0, // MediaQuery.textScaleFactorOf(context), todo
maxLines: maxLines ?? defaultTextStyle.maxLines,
textAlign: this.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
softWrap: this.softWrap ?? defaultTextStyle.softWrap,
overflow: this.overflow ?? defaultTextStyle.overflow,
textScaleFactor: this.textScaleFactor ?? 1.0, // MediaQuery.textScaleFactorOf(context), todo
maxLines: this.maxLines ?? defaultTextStyle.maxLines,
text: data,
children: textSpan != null ? new List<TextSpan>() {textSpan} : null
text: this.data,
children: this.textSpan != null ? new List<TextSpan> {this.textSpan} : null
public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
{
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
properties.add(new StringProperty("data", data, showName: false));
if (textSpan != null)
{
properties.add(textSpan.toDiagnosticsNode(name: "textSpan", style: DiagnosticsTreeStyle.transition));
properties.add(new StringProperty("data", this.data, showName: false));
if (this.textSpan != null) {
properties.add(this.textSpan.toDiagnosticsNode(name: "textSpan", style: DiagnosticsTreeStyle.transition));
if (style != null)
{
style.debugFillProperties(properties);
if (this.style != null) {
this.style.debugFillProperties(properties);
properties.add(new EnumProperty<TextAlign?>("textAlign", textAlign, defaultValue: null));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: null));
properties.add(new FlagProperty("softWrap", value: softWrap ?? false, ifTrue: "wrapping at box width",
ifFalse: "no wrapping except at line break characters", showName: true)); // todo ObjectFlagProperty
properties.add(new EnumProperty<TextOverflow?>("overflow", overflow, defaultValue: null));
properties.add(new DoubleProperty("textScaleFactor", textScaleFactor, defaultValue: null));
properties.add(new IntProperty("maxLines", maxLines, defaultValue: null));
properties.add(new EnumProperty<TextAlign?>("textAlign", this.textAlign,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new FlagProperty("softWrap", value: this.softWrap, ifTrue: "wrapping at box width",
ifFalse: "no wrapping except at line break characters", showName: true));
properties.add(new EnumProperty<TextOverflow?>("overflow", this.overflow,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DoubleProperty("textScaleFactor", this.textScaleFactor,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new IntProperty("maxLines", this.maxLines, defaultValue: Diagnostics.kNullDefaultValue));
}
}
}
正在加载...
取消
保存