浏览代码

text widget

/main
fzhangtj 6 年前
当前提交
504c268e
共有 6 个文件被更改,包括 319 次插入4 次删除
  1. 27
      Assets/UIWidgets/foundation/diagnostics.cs
  2. 25
      Assets/UIWidgets/painting/text_span.cs
  3. 5
      Assets/UIWidgets/ui/txt/paragraph.cs
  4. 77
      Assets/UIWidgets/widgets/basic.cs
  5. 186
      Assets/UIWidgets/widgets/text.cs
  6. 3
      Assets/UIWidgets/widgets/text.cs.meta

27
Assets/UIWidgets/foundation/diagnostics.cs


}
}
public class IntProperty : _NumProperty<int?> {
public IntProperty(String name, int? value,
string ifNull = null,
bool showName = true,
string unit = null,
object defaultValue = null,
DiagnosticLevel level = DiagnosticLevel.info
) :base(name,
value,
ifNull: ifNull,
unit: unit,
defaultValue: defaultValue,
showName: showName,
level: level){
}
protected override string numberToString()
{
if (value == null)
{
return "null";
}
return value.ToString();
}
}
public class FlagProperty : DiagnosticsProperty<bool> {
public FlagProperty(String name,

25
Assets/UIWidgets/painting/text_span.cs


using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIWidgets.foundation;
using UIWidgets.ui;
using UnityEditor;
using UnityEngine.Assertions;

{
}
public class TextSpan: IEquatable<TextSpan>
public class TextSpan: DiagnosticableTree, IEquatable<TextSpan>
{
public delegate bool Visitor(TextSpan span);
public readonly TextStyle style;

return result;
}
string toPlainText()
public string toPlainText()
{
var sb = new StringBuilder();
visitTextSpan((span) =>

}
return left.SequenceEqual(right);
}
public override List<DiagnosticsNode> debugDescribeChildren() {
if (children == null)
{
return new List<DiagnosticsNode>();
}
return children.Select((child) =>
{
if (child != null)
{
return child.toDiagnosticsNode();
}
else
{
return DiagnosticsNode.message("<null child>");
}
}).ToList();
}
}
}

5
Assets/UIWidgets/ui/txt/paragraph.cs


_alphabeticBaseline = maxAscent;
_ideographicBaseline = maxAscent; // todo Properly implement ideographic_baseline
}
lastDescent = maxDescent;
yOffset = Utils.PixelCorrectRound(yOffset + maxAscent + lastDescent);
foreach (var record in linePaintRecords)
{

for (var charIndex = line.start; charIndex < line.end; charIndex++)
{
_characterPositions[charIndex].y = yOffset;
_characterPositions[charIndex].y = yOffset;
lastDescent = maxDescent;
}
}

77
Assets/UIWidgets/widgets/basic.cs


}
}
public class RichText : LeafRenderObjectWidget
{
public RichText(TextSpan text, Key key = null,
TextAlign textAlign = TextAlign.left, TextDirection? textDirection = null,
bool softWrap = true, TextOverflow overflow = TextOverflow.clip, double textScaleFactor = 1.0,
int maxLines = 0): base(key)
{
D.assert(text != null);
this.text = text;
this.textAlign = textAlign;
this.textDirection = textDirection;
this.softWrap = softWrap;
this.overflow = overflow;
this.textScaleFactor = textScaleFactor;
this.maxLines = maxLines;
}
public override RenderObject createRenderObject(BuildContext context) {
D.assert(textDirection != null || WidgetsD.debugCheckHasDirectionality(context));
return new RenderParagraph(text,
textAlign: textAlign,
textDirection: textDirection ?? Directionality.of(context),
softWrap: softWrap,
overflow: overflow,
textScaleFactor: textScaleFactor,
maxLines: maxLines
);
}
public override void updateRenderObject(BuildContext context, RenderObject r) {
D.assert(textDirection != null || WidgetsD.debugCheckHasDirectionality(context));
var renderObject = (RenderParagraph) (r);
renderObject.text = text;
renderObject.textAlign = textAlign;
renderObject.textDirection = textDirection ?? Directionality.of(context);
renderObject.softWrap = softWrap;
renderObject.overflow = overflow;
renderObject.textScaleFactor = textScaleFactor;
renderObject.maxLines = maxLines;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: TextAlign.left));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: null));
properties.add(new FlagProperty("softWrap", value: softWrap, ifTrue: "wrapping at box width", ifFalse: "no wrapping except at line break characters", showName: true));
properties.add(new EnumProperty<TextOverflow>("overflow", overflow, defaultValue: TextOverflow.clip));
properties.add(new DoubleProperty("textScaleFactor", textScaleFactor, defaultValue: 1.0));
properties.add(new IntProperty("maxLines", maxLines, ifNull: "unlimited"));
properties.add(new StringProperty("text", text.toPlainText()));
}
public readonly TextSpan text;
public readonly TextAlign textAlign;
public readonly TextDirection? textDirection;
public readonly bool softWrap;
public readonly TextOverflow overflow;
public readonly double textScaleFactor;
public readonly int maxLines;
}
public class RawImage : LeafRenderObjectWidget {
public RawImage(Key key, ui.Image image, double width, double height, double scale, Color color,

public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<bool>("ignoring", this.ignoring));
}
}
public class Builder : StatelessWidget
{
public Builder(WidgetBuilder builder, Key key = null) : base(key)
{
D.assert(builder != null);
this.builder = builder;
}
public readonly WidgetBuilder builder;
public override Widget build(BuildContext context)
{
return builder(context);
}
}
}

