浏览代码

Implement backdrop.

/main
Yuncong Zhang 6 年前
当前提交
918cf889
共有 5 个文件被更改,包括 248 次插入145 次删除
  1. 242
      Runtime/material/animated_icons/animated_icons.cs
  2. 52
      Runtime/material/animated_icons/animated_icons_data.cs
  3. 4
      Samples/UIWidgetsGallery/gallery/backdrop.cs
  4. 92
      Runtime/widgets/visibility.cs
  5. 3
      Runtime/widgets/visibility.cs.meta

242
Runtime/material/animated_icons/animated_icons.cs


using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
D.assert(progress <= 1.0f);
D.assert(progress >= 0.0f);
if (values.Count == 1)
return values[0];
float targetIdx = MathUtils.lerpFloat(0, values.Count -1, progress);
int lowIdx = targetIdx.floor();
int highIdx = targetIdx.ceil();
float t = targetIdx - lowIdx;
return interpolator(values[lowIdx], values[highIdx], t);
D.assert(progress <= 1.0f);
D.assert(progress >= 0.0f);
if (values.Count == 1) {
return values[0];
}
float targetIdx = MathUtils.lerpFloat(0, values.Count - 1, progress);
int lowIdx = targetIdx.floor();
int highIdx = targetIdx.ceil();
float t = targetIdx - lowIdx;
return interpolator(values[lowIdx], values[highIdx], t);
public AnimatedIcon(
Key key = null,
AnimatedIconData icon = null,
Animation<float> progress = null,
Color color = null,
float? size = null
) : base(key: key) {
public AnimatedIcon(
Key key = null,
AnimatedIconData icon = null,
Animation<float> progress = null,
Color color = null,
float? size = null
) : base(key: key) {
D.assert(progress != null);
D.assert(icon != null);
this.progress = progress;

}
}
public readonly Animation<float> progress;
public readonly Animation<float> progress;
public readonly Color color;
public readonly Color color;
public readonly float? size;
public readonly float? size;
public readonly AnimatedIconData icon;
public readonly AnimatedIconData icon;
public static readonly _UiPathFactory _pathFactory = () => new Path();
public static readonly _UiPathFactory _pathFactory = () => new Path();
public override Widget build(BuildContext context) {
_AnimatedIconData iconData = (_AnimatedIconData) this.icon;
IconThemeData iconTheme = IconTheme.of(context);
float iconSize = this.size ?? iconTheme.size ?? 0.0f;
float? iconOpacity = iconTheme.opacity;
Color iconColor = this.color ?? iconTheme.color;
if (iconOpacity != 1.0f) {
iconColor = iconColor.withOpacity(iconColor.opacity * (iconOpacity ?? 1.0f));
}
public override Widget build(BuildContext context) {
_AnimatedIconData iconData = (_AnimatedIconData) this.icon;
IconThemeData iconTheme = IconTheme.of(context);
float iconSize = this.size ?? iconTheme.size ?? 0.0f;
float? iconOpacity = iconTheme.opacity;
Color iconColor = this.color ?? iconTheme.color;
if (iconOpacity != 1.0f)
iconColor = iconColor.withOpacity(iconColor.opacity * (iconOpacity ?? 1.0f));
return new CustomPaint(
size: new Size(iconSize, iconSize),
painter: new _AnimatedIconPainter(
paths: iconData.paths,
progress: this.progress,
color: iconColor,
scale: iconSize / iconData.size.width,
uiPathFactory: _pathFactory
)
);
}
return new CustomPaint(
size: new Size(iconSize, iconSize),
painter: new _AnimatedIconPainter(
paths: iconData.paths,
progress: this.progress,
color: iconColor,
scale: iconSize / iconData.size.width,
uiPathFactory: _pathFactory
)
);
}
}
public delegate Path _UiPathFactory();

