浏览代码

Merge branch 'dev' of github.com:UnityTech/UIWidgets into fix_raster_cache_assert

/main
xingwei.zhu 5 年前
当前提交
b8db6773
共有 6 个文件被更改,包括 68 次插入536 次删除
  1. 96
      Runtime/cupertino/date_picker.cs
  2. 2
      Runtime/cupertino/localization.cs
  3. 119
      Runtime/cupertino/picker.cs
  4. 356
      Runtime/painting/matrix_utils.cs
  5. 26
      Runtime/service/text_formatter.cs
  6. 5
      Runtime/widgets/scroll_physics.cs

96
Runtime/cupertino/date_picker.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.cupertino {
class CupertinoDatePickerUtils {
static class CupertinoDatePickerUtils {
public const float _kItemExtent = 32.0f;
public const float _kPickerWidth = 330.0f;
public const bool _kUseMagnifier = true;

public class _DatePickerLayoutDelegate : MultiChildLayoutDelegate {
public _DatePickerLayoutDelegate(
List<float> columnWidths,
int textDirectionFactor
List<float> columnWidths
this.textDirectionFactor = textDirectionFactor;
public readonly int textDirectionFactor;
public override void performLayout(Size size) {
float remainingWidth = size.width;

float currentHorizontalOffset = 0.0f;
for (int i = 0; i < this.columnWidths.Count; i++) {
int index = this.textDirectionFactor == 1 ? i : this.columnWidths.Count - i - 1;
float childWidth = this.columnWidths[index] + CupertinoDatePickerUtils._kDatePickerPadSize * 2;
if (index == 0 || index == this.columnWidths.Count - 1) {
float childWidth = this.columnWidths[i] + CupertinoDatePickerUtils._kDatePickerPadSize * 2;
if (i == 0 || i == this.columnWidths.Count - 1) {
this.layoutChild(index, BoxConstraints.tight(new Size(childWidth, size.height)));
this.positionChild(index, new Offset(currentHorizontalOffset, 0.0f));
this.layoutChild(i, BoxConstraints.tight(new Size(childWidth, size.height)));
this.positionChild(i, new Offset(currentHorizontalOffset, 0.0f));
return this.columnWidths != ((_DatePickerLayoutDelegate) oldDelegate).columnWidths
|| this.textDirectionFactor != ((_DatePickerLayoutDelegate) oldDelegate).textDirectionFactor;
return this.columnWidths != ((_DatePickerLayoutDelegate) oldDelegate).columnWidths;
}
}

text: new TextSpan(
style: DefaultTextStyle.of(context).style,
text: longestText
),
textDirection: Directionality.of(context)
)
);

delegate Widget _ColumnBuilder(float offAxisFraction, TransitionBuilder itemPositioningBuilder);
class _CupertinoDatePickerDateTimeState : State<CupertinoDatePicker> {
public int textDirectionFactor;
public CupertinoLocalizations localizations;
public Alignment alignCenterLeft;
public Alignment alignCenterRight;

public override void didChangeDependencies() {
base.didChangeDependencies();
this.textDirectionFactor = Directionality.of(this.context) == TextDirection.ltr ? 1 : -1;
this.alignCenterLeft = this.textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight;
this.alignCenterRight = this.textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft;
this.alignCenterLeft = Alignment.centerLeft;
this.alignCenterRight = Alignment.centerRight;
estimatedColumnWidths.Clear();
}

var _i = i;
float offAxisFraction = 0.0f;
if (_i == 0) {
offAxisFraction = -0.5f * this.textDirectionFactor;
offAxisFraction = -0.5f;
offAxisFraction = 0.5f * this.textDirectionFactor;
offAxisFraction = 0.5f;
padding = padding.flipped;
}
if (this.textDirectionFactor == -1) {
padding = padding.flipped;
}

style: CupertinoDatePickerUtils._kDefaultPickerTextStyle,
child: new CustomMultiChildLayout(
layoutDelegate: new _DatePickerLayoutDelegate(
columnWidths: columnWidths,
textDirectionFactor: this.textDirectionFactor
columnWidths: columnWidths
),
children: pickers
)

}
class _CupertinoDatePickerDateState : State<CupertinoDatePicker> {
int textDirectionFactor;
CupertinoLocalizations localizations;
Alignment alignCenterLeft;

public override void didChangeDependencies() {
base.didChangeDependencies();
this.textDirectionFactor = Directionality.of(this.context) == TextDirection.ltr ? 1 : -1;
this.alignCenterLeft = this.textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight;
this.alignCenterRight = this.textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft;
this.alignCenterLeft = Alignment.centerLeft;
this.alignCenterRight = Alignment.centerRight;
this.estimatedColumnWidths[(int) _PickerColumnType.dayOfMonth] = CupertinoDatePicker._getColumnWidth(
_PickerColumnType.dayOfMonth, this.localizations, this.context);

List<Widget> pickers = new List<Widget>();
for (int i = 0; i < columnWidths.Count; i++) {
var _i = i;
float offAxisFraction = (_i - 1) * 0.3f * this.textDirectionFactor;
float offAxisFraction = (_i - 1) * 0.3f;
if (this.textDirectionFactor == -1) {
padding = EdgeInsets.only(left: CupertinoDatePickerUtils._kDatePickerPadSize);
}
pickers.Add(new LayoutId(
id: _i,

style: CupertinoDatePickerUtils._kDefaultPickerTextStyle,
child: new CustomMultiChildLayout(
layoutDelegate: new _DatePickerLayoutDelegate(
columnWidths: columnWidths,
textDirectionFactor: this.textDirectionFactor
columnWidths: columnWidths
),
children:
pickers

}
class _CupertinoTimerPickerState : State<CupertinoTimerPicker> {
int textDirectionFactor;
CupertinoLocalizations localizations;
Alignment alignCenterLeft;
Alignment alignCenterRight;

public override void didChangeDependencies() {
base.didChangeDependencies();
this.textDirectionFactor = Directionality.of(this.context) == TextDirection.ltr ? 1 : -1;
this.alignCenterLeft = this.textDirectionFactor == 1 ? Alignment.centerLeft : Alignment.centerRight;
this.alignCenterRight = this.textDirectionFactor == 1 ? Alignment.centerRight : Alignment.centerLeft;
this.alignCenterLeft = Alignment.centerLeft;
this.alignCenterRight = Alignment.centerRight;
offAxisFraction: -0.5f * this.textDirectionFactor,
offAxisFraction: -0.5f,
itemExtent: CupertinoDatePickerUtils._kItemExtent,
backgroundColor: CupertinoDatePickerUtils._kBackgroundColor,
onSelectedItemChanged: (int index) => {

float hourLabelWidth = this.widget.mode == CupertinoTimerPickerMode.hm
? CupertinoDatePickerUtils._kPickerWidth / 4
: CupertinoDatePickerUtils._kPickerWidth / 6;
string semanticsLabel = this.textDirectionFactor == 1
? this.localizations.timerPickerHour(index) + this.localizations.timerPickerHourLabel(index)
: this.localizations.timerPickerHourLabel(index) + this.localizations.timerPickerHour(index);
padding: this.textDirectionFactor == 1
? EdgeInsets.only(right: hourLabelWidth)
: EdgeInsets.only(left: hourLabelWidth),
padding: EdgeInsets.only(right: hourLabelWidth),
child: new Container(
alignment: this.alignCenterRight,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

Widget _buildMinutePicker() {
float offAxisFraction;
if (this.widget.mode == CupertinoTimerPickerMode.hm) {
offAxisFraction = 0.5f * this.textDirectionFactor;
offAxisFraction = 0.5f;
offAxisFraction = -0.5f * this.textDirectionFactor;
offAxisFraction = -0.5f;
}
return new CupertinoPicker(

},
children: CupertinoDatePickerUtils.listGenerate(60 / this.widget.minuteInterval, (int index) => {
int minute = index * this.widget.minuteInterval;
string semanticsLabel = this.textDirectionFactor == 1
? this.localizations.timerPickerMinute(minute) +
this.localizations.timerPickerMinuteLabel(minute)
: this.localizations.timerPickerMinuteLabel(minute) +
this.localizations.timerPickerMinute(minute);
padding: this.textDirectionFactor == 1
? EdgeInsets.only(right: CupertinoDatePickerUtils._kPickerWidth / 4)
: EdgeInsets.only(left: CupertinoDatePickerUtils._kPickerWidth / 4),
padding: EdgeInsets.only(right: CupertinoDatePickerUtils._kPickerWidth / 4),
child: new Container(
alignment: this.alignCenterRight,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

minuteLabel = new IgnorePointer(
child: new Container(
alignment: this.alignCenterLeft,
padding: this.textDirectionFactor == 1
? EdgeInsets.only(left: CupertinoDatePickerUtils._kPickerWidth / 10)
: EdgeInsets.only(right: CupertinoDatePickerUtils._kPickerWidth / 10),
padding: EdgeInsets.only(left: CupertinoDatePickerUtils._kPickerWidth / 10),
child: new Container(
alignment: this.alignCenterLeft,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

}
Widget _buildSecondPicker() {
float offAxisFraction = 0.5f * this.textDirectionFactor;
float offAxisFraction = 0.5f;
float secondPickerWidth = this.widget.mode == CupertinoTimerPickerMode.ms
? CupertinoDatePickerUtils._kPickerWidth / 10
: CupertinoDatePickerUtils._kPickerWidth / 6;

},
children: CupertinoDatePickerUtils.listGenerate(60 / this.widget.secondInterval, (int index) => {
int second = index * this.widget.secondInterval;
string semanticsLabel = this.textDirectionFactor == 1
? this.localizations.timerPickerSecond(second) +
this.localizations.timerPickerSecondLabel(second)
: this.localizations.timerPickerSecondLabel(second) +
this.localizations.timerPickerSecond(second);
return new Container(
alignment: this.alignCenterLeft,
child: new Container(

Widget secondLabel = new IgnorePointer(
child: new Container(
alignment: this.alignCenterLeft,
padding: this.textDirectionFactor == 1
? EdgeInsets.only(left: secondPickerWidth)
: EdgeInsets.only(right: secondPickerWidth),
padding: EdgeInsets.only(left: secondPickerWidth),
child: new Container(
alignment: this.alignCenterLeft,
padding: EdgeInsets.symmetric(horizontal: 2.0f),

2
Runtime/cupertino/localization.cs


public override string datePickerMediumDate(DateTime date) {
var day = _shortWeekdays[((int) date.DayOfWeek + 6) % 7];
var month = _shortMonths[date.Month - 1];
return $"{day}, {month} {date.Day.ToString().PadRight(2)} ";
return $"{day} {month} {date.Day.ToString().PadRight(2)} ";
}
public override DatePickerDateOrder datePickerDateOrder {

119
Runtime/cupertino/picker.cs


using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.cupertino {
class CupertinoPickerUtils {
static class CupertinoPickerUtils {
public static Color _kHighlighterBorder = new Color(0xFF7F7F7F);
public static Color _kDefaultBackground = new Color(0xFFD2D4DB);
public const float _kDefaultDiameterRatio = 1.35f;

}
class _CupertinoPickerState : State<CupertinoPicker> {
int _lastHapticIndex;
FixedExtentScrollController _controller;
public override void initState() {

}
void _handleSelectedItemChanged(int index) {
// if (defaultTargetPlatform == TargetPlatform.iOS && index != _lastHapticIndex) {
// _lastHapticIndex = index;
// // HapticFeedback.selectionClick();
// }
this._lastHapticIndex = index;
if (this.widget.onSelectedItemChanged != null) {
this.widget.onSelectedItemChanged(index);
}

Widget result = new Stack(
children: new List<Widget> {
Positioned.fill(
child: new _CupertinoPickerSemantics(
scrollController: this.widget.scrollController ?? this._controller,
child: ListWheelScrollView.useDelegate(
controller: this.widget.scrollController ?? this._controller,
physics: new FixedExtentScrollPhysics(),
diameterRatio: this.widget.diameterRatio,
perspective: CupertinoPickerUtils._kDefaultPerspective,
offAxisFraction: this.widget.offAxisFraction,
useMagnifier: this.widget.useMagnifier,
magnification: this.widget.magnification,
itemExtent: this.widget.itemExtent,
onSelectedItemChanged: this._handleSelectedItemChanged,
childDelegate: this.widget.childDelegate
)
child: ListWheelScrollView.useDelegate(
controller: this.widget.scrollController ?? this._controller,
physics: new FixedExtentScrollPhysics(),
diameterRatio: this.widget.diameterRatio,
perspective: CupertinoPickerUtils._kDefaultPerspective,
offAxisFraction: this.widget.offAxisFraction,
useMagnifier: this.widget.useMagnifier,
magnification: this.widget.magnification,
itemExtent: this.widget.itemExtent,
onSelectedItemChanged: this._handleSelectedItemChanged,
childDelegate: this.widget.childDelegate
)
),
this._buildGradientScreen(),

}
return result;
}
}
class _CupertinoPickerSemantics : SingleChildRenderObjectWidget {
public _CupertinoPickerSemantics(
FixedExtentScrollController scrollController,
Key key = null,
Widget child = null
) : base(key: key, child: child) {
this.scrollController = scrollController;
}
public readonly FixedExtentScrollController scrollController;
public override RenderObject createRenderObject(BuildContext context) {
return new _RenderCupertinoPickerSemantics(this.scrollController, Directionality.of(context));
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
((_RenderCupertinoPickerSemantics) renderObject).textDirection = Directionality.of(context);
((_RenderCupertinoPickerSemantics) renderObject).controller = this.scrollController;
}
}
class _RenderCupertinoPickerSemantics : RenderProxyBox {
public _RenderCupertinoPickerSemantics(FixedExtentScrollController controller, TextDirection _textDirection) {
this.controller = controller;
this._textDirection = _textDirection;
}
public FixedExtentScrollController controller {
get { return this._controller; }
set {
if (value == this._controller) {
return;
}
if (this._controller != null) {
this._controller.removeListener(this._handleScrollUpdate);
}
else {
this._currentIndex = value.initialItem;
}
value.addListener(this._handleScrollUpdate);
this._controller = value;
}
}
FixedExtentScrollController _controller;
public TextDirection textDirection {
get { return this._textDirection; }
set {
if (this.textDirection == value) {
return;
}
this._textDirection = value;
}
}
TextDirection _textDirection;
int _currentIndex = 0;
void _handleIncrease() {
this.controller.jumpToItem(this._currentIndex + 1);
}
void _handleDecrease() {
if (this._currentIndex == 0) {
return;
}
this.controller.jumpToItem(this._currentIndex - 1);
}
void _handleScrollUpdate() {
if (this.controller.selectedItem == this._currentIndex) {
return;
}
this._currentIndex = this.controller.selectedItem;
}
}
}

356
Runtime/painting/matrix_utils.cs


return matrix;
}
public static Matrix4x4 createCylindricalProjectionTransform(
float radius,
float angle,
float perspective = 0.001f,
Axis orientation = Axis.vertical
) {
D.assert(perspective >= 0 && perspective <= 1.0);
Matrix4x4 result = Matrix4x4.identity;
result[3, 2] = -perspective;
result[2, 3] = -radius;
result[3, 3] = perspective * radius + 1.0f;
result *= (
orientation == Axis.horizontal
? rotationY(angle)
: rotationX(angle)
) * translationValues(0.0f, 0.0f, radius);
return result;
}
public static Matrix4x4 rotationY(float angle) {
var matrix = Matrix4x4.zero;
matrix[15] = 1.0f;
float c = Mathf.Cos(angle);
float s = Mathf.Sin(angle);
matrix[0] = c;
matrix[1] = 0.0f;
matrix[2] = -s;
matrix[4] = 0.0f;
matrix[5] = 1.0f;
matrix[6] = 0.0f;
matrix[8] = s;
matrix[9] = 0.0f;
matrix[10] = c;
matrix[3] = 0.0f;
matrix[7] = 0.0f;
matrix[11] = 0.0f;
return matrix;
}
public static Matrix4x4 rotationX(float angle) {
var matrix = Matrix4x4.zero;
matrix[15] = 1.0f;
float c = Mathf.Cos(angle);
float s = Mathf.Sin(angle);
matrix[0] = 1.0f;
matrix[1] = 0.0f;
matrix[2] = 0.0f;
matrix[4] = 0.0f;
matrix[5] = c;
matrix[6] = s;
matrix[8] = 0.0f;
matrix[9] = -s;
matrix[10] = c;
matrix[3] = 0.0f;
matrix[7] = 0.0f;
matrix[11] = 0.0f;
return matrix;
}
public static Matrix4x4 translationValues(float x, float y, float z) {
var matrix = Matrix4x4.identity;
matrix[14] = z;
matrix[13] = y;
matrix[12] = x;
return matrix;
}
public static Matrix4x4 translate(this Matrix4x4 m, Vector4 x, float y = 0.0f, float z = 0.0f) {
float tw = x.w;
float tx = x.x;
float ty = x.y;
float tz = x.z;
float t1 = m[0] * tx + m[4] * ty + m[8] * tz + m[12] * tw;
float t2 = m[1] * tx + m[5] * ty + m[9] * tz + m[13] * tw;
float t3 = m[2] * tx + m[6] * ty + m[10] * tz + m[14] * tw;
float t4 = m[3] * tx + m[7] * ty + m[11] * tz + m[15] * tw;
m[12] = t1;
m[13] = t2;
m[14] = t3;
m[15] = t4;
return m;
}
public static Matrix4x4 translate(this Matrix4x4 m, Vector3 x, float y = 0.0f, float z = 0.0f) {
float tw = 1.0f;
float tx = x.x;
float ty = x.y;
float tz = x.z;
float t1 = m[0] * tx + m[4] * ty + m[8] * tz + m[12] * tw;
float t2 = m[1] * tx + m[5] * ty + m[9] * tz + m[13] * tw;
float t3 = m[2] * tx + m[6] * ty + m[10] * tz + m[14] * tw;
float t4 = m[3] * tx + m[7] * ty + m[11] * tz + m[15] * tw;
m[12] = t1;
m[13] = t2;
m[14] = t3;
m[15] = t4;
return m;
}
public static Matrix4x4 translate(this Matrix4x4 m, float x, float y = 0.0f, float z = 0.0f) {
float tw = 1.0f;
float tx = x;
float ty = y;
float tz = z;
float t1 = m[0] * tx + m[4] * ty + m[8] * tz + m[12] * tw;
float t2 = m[1] * tx + m[5] * ty + m[9] * tz + m[13] * tw;
float t3 = m[2] * tx + m[6] * ty + m[10] * tz + m[14] * tw;
float t4 = m[3] * tx + m[7] * ty + m[11] * tz + m[15] * tw;
m[12] = t1;
m[13] = t2;
m[14] = t3;
m[15] = t4;
return m;
}
public static void multiply(this Matrix3 m, Matrix3 arg) {
float m00 = m[0];
float m01 = m[3];
float m02 = m[6];
float m10 = m[1];
float m11 = m[4];
float m12 = m[7];
float m20 = m[2];
float m21 = m[5];
float m22 = m[8];
List<float> argStorage = new List<float> {
arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8]
};
float n00 = argStorage[0];
float n01 = argStorage[3];
float n02 = argStorage[6];
float n10 = argStorage[1];
float n11 = argStorage[4];
float n12 = argStorage[7];
float n20 = argStorage[2];
float n21 = argStorage[5];
float n22 = argStorage[8];
m[0] = (m00 * n00) + (m01 * n10) + (m02 * n20);
m[3] = (m00 * n01) + (m01 * n11) + (m02 * n21);
m[6] = (m00 * n02) + (m01 * n12) + (m02 * n22);
m[1] = (m10 * n00) + (m11 * n10) + (m12 * n20);
m[4] = (m10 * n01) + (m11 * n11) + (m12 * n21);
m[7] = (m10 * n02) + (m11 * n12) + (m12 * n22);
m[2] = (m20 * n00) + (m21 * n10) + (m22 * n20);
m[5] = (m20 * n01) + (m21 * n11) + (m22 * n21);
m[8] = (m20 * n02) + (m21 * n12) + (m22 * n22);
}
public static void multiply(this Matrix4x4 m, Matrix4x4 arg) {
float m00 = m[0];
float m01 = m[4];
float m02 = m[8];
float m03 = m[12];
float m10 = m[1];
float m11 = m[5];
float m12 = m[9];
float m13 = m[13];
float m20 = m[2];
float m21 = m[6];
float m22 = m[10];
float m23 = m[14];
float m30 = m[3];
float m31 = m[7];
float m32 = m[11];
float m33 = m[15];
List<float> argStorage = new List<float> {
arg.m00, arg.m01, arg.m02, arg.m03,
arg.m10, arg.m11, arg.m12, arg.m13,
arg.m20, arg.m21, arg.m22, arg.m23,
arg.m30, arg.m31, arg.m32, arg.m33,
};
float n00 = argStorage[0];
float n01 = argStorage[4];
float n02 = argStorage[8];
float n03 = argStorage[12];
float n10 = argStorage[1];
float n11 = argStorage[5];
float n12 = argStorage[9];
float n13 = argStorage[13];
float n20 = argStorage[2];
float n21 = argStorage[6];
float n22 = argStorage[10];
float n23 = argStorage[14];
float n30 = argStorage[3];
float n31 = argStorage[7];
float n32 = argStorage[11];
float n33 = argStorage[15];
m[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30);
m[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31);
m[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32);
m[12] = (m00 * n03) + (m01 * n13) + (m02 * n23) + (m03 * n33);
m[1] = (m10 * n00) + (m11 * n10) + (m12 * n20) + (m13 * n30);
m[5] = (m10 * n01) + (m11 * n11) + (m12 * n21) + (m13 * n31);
m[9] = (m10 * n02) + (m11 * n12) + (m12 * n22) + (m13 * n32);
m[13] = (m10 * n03) + (m11 * n13) + (m12 * n23) + (m13 * n33);
m[2] = (m20 * n00) + (m21 * n10) + (m22 * n20) + (m23 * n30);
m[6] = (m20 * n01) + (m21 * n11) + (m22 * n21) + (m23 * n31);
m[10] = (m20 * n02) + (m21 * n12) + (m22 * n22) + (m23 * n32);
m[14] = (m20 * n03) + (m21 * n13) + (m22 * n23) + (m23 * n33);
m[3] = (m30 * n00) + (m31 * n10) + (m32 * n20) + (m33 * n30);
m[7] = (m30 * n01) + (m31 * n11) + (m32 * n21) + (m33 * n31);
m[11] = (m30 * n02) + (m31 * n12) + (m32 * n22) + (m33 * n32);
m[15] = (m30 * n03) + (m31 * n13) + (m32 * n23) + (m33 * n33);
}
public static void scale(this Matrix4x4 m, object x, float? y = null, float? z = null) {
float sx = 0f;
float sy = 0f;
float sz = 0f;
float sw = x is Vector4 _xv4 ? _xv4.w : 1.0f;
if (x is Vector3 xv3) {
sx = xv3.x;
sy = xv3.y;
sz = xv3.z;
}
else if (x is Vector4 xv4) {
sx = xv4.x;
sy = xv4.y;
sz = xv4.z;
}
else if (x is float xf) {
sx = xf;
sy = y ?? xf;
sz = z ?? xf;
}
m[0] *= sx;
m[1] *= sx;
m[2] *= sx;
m[3] *= sx;
m[4] *= sy;
m[5] *= sy;
m[6] *= sy;
m[7] *= sy;
m[8] *= sz;
m[9] *= sz;
m[10] *= sz;
m[11] *= sz;
m[12] *= sw;
m[13] *= sw;
m[14] *= sw;
m[15] *= sw;
}
public static Rect inverseTransformRect(Matrix4x4 transform, Rect rect) {
D.assert(rect != null);
D.assert(transform.determinant != 0.0);
if (transform == Matrix4x4.identity)
return rect;
var copy = transform;
copy.invert();
transform = copy;
return transformRect(transform, rect);
}
public static float invert(this Matrix4x4 m) {
return m.copyInverse();
}
public static float copyInverse(this Matrix4x4 m) {
List<float> argStorage = new List<float> {
m.m00, m.m01, m.m02, m.m03,
m.m10, m.m11, m.m12, m.m13,
m.m20, m.m21, m.m22, m.m23,
m.m30, m.m31, m.m32, m.m33,
};
float a00 = argStorage[0];
float a01 = argStorage[1];
float a02 = argStorage[2];
float a03 = argStorage[3];
float a10 = argStorage[4];
float a11 = argStorage[5];
float a12 = argStorage[6];
float a13 = argStorage[7];
float a20 = argStorage[8];
float a21 = argStorage[9];
float a22 = argStorage[10];
float a23 = argStorage[11];
float a30 = argStorage[12];
float a31 = argStorage[13];
float a32 = argStorage[14];
float a33 = argStorage[15];
float b00 = a00 * a11 - a01 * a10;
float b01 = a00 * a12 - a02 * a10;
float b02 = a00 * a13 - a03 * a10;
float b03 = a01 * a12 - a02 * a11;
float b04 = a01 * a13 - a03 * a11;
float b05 = a02 * a13 - a03 * a12;
float b06 = a20 * a31 - a21 * a30;
float b07 = a20 * a32 - a22 * a30;
float b08 = a20 * a33 - a23 * a30;
float b09 = a21 * a32 - a22 * a31;
float b10 = a21 * a33 - a23 * a31;
float b11 = a22 * a33 - a23 * a32;
float det =
(b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06);
if (det == 0.0f) {
m[0] = argStorage[0];
m[1] = argStorage[1];
m[2] = argStorage[2];
m[3] = argStorage[3];
m[4] = argStorage[4];
m[5] = argStorage[5];
m[6] = argStorage[6];
m[7] = argStorage[7];
m[8] = argStorage[8];
m[9] = argStorage[9];
m[10] = argStorage[10];
m[11] = argStorage[11];
m[12] = argStorage[12];
m[13] = argStorage[13];
m[14] = argStorage[14];
m[15] = argStorage[15];
return 0.0f;
}
float invDet = 1.0f / det;
m[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
m[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
m[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet;
m[3] = (-a21 * b05 + a22 * b04 - a23 * b03) * invDet;
m[4] = (-a10 * b11 + a12 * b08 - a13 * b07) * invDet;
m[5] = (a00 * b11 - a02 * b08 + a03 * b07) * invDet;
m[6] = (-a30 * b05 + a32 * b02 - a33 * b01) * invDet;
m[7] = (a20 * b05 - a22 * b02 + a23 * b01) * invDet;
m[8] = (a10 * b10 - a11 * b08 + a13 * b06) * invDet;
m[9] = (-a00 * b10 + a01 * b08 - a03 * b06) * invDet;
m[10] = (a30 * b04 - a31 * b02 + a33 * b00) * invDet;
m[11] = (-a20 * b04 + a21 * b02 - a23 * b00) * invDet;
m[12] = (-a10 * b09 + a11 * b07 - a12 * b06) * invDet;
m[13] = (a00 * b09 - a01 * b07 + a02 * b06) * invDet;
m[14] = (-a30 * b03 + a31 * b01 - a32 * b00) * invDet;
m[15] = (a20 * b03 - a21 * b01 + a22 * b00) * invDet;
return det;
}
public static Matrix3 toMatrix3(this Matrix4x4 m) {
var m3 = Matrix3.I();
m3[0] = m[0];
m3[1] = m[1];
m3[2] = m[2];
m3[3] = m[3];
m3[4] = m[4];
m3[5] = m[5];
m3[6] = m[6];
m3[7] = m[7];
m3[8] = m[8];
return m3;
}
}
public class TransformProperty : DiagnosticsProperty<Matrix3> {

26
Runtime/service/text_formatter.cs


}
}
public class WhitelistingTextInputFormatter : TextInputFormatter {
public WhitelistingTextInputFormatter(Regex whitelistedPattern) {
D.assert(whitelistedPattern != null);
this.whitelistedPattern = whitelistedPattern;
}
readonly Regex whitelistedPattern;
public override TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
return Util._selectionAwareTextManipulation(
value: newValue,
substringManipulation: substring => {
string groups = "";
foreach (Match match in this.whitelistedPattern.Matches(input: substring)) {
groups += match.Groups[0].Value;
}
return groups;
}
);
}
public static readonly WhitelistingTextInputFormatter digitsOnly
= new WhitelistingTextInputFormatter(new Regex(@"\d+"));
}
static class Util {
internal static TextEditingValue _selectionAwareTextManipulation(TextEditingValue value,
Func<string, string> substringManipulation) {

5
Runtime/widgets/scroll_physics.cs


}
}
// todo: Handle the case of the device pixel ratio changing. use 1 as devicePixelRatio for now.
velocity: 1.0f / (0.050f * 1),
distance: 1.0f / 1
velocity: 1.0f / (0.050f * Window.instance.devicePixelRatio),
distance: 1.0f / Window.instance.devicePixelRatio
);
public virtual Tolerance tolerance {

正在加载...
取消
保存