浏览代码

some updates.

/main
kg 6 年前
当前提交
8ebc1ef6
共有 7 个文件被更改,包括 785 次插入1 次删除
  1. 13
      Assets/UIWidgets/rendering/box.cs
  2. 2
      Assets/UIWidgets/rendering/object.cs
  3. 12
      Assets/UIWidgets/ui/geometry.cs
  4. 629
      Assets/UIWidgets/rendering/shifted_box.cs
  5. 3
      Assets/UIWidgets/rendering/shifted_box.cs.meta
  6. 124
      Assets/UIWidgets/rendering/stack.cs
  7. 3
      Assets/UIWidgets/rendering/stack.cs.meta

13
Assets/UIWidgets/rendering/box.cs


);
}
public BoxConstraints deflate(EdgeInsets edges) {
double horizontal = edges.horizontal;
double vertical = edges.vertical;
double deflatedMinWidth = Math.Max(0.0, this.minWidth - horizontal);
double deflatedMinHeight = Math.Max(0.0, this.minHeight - vertical);
return new BoxConstraints(
minWidth: deflatedMinWidth,
maxWidth: Math.Max(deflatedMinWidth, this.maxWidth - horizontal),
minHeight: deflatedMinHeight,
maxHeight: Math.Max(deflatedMinHeight, this.maxHeight - vertical)
);
}
public BoxConstraints loosen() {
return new BoxConstraints(
minWidth: 0.0,

2
Assets/UIWidgets/rendering/object.cs


this.markNeedsPaint();
}
public bool sizedByParent {
public virtual bool sizedByParent {
get { return false; }
}

12
Assets/UIWidgets/ui/geometry.cs


get { return this.width <= 0.0 || this.height <= 0.0; }
}
public static Size operator +(Size a, Offset b) {
return new Size(a.width + b.dx, a.height + b.dy);
}
public static Size operator -(Size a, Offset b) {
return new Size(a.width - b.dx, a.height - b.dy);
}
public static Offset operator -(Size a, Size b) {
return new Offset(a.width - b.width, a.height - b.width);
}
public static Size operator *(Size a, double operand) {
return new Size(a.width * operand, a.height * operand);
}

629
Assets/UIWidgets/rendering/shifted_box.cs


using System;
using UIWidgets.painting;
using UIWidgets.ui;
namespace UIWidgets.rendering {
public abstract class RenderShiftedBox : RenderObjectWithChildMixinRenderBox<RenderBox> {
protected RenderShiftedBox(RenderBox child) {
this.child = child;
}
public override double computeMinIntrinsicWidth(double height) {
if (this.child != null) {
return this.child.getMinIntrinsicWidth(height);
}
return 0.0;
}
public override double computeMaxIntrinsicWidth(double height) {
if (this.child != null) {
return this.child.getMaxIntrinsicWidth(height);
}
return 0.0;
}
public override double computeMinIntrinsicHeight(double width) {
if (this.child != null) {
return this.child.getMinIntrinsicHeight(width);
}
return 0.0;
}
public override double computeMaxIntrinsicHeight(double width) {
if (this.child != null) {
return this.child.getMaxIntrinsicHeight(width);
}
return 0.0;
}
public override double? computeDistanceToActualBaseline(TextBaseline baseline) {
double? result;
if (this.child != null) {
result = this.child.getDistanceToActualBaseline(baseline);
if (result != null) {
var childParentData = (BoxParentData) this.child.parentData;
result += childParentData.offset.dy;
}
} else {
result = base.computeDistanceToActualBaseline(baseline);
}
return result;
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
var childParentData = (BoxParentData) this.child.parentData;
context.paintChild(this.child, childParentData.offset + offset);
}
}
}
public class RenderPadding : RenderShiftedBox {
RenderPadding(
EdgeInsets padding = null,
RenderBox child = null
) : base(child) {
this._padding = padding;
}
public EdgeInsets padding {
get { return this._padding; }
set {
if (this._padding == value) {
return;
}
this._padding = value;
this.markNeedsLayout();
}
}
public EdgeInsets _padding;
public override double computeMinIntrinsicWidth(double height) {
if (this.child != null) {
return this.child.getMinIntrinsicWidth(Math.Max(0.0, height - this._padding.vertical)) +
this._padding.horizontal;
}
return this._padding.horizontal;
}
public override double computeMaxIntrinsicWidth(double height) {
if (this.child != null) {
return this.child.getMaxIntrinsicWidth(Math.Max(0.0, height - this._padding.vertical)) +
this._padding.horizontal;
}
return this._padding.horizontal;
}
public override double computeMinIntrinsicHeight(double width) {
if (this.child != null) {
return this.child.getMinIntrinsicHeight(Math.Max(0.0, width - this._padding.horizontal)) +
this._padding.vertical;
}
return this._padding.vertical;
}
public override double computeMaxIntrinsicHeight(double width) {
if (this.child != null) {
return this.child.getMaxIntrinsicHeight(Math.Max(0.0, width - this._padding.horizontal)) +
this._padding.vertical;
}
return this._padding.vertical;
}
public override void performLayout() {
if (this.child == null) {
this.size = this.constraints.constrain(this._padding.inflateSize(Size.zero));
return;
}
var innerConstraints = this.constraints.deflate(this._padding);
this.child.layout(innerConstraints, parentUsesSize: true);
var childParentData = (BoxParentData) this.child.parentData;
childParentData.offset = this._padding.topLeft;
this.size = this.constraints.constrain(this._padding.inflateSize(this.child.size));
}
}
public abstract class RenderAligningShiftedBox : RenderShiftedBox {
protected RenderAligningShiftedBox(
Alignment alignment = null,
RenderBox child = null
) : base(child) {
this._alignment = alignment ?? Alignment.center;
}
public Alignment alignment {
get { return this._alignment; }
set {
if (this._alignment == value) {
return;
}
this._alignment = value;
this.markNeedsLayout();
}
}
public Alignment _alignment;
protected void alignChild() {
var childParentData = (BoxParentData) this.child.parentData;
childParentData.offset = this._alignment.alongOffset(this.size - this.child.size);
}
}
public class RenderPositionedBox : RenderAligningShiftedBox {
public RenderPositionedBox(
RenderBox child = null,
double? widthFactor = null,
double? heightFactor = null,
Alignment alignment = null
) : base(alignment, child) {
this._widthFactor = widthFactor;
this._heightFactor = heightFactor;
}
public double? widthFactor {
get { return this._widthFactor; }
set {
if (this._widthFactor == value) {
return;
}
this._widthFactor = value;
this.markNeedsLayout();
}
}
public double? _widthFactor;
public double? heightFactor {
get { return this._heightFactor; }
set {
if (this._heightFactor == value) {
return;
}
this._heightFactor = value;
this.markNeedsLayout();
}
}
public double? _heightFactor;
public override void performLayout() {
bool shrinkWrapWidth = this._widthFactor != null || double.IsPositiveInfinity(this.constraints.maxWidth);
bool shrinkWrapHeight = this._heightFactor != null || double.IsPositiveInfinity(this.constraints.maxHeight);
if (this.child != null) {
this.child.layout(this.constraints.loosen(), parentUsesSize: true);
this.size = this.constraints.constrain(new Size(
shrinkWrapWidth ? this.child.size.width * (this._widthFactor ?? 1.0) : double.PositiveInfinity,
shrinkWrapHeight ? this.child.size.height * (this._heightFactor ?? 1.0) : double.PositiveInfinity));
this.alignChild();
} else {
this.size = this.constraints.constrain(new Size(
shrinkWrapWidth ? 0.0 : double.PositiveInfinity,
shrinkWrapHeight ? 0.0 : double.PositiveInfinity));
}
}
}
public class RenderConstrainedOverflowBox : RenderAligningShiftedBox {
public RenderConstrainedOverflowBox(
RenderBox child = null,
double? minWidth = null,
double? maxWidth = null,
double? minHeight = null,
double? maxHeight = null,
Alignment alignment = null
) : base(alignment, child) {
this._minWidth = minWidth;
this._maxWidth = maxWidth;
this._minHeight = minHeight;
this._maxHeight = maxHeight;
}
public double? minWidth {
get { return this._minWidth; }
set {
if (this._minWidth == value) {
return;
}
this._minWidth = value;
this.markNeedsLayout();
}
}
public double? _minWidth;
public double? maxWidth {
get { return this._maxWidth; }
set {
if (this._maxWidth == value) {
return;
}
this._maxWidth = value;
this.markNeedsLayout();
}
}
public double? _maxWidth;
public double? minHeight {
get { return this._minHeight; }
set {
if (this._minHeight == value) {
return;
}
this._minHeight = value;
this.markNeedsLayout();
}
}
public double? _minHeight;
public double? maxHeight {
get { return this._maxHeight; }
set {
if (this._maxHeight == value) {
return;
}
this._maxHeight = value;
this.markNeedsLayout();
}
}
public double? _maxHeight;
public BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
return new BoxConstraints(
minWidth: this._minWidth ?? constraints.minWidth,
maxWidth: this._maxWidth ?? constraints.maxWidth,
minHeight: this._minHeight ?? constraints.minHeight,
maxHeight: this._maxHeight ?? constraints.maxHeight
);
}
public override bool sizedByParent {
get { return true; }
}
public override void performResize() {
this.size = this.constraints.biggest;
}
public override void performLayout() {
if (this.child != null) {
this.child.layout(this._getInnerConstraints(this.constraints), parentUsesSize: true);
this.alignChild();
}
}
}
public class RenderUnconstrainedBox : RenderAligningShiftedBox {
public RenderUnconstrainedBox(
Alignment alignment = null,
Axis? constrainedAxis = null,
RenderBox child = null
) : base(alignment, child) {
this._constrainedAxis = constrainedAxis;
}
public Axis? constrainedAxis {
get { return this._constrainedAxis; }
set {
if (this._constrainedAxis == value) {
return;
}
this._constrainedAxis = value;
this.markNeedsLayout();
}
}
public Axis? _constrainedAxis;
public Rect _overflowContainerRect = Rect.zero;
public Rect _overflowChildRect = Rect.zero;
public bool _isOverflowing = false;
public override void performLayout() {
if (this.child != null) {
BoxConstraints childConstraints = null;
if (this.constrainedAxis != null) {
switch (this.constrainedAxis) {
case Axis.horizontal:
childConstraints = new BoxConstraints(
maxWidth: this.constraints.maxWidth,
minWidth: this.constraints.minWidth);
break;
case Axis.vertical:
childConstraints = new BoxConstraints(
maxHeight: this.constraints.maxHeight,
minHeight: this.constraints.minHeight);
break;
}
} else {
childConstraints = new BoxConstraints();
}
this.child.layout(childConstraints, parentUsesSize: true);
this.size = this.constraints.constrain(this.child.size);
this.alignChild();
var childParentData = (BoxParentData) child.parentData;
this._overflowContainerRect = Offset.zero & this.size;
this._overflowChildRect = childParentData.offset & this.child.size;
} else {
this.size = this.constraints.smallest;
this._overflowContainerRect = Rect.zero;
this._overflowChildRect = Rect.zero;
}
this._isOverflowing = RelativeRect.fromRect(
this._overflowContainerRect, this._overflowChildRect).hasInsets;
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child == null || this.size.isEmpty) {
return;
}
if (!this._isOverflowing) {
base.paint(context, offset);
return;
}
context.pushClipRect(this.needsCompositing, offset, Offset.zero & this.size, base.paint);
}
}
public class RenderSizedOverflowBox : RenderAligningShiftedBox {
public RenderSizedOverflowBox(
RenderBox child = null,
Size requestedSize = null,
Alignment alignment = null
) : base(alignment, child) {
this._requestedSize = requestedSize;
}
public Size requestedSize {
get { return this._requestedSize; }
set {
if (this._requestedSize == value) {
return;
}
this._requestedSize = value;
this.markNeedsLayout();
}
}
public Size _requestedSize;
public override double computeMinIntrinsicWidth(double height) {
return this._requestedSize.width;
}
public override double computeMaxIntrinsicWidth(double height) {
return this._requestedSize.width;
}
public override double computeMinIntrinsicHeight(double width) {
return this._requestedSize.height;
}
public override double computeMaxIntrinsicHeight(double width) {
return this._requestedSize.height;
}
public override double? computeDistanceToActualBaseline(TextBaseline baseline) {
if (this.child != null) {
return this.child.getDistanceToActualBaseline(baseline);
}
return base.computeDistanceToActualBaseline(baseline);
}
public override void performLayout() {
this.size = this.constraints.constrain(this._requestedSize);
if (this.child != null) {
this.child.layout(this.constraints);
this.alignChild();
}
}
}
public class RenderFractionallySizedOverflowBox : RenderAligningShiftedBox {
public RenderFractionallySizedOverflowBox(
RenderBox child = null,
double? widthFactor = null,
double? heightFactor = null,
Alignment alignment = null
) : base(alignment, child) {
this._widthFactor = widthFactor;
this._heightFactor = heightFactor;
}
public double? widthFactor {
get { return this._widthFactor; }
set {
if (this._widthFactor != value) {
return;
}
this._widthFactor = value;
this.markNeedsLayout();
}
}
public double? _widthFactor;
public double? heightFactor {
get { return this._heightFactor; }
set {
if (this._heightFactor != value) {
return;
}
this._heightFactor = value;
this.markNeedsLayout();
}
}
public double? _heightFactor;
public BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
double minWidth = constraints.minWidth;
double maxWidth = constraints.maxWidth;
if (this._widthFactor != null) {
double width = maxWidth * this._widthFactor.Value;
minWidth = width;
maxWidth = width;
}
double minHeight = constraints.minHeight;
double maxHeight = constraints.maxHeight;
if (this._heightFactor != null) {
double height = maxHeight * this._heightFactor.Value;
minHeight = height;
maxHeight = height;
}
return new BoxConstraints(
minWidth: minWidth,
maxWidth: maxWidth,
minHeight: minHeight,
maxHeight: maxHeight
);
}
public override double computeMinIntrinsicWidth(double height) {
double result;
if (this.child == null) {
result = base.computeMinIntrinsicWidth(height);
} else {
result = this.child.getMinIntrinsicWidth(height * (this._heightFactor ?? 1.0));
}
return result / (this._widthFactor ?? 1.0);
}
public override double computeMaxIntrinsicWidth(double height) {
double result;
if (this.child == null) {
result = base.computeMaxIntrinsicWidth(height);
} else {
result = this.child.getMaxIntrinsicWidth(height * (this._heightFactor ?? 1.0));
}
return result / (this._widthFactor ?? 1.0);
}
public override double computeMinIntrinsicHeight(double width) {
double result;
if (this.child == null) {
result = base.computeMinIntrinsicHeight(width);
} else {
result = this.child.getMinIntrinsicHeight(width * (this._widthFactor ?? 1.0));
}
return result / (this._heightFactor ?? 1.0);
}
public override double computeMaxIntrinsicHeight(double width) {
double result;
if (this.child == null) {
result = base.computeMaxIntrinsicHeight(width);
} else {
result = this.child.getMaxIntrinsicHeight(width * (this._widthFactor ?? 1.0));
}
return result / (this._heightFactor ?? 1.0);
}
public override void performLayout() {
if (this.child != null) {
this.child.layout(this._getInnerConstraints(this.constraints), parentUsesSize: true);
this.size = this.constraints.constrain(this.child.size);
this.alignChild();
} else {
this.size = this.constraints.constrain(
this._getInnerConstraints(this.constraints).constrain(Size.zero));
}
}
}
public class RenderBaseline : RenderShiftedBox {
public RenderBaseline(
RenderBox child = null,
double baseline = 0.0,
TextBaseline baselineType = TextBaseline.alphabetic
) : base(child) {
this._baseline = baseline;
this._baselineType = baselineType;
}
public double baseline {
get { return this._baseline; }
set {
if (this._baseline != value) {
return;
}
this._baseline = value;
this.markNeedsLayout();
}
}
public double _baseline;
public TextBaseline baselineType {
get { return this._baselineType; }
set {
if (this._baselineType != value) {
return;
}
this._baselineType = value;
this.markNeedsLayout();
}
}
public TextBaseline _baselineType;
public override void performLayout() {
if (this.child != null) {
this.child.layout(this.constraints.loosen(), parentUsesSize: true);
double? childBaseline = this.child.getDistanceToBaseline(this.baselineType);
double actualBaseline = this.baseline;
double top = actualBaseline - childBaseline.Value;
var childParentData = (BoxParentData) child.parentData;
childParentData.offset = new Offset(0.0, top);
Size childSize = this.child.size;
this.size = this.constraints.constrain(new Size(childSize.width, top + childSize.height));
} else {
this.performResize();
}
}
}
}