this.uiPathFactory = uiPathFactory;
}
public readonly List<_PathFrames> paths;
public readonly Animation<float> progress;
public readonly Color color;
public readonly float? scale;
public readonly bool? shouldMirror;
public readonly _UiPathFactory uiPathFactory;
public readonly List<_PathFrames> paths;
public readonly Animation<float> progress;
public readonly Color color;
public readonly float? scale;
public readonly bool? shouldMirror;
public readonly _UiPathFactory uiPathFactory;
public override void paint(ui.Canvas canvas, Size size) {
canvas.scale(this.scale ?? 1.0f, this.scale ?? 1.0f);
if (this.shouldMirror == true) {
canvas.rotate(Mathf.PI);
canvas.translate(-size.width, -size.height);
}
public override void paint(Canvas canvas, Size size) {
canvas.scale(this.scale ?? 1.0f, this.scale ?? 1.0f);
if (this.shouldMirror == true) {
canvas.rotate(Mathf.PI);
canvas.translate(-size.width, -size.height);
}
float clampedProgress = this.progress.value.clamp(0.0f, 1.0f);
foreach (_PathFrames path in this.paths)
path.paint(canvas, this.color, this.uiPathFactory, clampedProgress);
}
float clampedProgress = this.progress.value.clamp(0.0f, 1.0f);
foreach (_PathFrames path in this.paths) {
path.paint(canvas, this.color, this.uiPathFactory, clampedProgress);
}
}
public override bool shouldRepaint(CustomPainter _oldDelegate) {
_AnimatedIconPainter oldDelegate = _oldDelegate as _AnimatedIconPainter;
return oldDelegate.progress.value != this.progress.value
|| oldDelegate.color != this.color
|| oldDelegate.paths != this.paths
|| oldDelegate.scale != this.scale
|| oldDelegate.uiPathFactory != this.uiPathFactory;
}
public override bool shouldRepaint(CustomPainter _oldDelegate) {
_AnimatedIconPainter oldDelegate = _oldDelegate as _AnimatedIconPainter;
return oldDelegate.progress.value != this.progress.value
|| oldDelegate.color != this.color
|| oldDelegate.paths != this.paths
|| oldDelegate.scale != this.scale
|| oldDelegate.uiPathFactory != this.uiPathFactory;
}
public override bool? hitTest(Offset position) => null;
public override bool? hitTest(Offset position) {
return null;
}
}
class _PathFrames {

this.opacities = opacities;
}
public readonly List<_PathCommand> commands;
public readonly List<float> opacities;
public readonly List<_PathCommand> commands;
public readonly List<float> opacities;
public void paint(Canvas canvas, Color color, _UiPathFactory uiPathFactory, float progress) {
float opacity = AnimatedIconUtils._interpolate<float>(this.opacities, progress, MathUtils.lerpFloat);
Paint paint = new Paint();
paint.style = PaintingStyle.fill;
paint.color = color.withOpacity(color.opacity * opacity);
Path path = uiPathFactory();
foreach (_PathCommand command in this.commands) {
command.apply(path, progress);
}
public void paint(ui.Canvas canvas, Color color, _UiPathFactory uiPathFactory, float progress) {
float opacity = AnimatedIconUtils._interpolate<float>(this.opacities, progress, MathUtils.lerpFloat);
Paint paint = new Paint();
paint.style = PaintingStyle.fill;
paint.color = color.withOpacity(color.opacity * opacity);
Path path = uiPathFactory();
foreach (_PathCommand command in this.commands)
command.apply(path, progress);
canvas.drawPath(path, paint);
}
canvas.drawPath(path, paint);
}
public _PathCommand() {}
public _PathCommand() {
}
public abstract void apply(Path path, float progress);
public abstract void apply(Path path, float progress);
}
class _PathMoveTo : _PathCommand {

public readonly List<Offset> points;
public readonly List<Offset> points;
public override void apply(Path path, float progress) {
Offset offset = AnimatedIconUtils._interpolate<Offset>(this.points, progress, Offset.lerp);
path.moveTo(offset.dx, offset.dy);
}
public override void apply(Path path, float progress) {
Offset offset = AnimatedIconUtils._interpolate<Offset>(this.points, progress, Offset.lerp);
path.moveTo(offset.dx, offset.dy);
}
public _PathCubicTo(List<Offset> controlPoints1, List<Offset> controlPoints2, List<Offset> targetPoints) {
this.controlPoints1 = controlPoints1;
this.controlPoints2 = controlPoints2;
this.targetPoints = targetPoints;
}
public _PathCubicTo(List<Offset> controlPoints1, List<Offset> controlPoints2, List<Offset> targetPoints) {
this.controlPoints1 = controlPoints1;
this.controlPoints2 = controlPoints2;
this.targetPoints = targetPoints;
}
public readonly List<Offset> controlPoints2;
public readonly List<Offset> controlPoints1;
public readonly List<Offset> targetPoints;
public readonly List<Offset> controlPoints2;
public readonly List<Offset> controlPoints1;
public readonly List<Offset> targetPoints;
public override void apply(Path path, float progress) {
Offset controlPoint1 = AnimatedIconUtils._interpolate<Offset>(this.controlPoints1, progress, Offset.lerp);
Offset controlPoint2 = AnimatedIconUtils._interpolate<Offset>(this.controlPoints2, progress, Offset.lerp);
Offset targetPoint = AnimatedIconUtils._interpolate<Offset>(this.targetPoints, progress, Offset.lerp);
// TODO: replace with cubicTo
path.bezierTo(
controlPoint1.dx, controlPoint1.dy,
controlPoint2.dx, controlPoint2.dy,
targetPoint.dx, targetPoint.dy
);
}
public override void apply(Path path, float progress) {
Offset controlPoint1 = AnimatedIconUtils._interpolate<Offset>(this.controlPoints1, progress, Offset.lerp);
Offset controlPoint2 = AnimatedIconUtils._interpolate<Offset>(this.controlPoints2, progress, Offset.lerp);
Offset targetPoint = AnimatedIconUtils._interpolate<Offset>(this.targetPoints, progress, Offset.lerp);
// TODO: replace with cubicTo
path.bezierTo(
controlPoint1.dx, controlPoint1.dy,
controlPoint2.dx, controlPoint2.dy,
targetPoint.dx, targetPoint.dy
);
}
}
class _PathLineTo : _PathCommand {

List<Offset> points;
List<Offset> points;
public override void apply(Path path, float progress) {
Offset point = AnimatedIconUtils._interpolate<Offset>(this.points, progress, Offset.lerp);
path.lineTo(point.dx, point.dy);
}
public override void apply(Path path, float progress) {
Offset point = AnimatedIconUtils._interpolate<Offset>(this.points, progress, Offset.lerp);
path.lineTo(point.dx, point.dy);
}
public _PathClose() {}
public _PathClose() {
}
public override void apply(Path path, float progress) {
path.close();
}
public override void apply(Path path, float progress) {
path.close();
}
}