186
Assets/UIWidgets/widgets/text.cs


using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.painting;
using UIWidgets.rendering;
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,
bool softWrap = true,
TextOverflow overflow = TextOverflow.clip, Key key = null) : base(key, child)
{
D.assert(style != null);
D.assert(child != null);
this.style = style;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.maxLines = maxLines;
this.overflow = overflow;
}
public static DefaultTextStyle fallback()
{
return new DefaultTextStyle(new TextStyle(), null, TextAlign.left, 0, true,
TextOverflow.clip, null);
}
public static Widget merge(Key key, TextStyle style, TextAlign? textAlign,
bool? softWrap, TextOverflow? overflow, int? maxLines, Widget child)
{
D.assert(child != null);
return new Builder((context =>
{
var parent = DefaultTextStyle.of(context);
return new DefaultTextStyle(
key: key,
style: parent.style.merge(style),
textAlign: textAlign ?? parent.textAlign,
softWrap: softWrap ?? parent.softWrap,
overflow: overflow ?? parent.overflow,
maxLines: maxLines ?? parent.maxLines,
child: child
);
}));
}
public readonly TextStyle style;
public readonly TextAlign textAlign;
public readonly bool softWrap;
public readonly TextOverflow overflow;
public readonly int maxLines;
public static DefaultTextStyle of(BuildContext context)
{
var inherit = (DefaultTextStyle) context.inheritFromWidgetOfExactType(typeof(DefaultTextStyle));
return inherit ?? DefaultTextStyle.fallback();
}
public override bool updateShouldNotify(InheritedWidget w)
{
var oldWidget = (DefaultTextStyle) w;
return style != oldWidget.style ||
textAlign != oldWidget.textAlign ||
softWrap != oldWidget.softWrap ||
overflow != oldWidget.overflow ||
maxLines != oldWidget.maxLines;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
{
base.debugFillProperties(properties);
if (style != null)
{
style.debugFillProperties(properties);
}
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: null));
properties.add(new FlagProperty("softWrap", value: softWrap, ifTrue: "wrapping at box width",
ifFalse: "no wrapping except at line break characters", showName: true));
properties.add(new EnumProperty<TextOverflow>("overflow", overflow, defaultValue: null));
properties.add(new IntProperty("maxLines", maxLines, defaultValue: null));
}
}
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) : base(key)
{
D.assert(data != null);
this.textSpan = null;
this.data = data;
this.style = style;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.overflow = overflow;
this.textScaleFactor = textScaleFactor;
}
public Text(TextSpan textSpan, Key key = null, TextStyle style = null,
TextAlign? textAlign = null, bool? softWrap = null,
TextOverflow? overflow = null, double? textScaleFactor = null) : base(key)
{
D.assert(textSpan != null);
this.textSpan = textSpan;
this.data = null;
this.style = style;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.overflow = overflow;
this.textScaleFactor = textScaleFactor;
}
public readonly string data;
public readonly TextSpan textSpan;
public readonly TextStyle style;
public readonly TextAlign? textAlign;
public readonly TextDirection? textDirection;
public readonly bool? softWrap;
public readonly TextOverflow? overflow;
public readonly double? textScaleFactor;
public readonly int? maxLines;
public override Widget build(BuildContext context)
{
DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context);
TextStyle effectiveTextStyle = style;
if (style == null || style.inherit)
{
effectiveTextStyle = defaultTextStyle.style.merge(style);
}
return new RichText(
textAlign: textAlign ?? defaultTextStyle.textAlign,
textDirection: textDirection,
softWrap: softWrap ?? defaultTextStyle.softWrap,
overflow: overflow ?? defaultTextStyle.overflow,
textScaleFactor: textScaleFactor ?? 1.0, // MediaQuery.textScaleFactorOf(context), todo
maxLines: maxLines ?? defaultTextStyle.maxLines,
text: new TextSpan(
style: effectiveTextStyle,
text: data,
children: textSpan != null ? new List<TextSpan>() {textSpan} : null
)
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
{
base.debugFillProperties(properties);
properties.add(new StringProperty("data", data, showName: false));
if (textSpan != null)
{
properties.add(textSpan.toDiagnosticsNode(name: "textSpan", style: DiagnosticsTreeStyle.transition));
}
if (style != null)
{
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));
}
}
}

3
Assets/UIWidgets/widgets/text.cs.meta


fileFormatVersion: 2
guid: a0782677b6674b2fa33872f1d9bb36db
timeCreated: 1537576563
正在加载...
取消
保存