3
Assets/UIWidgets/rendering/shifted_box.cs.meta


fileFormatVersion: 2
guid: 44ca0b36c9844abfbed7a60e76c5391e
timeCreated: 1535007022

124
Assets/UIWidgets/rendering/stack.cs


using System;
using UIWidgets.ui;
namespace UIWidgets.rendering {
public class RelativeRect : IEquatable<RelativeRect> {
private RelativeRect(double left, double top, double right, double bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public readonly double left;
public readonly double top;
public readonly double right;
public readonly double bottom;
public static RelativeRect fromLTRB(double left, double top, double right, double bottom) {
return new RelativeRect(left, top, right, bottom);
}
public static RelativeRect fromSize(Rect rect, Size container) {
return new RelativeRect(
rect.left,
rect.top,
container.width - rect.right,
container.height - rect.bottom);
}
public static RelativeRect fromRect(Rect rect, Rect container) {
return RelativeRect.fromLTRB(
rect.left - container.left,
rect.top - container.top,
container.right - rect.right,
container.bottom - rect.bottom
);
}
public static readonly RelativeRect fill = RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0);
public bool hasInsets {
get { return this.left > 0.0 || this.top > 0.0 || this.right > 0.0 || this.bottom > 0.0; }
}
public RelativeRect shift(Offset offset) {
return RelativeRect.fromLTRB(
this.left + offset.dx,
this.top + offset.dy,
this.right - offset.dx,
this.bottom - offset.dy);
}
public RelativeRect inflate(double delta) {
return RelativeRect.fromLTRB(
this.left - delta,
this.top - delta,
this.right - delta,
this.bottom - delta);
}
public RelativeRect deflate(double delta) {
return this.inflate(-delta);
}
public RelativeRect intersect(RelativeRect other) {
return RelativeRect.fromLTRB(
Math.Max(this.left, other.left),
Math.Max(this.top, other.top),
Math.Max(this.right, other.right),
Math.Max(this.bottom, other.bottom)
);
}
public Rect toRect(Rect container) {
return Rect.fromLTRB(
this.left + container.left,
this.top + container.top,
container.right - this.right,
container.bottom - this.bottom);
}
public Rect toSize(Size container) {
return Rect.fromLTRB(
this.left,
this.top,
container.width - this.right,
container.height - this.bottom);
}
public bool Equals(RelativeRect other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return this.left.Equals(other.left)
&& this.top.Equals(other.top)
&& this.right.Equals(other.right)
&& this.bottom.Equals(other.bottom);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((RelativeRect) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.left.GetHashCode();
hashCode = (hashCode * 397) ^ this.top.GetHashCode();
hashCode = (hashCode * 397) ^ this.right.GetHashCode();
hashCode = (hashCode * 397) ^ this.bottom.GetHashCode();
return hashCode;
}
}
public static bool operator ==(RelativeRect a, RelativeRect b) {
return object.Equals(a, b);
}
public static bool operator !=(RelativeRect a, RelativeRect b) {
return !(a == b);
}
}
}

3
Assets/UIWidgets/rendering/stack.cs.meta


fileFormatVersion: 2
guid: cb21eea13f0f4663bdcf7d8679d90133
timeCreated: 1535009723
正在加载...
取消
保存