52
Runtime/material/animated_icons/animated_icons_data.cs


using System.Collections.Generic;
using Unity.UIWidgets.ui;
using UnityEngine;
public static readonly AnimatedIconData add_event = AnimatedIconsData._add_event;
public static readonly AnimatedIconData add_event = AnimatedIconsData._add_event;
public static readonly AnimatedIconData arrow_menu = AnimatedIconsData._arrow_menu;
public static readonly AnimatedIconData arrow_menu = AnimatedIconsData._arrow_menu;
public static readonly AnimatedIconData close_menu = AnimatedIconsData._close_menu;
public static readonly AnimatedIconData close_menu = AnimatedIconsData._close_menu;
// public readonly AnimatedIconData ellipsis_search = AnimatedIconsData._ellipsis_search;
// public readonly AnimatedIconData ellipsis_search = AnimatedIconsData._ellipsis_search;
// public readonly AnimatedIconData event_add = AnimatedIconsData._event_add;
// public readonly AnimatedIconData event_add = AnimatedIconsData._event_add;
// public readonly AnimatedIconData home_menu = AnimatedIconsData._home_menu;
// public readonly AnimatedIconData home_menu = AnimatedIconsData._home_menu;
// public readonly AnimatedIconData list_view = AnimatedIconsData._list_view;
// public readonly AnimatedIconData list_view = AnimatedIconsData._list_view;
// public readonly AnimatedIconData menu_arrow = AnimatedIconsData._menu_arrow;
// public readonly AnimatedIconData menu_arrow = AnimatedIconsData._menu_arrow;
// public readonly AnimatedIconData menu_close = AnimatedIconsData._menu_close;
// public readonly AnimatedIconData menu_close = AnimatedIconsData._menu_close;
// public readonly AnimatedIconData menu_home = AnimatedIconsData._menu_home;
// public readonly AnimatedIconData menu_home = AnimatedIconsData._menu_home;
// public readonly AnimatedIconData pause_play = AnimatedIconsData._pause_play;
// public readonly AnimatedIconData pause_play = AnimatedIconsData._pause_play;
// public readonly AnimatedIconData play_pause = AnimatedIconsData._play_pause;
// public readonly AnimatedIconData play_pause = AnimatedIconsData._play_pause;
// public readonly AnimatedIconData search_ellipsis = AnimatedIconsData._search_ellipsis;
// public readonly AnimatedIconData search_ellipsis = AnimatedIconsData._search_ellipsis;
// public readonly AnimatedIconData view_list = AnimatedIconsData._view_list;
// public readonly AnimatedIconData view_list = AnimatedIconsData._view_list;
public AnimatedIconData() {}
public AnimatedIconData() {
}
public abstract bool matchTextDirection { get; }
public abstract bool matchTextDirection { get; }
public _AnimatedIconData(Size size, List<_PathFrames> paths, bool matchTextDirection = false) {
this.size = size;
this.paths = paths;
this.matchTextDirection = matchTextDirection;
}
public _AnimatedIconData(Size size, List<_PathFrames> paths, bool matchTextDirection = false) {
this.size = size;
this.paths = paths;
this.matchTextDirection = matchTextDirection;
}
public readonly Size size;
public readonly List<_PathFrames> paths;
public readonly Size size;
public readonly List<_PathFrames> paths;
public override bool matchTextDirection { get; }
public override bool matchTextDirection { get; }
}

