浏览代码

Merge pull request #172 from UnityTech/yczhang

Implement rotated box.
/main
GitHub 6 年前
当前提交
7a3d2cea
共有 3 个文件被更改,包括 156 次插入7 次删除
  1. 33
      Runtime/widgets/basic.cs
  2. 127
      Runtime/rendering/rotated_box.cs
  3. 3
      Runtime/rendering/rotated_box.cs.meta

33
Runtime/widgets/basic.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.Runtime.rendering;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;

public readonly float? stepHeight;
float? _stepWidth {
get {
return this.stepWidth == 0.0f ? null : this.stepWidth;
}
get { return this.stepWidth == 0.0f ? null : this.stepWidth; }
get {
return this.stepHeight == 0.0f ? null : this.stepHeight;
}
get { return this.stepHeight == 0.0f ? null : this.stepHeight; }
}
public override RenderObject createRenderObject(BuildContext context) {

properties.add(new FloatProperty("elevation", this.elevation));
properties.add(new DiagnosticsProperty<Color>("color", this.color));
properties.add(new DiagnosticsProperty<Color>("shadowColor", this.shadowColor));
}
}
public class RotatedBox : SingleChildRenderObjectWidget {
public RotatedBox(
Key key = null,
int? quarterTurns = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(quarterTurns != null);
this.quarterTurns = quarterTurns;
}
public readonly int? quarterTurns;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderRotatedBox(this.quarterTurns ?? 0);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
(renderObject as RenderRotatedBox).quarterTurns = this.quarterTurns ?? 0;
}
}

127
Runtime/rendering/rotated_box.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;
namespace UIWidgets.Runtime.rendering {
class RotatedBoxUtils {
public const float _kQuarterTurnsInRadians = Mathf.PI / 2.0f;
}
public class RenderRotatedBox : RenderObjectWithChildMixinRenderBox<RenderBox> {
public RenderRotatedBox(
int quarterTurns,
RenderBox child = null
) {
this.child = child;
this._quarterTurns = quarterTurns;
}
public int quarterTurns {
get { return this._quarterTurns; }
set {
if (this._quarterTurns == value) {
return;
}
this._quarterTurns = value;
this.markNeedsLayout();
}
}
int _quarterTurns;
bool _isVertical {
get { return this.quarterTurns % 2 == 1; }
}
protected override float computeMinIntrinsicWidth(float height) {
if (this.child == null) {
return 0.0f;
}
return this._isVertical
? this.child.getMinIntrinsicHeight(height)
: this.child.getMinIntrinsicWidth(height);
}
protected override float computeMaxIntrinsicWidth(float height) {
if (this.child == null) {
return 0.0f;
}
return this._isVertical
? this.child.getMaxIntrinsicHeight(height)
: this.child.getMaxIntrinsicWidth(height);
}
protected override float computeMinIntrinsicHeight(float width) {
if (this.child == null) {
return 0.0f;
}
return this._isVertical ? this.child.getMinIntrinsicWidth(width) : this.child.getMinIntrinsicHeight(width);
}
protected override float computeMaxIntrinsicHeight(float width) {
if (this.child == null) {
return 0.0f;
}
return this._isVertical ? this.child.getMaxIntrinsicWidth(width) : this.child.getMaxIntrinsicHeight(width);
}
Matrix3 _paintTransform;
protected override void performLayout() {
this._paintTransform = null;
if (this.child != null) {
this.child.layout(this._isVertical ? this.constraints.flipped : this.constraints, parentUsesSize: true);
this.size = this._isVertical
? new Size(this.child.size.height, this.child.size.width)
: this.child.size;
this._paintTransform = Matrix3.I();
this._paintTransform.preTranslate(this.size.width / 2.0f, this.size.height / 2.0f);
this._paintTransform.preRotate(RotatedBoxUtils._kQuarterTurnsInRadians * (this.quarterTurns % 4));
this._paintTransform.preTranslate(-this.child.size.width / 2.0f, -this.child.size.height / 2.0f);
}
else {
this.performResize();
}
}
protected override bool hitTestChildren(
HitTestResult result,
Offset position = null
) {
D.assert(this._paintTransform != null || this.debugNeedsLayout || this.child == null);
if (this.child == null || this._paintTransform == null) {
return false;
}
Matrix3 inverse = Matrix3.I();
this._paintTransform.invert(inverse);
return this.child.hitTest(result, position: inverse.mapPoint(position));
}
void _paintChild(PaintingContext context, Offset offset) {
context.paintChild(this.child, offset);
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
context.pushTransform(this.needsCompositing, offset, this._paintTransform, this._paintChild);
}
}
public override void applyPaintTransform(RenderObject child, Matrix3 transform) {
if (this._paintTransform != null) {
transform.preConcat(this._paintTransform);
}
base.applyPaintTransform(child, transform);
}
}
}

3
Runtime/rendering/rotated_box.cs.meta


fileFormatVersion: 2
guid: 057a0f3b94794fce9f9f3aa7bb624256
timeCreated: 1557210363
正在加载...
取消
保存