4
Samples/UIWidgetsGallery/gallery/backdrop.cs


using UnityEngine;
namespace UIWidgetsGallery.gallery {
public class BackdropConstants {
class BackdropConstants {
public const float _kFrontHeadingHeight = 32.0f;
public const float _kFrontClosedHeight = 92.0f;
public const float _kBackAppBarHeight = 56.0f;

}
}
class Backdrop : StatefulWidget {
public class Backdrop : StatefulWidget {
public Backdrop(
Widget frontAction,
Widget frontTitle,

92
Runtime/widgets/visibility.cs


using Unity.UIWidgets.foundation;
namespace Unity.UIWidgets.widgets {
public class Visibility : StatelessWidget {
public Visibility(
Key key = null,
Widget child = null,
Widget replacement = null,
bool visible = true,
bool maintainState = false,
bool maintainAnimation = false,
bool maintainSize = false,
bool maintainInteractivity = false
) : base(key: key) {
D.assert(child != null);
D.assert(replacement != null);
D.assert(maintainState == true || maintainAnimation == false,
"Cannot maintain animations if the state is not also maintained.");
D.assert(maintainAnimation == true || maintainSize == false,
"Cannot maintain size if animations are not maintained.");
D.assert(maintainSize == true || maintainInteractivity == false,
"Cannot maintain interactivity if size is not maintained.");
this.replacement = replacement ?? SizedBox.shrink();
this.child = child;
this.visible = visible;
this.maintainState = maintainState;
this.maintainAnimation = maintainAnimation;
this.maintainSize = maintainSize;
this.maintainInteractivity = maintainInteractivity;
}
public readonly Widget child;
public readonly Widget replacement;
public readonly bool visible;
public readonly bool maintainState;
public readonly bool maintainAnimation;
public readonly bool maintainSize;
public readonly bool maintainInteractivity;
public override Widget build(BuildContext context) {
if (this.maintainSize) {
Widget result = this.child;
if (!this.maintainInteractivity) {
result = new IgnorePointer(
child: this.child,
ignoring: !this.visible
);
}
return new Opacity(
opacity: this.visible ? 1.0f : 0.0f,
child: result
);
}
D.assert(!this.maintainInteractivity);
D.assert(!this.maintainSize);
if (this.maintainState) {
Widget result = this.child;
if (!this.maintainAnimation) {
result = new TickerMode(child: this.child, enabled: this.visible);
}
return new Offstage(
child: result,
offstage: !this.visible
);
}
D.assert(!this.maintainAnimation);
D.assert(!this.maintainState);
return this.visible ? this.child : this.replacement;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagProperty("visible", value: this.visible, ifFalse: "hidden", ifTrue: "visible"));
properties.add(new FlagProperty("maintainState", value: this.maintainState, ifFalse: "maintainState"));
properties.add(new FlagProperty("maintainAnimation", value: this.maintainAnimation,
ifFalse: "maintainAnimation"));
properties.add(new FlagProperty("maintainSize", value: this.maintainSize, ifFalse: "maintainSize"));
properties.add(new FlagProperty("maintainInteractivity", value: this.maintainInteractivity,
ifFalse: "maintainInteractivity"));
}
}
}

3
Runtime/widgets/visibility.cs.meta


fileFormatVersion: 2
guid: f24846c5a2354d9a8b02bf83f3e8398e
timeCreated: 1552895385
正在加载...
取消
保存