xingwei.zhu
6 年前
当前提交
52fc6d0b
共有 17 个文件被更改,包括 521 次插入 和 195 次删除
-
14Runtime/material/app.cs
-
30Runtime/material/arc.cs
-
8Runtime/material/drawer.cs
-
5Runtime/material/drawer_header.cs
-
6Runtime/material/expansion_panel.cs
-
5Runtime/material/expansion_tile.cs
-
6Runtime/material/icon_button.cs
-
5Runtime/material/ink_highlight.cs
-
37Runtime/material/ink_ripple.cs
-
48Runtime/material/ink_splash.cs
-
12Runtime/material/material.cs
-
10Runtime/material/scrollbar.cs
-
4Runtime/material/theme.cs
-
10Runtime/material/theme_data.cs
-
7Runtime/material/tooltip.cs
-
317Runtime/material/toggleable.cs
-
192Runtime/material/utils.cs
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.scheduler; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
static class ToggleableUtils { |
|||
public static readonly TimeSpan _kToggleDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
|
|||
public static readonly Animatable<float> _kRadialReactionRadiusTween = |
|||
new FloatTween(begin: 0.0f, end: Constants.kRadialReactionRadius); |
|||
} |
|||
|
|||
public abstract class RenderToggleable : RenderConstrainedBox { |
|||
RenderToggleable( |
|||
bool? value = null, |
|||
bool tristate = false, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
ValueChanged<bool?> onChanged = null, |
|||
BoxConstraints additionalConstraints = null, |
|||
TickerProvider vsync = null |
|||
) : base(additionalConstraints: additionalConstraints) { |
|||
D.assert(tristate || value != null); |
|||
D.assert(activeColor != null); |
|||
D.assert(inactiveColor != null); |
|||
D.assert(vsync != null); |
|||
this._value = value; |
|||
this._tristate = tristate; |
|||
this._activeColor = activeColor; |
|||
this._inactiveColor = inactiveColor; |
|||
this._onChanged = onChanged; |
|||
this._vsync = vsync; |
|||
|
|||
this._tap = new TapGestureRecognizer { |
|||
onTapDown = this._handleTapDown, |
|||
onTap = this._handleTap, |
|||
onTapUp = this._handleTapUp, |
|||
onTapCancel = this._handleTapCancel |
|||
}; |
|||
|
|||
this._positionController = new AnimationController( |
|||
duration: ToggleableUtils._kToggleDuration, |
|||
value: value == false ? 0.0f : 1.0f, |
|||
vsync: vsync); |
|||
|
|||
this._position = new CurvedAnimation( |
|||
parent: this._positionController, |
|||
curve: Curves.linear); |
|||
this._position.addListener(this.markNeedsPaint); |
|||
this._position.addStatusListener(this._handlePositionStateChanged); |
|||
|
|||
this._reactionController = new AnimationController( |
|||
duration: Constants.kRadialReactionDuration, |
|||
vsync: vsync); |
|||
|
|||
this._reaction = new CurvedAnimation( |
|||
parent: this._reactionController, |
|||
curve: Curves.fastOutSlowIn); |
|||
this._reaction.addListener(this.markNeedsPaint); |
|||
} |
|||
|
|||
protected AnimationController positionController { |
|||
get { return this._positionController; } |
|||
} |
|||
|
|||
AnimationController _positionController; |
|||
|
|||
public CurvedAnimation position { |
|||
get { return this._position; } |
|||
} |
|||
|
|||
CurvedAnimation _position; |
|||
|
|||
protected AnimationController reactionController { |
|||
get { return this._reactionController; } |
|||
} |
|||
|
|||
AnimationController _reactionController; |
|||
|
|||
Animation<float> _reaction; |
|||
|
|||
public TickerProvider vsync { |
|||
get { return this._vsync; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._vsync) { |
|||
return; |
|||
} |
|||
|
|||
this._vsync = value; |
|||
this.positionController.resync(this.vsync); |
|||
this.reactionController.resync(this.vsync); |
|||
} |
|||
} |
|||
|
|||
TickerProvider _vsync; |
|||
|
|||
public bool? value { |
|||
get { return this._value; } |
|||
set { |
|||
D.assert(this.tristate || value != null); |
|||
if (value == this._value) { |
|||
return; |
|||
} |
|||
|
|||
this._value = value; |
|||
this._position.curve = Curves.easeIn; |
|||
this._position.reverseCurve = Curves.easeOut; |
|||
if (this.tristate) { |
|||
switch (this._positionController.status) { |
|||
case AnimationStatus.forward: |
|||
case AnimationStatus.completed: { |
|||
this._positionController.reverse(); |
|||
break; |
|||
} |
|||
default: { |
|||
this._positionController.forward(); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
else { |
|||
if (value == true) { |
|||
this._positionController.forward(); |
|||
} |
|||
else { |
|||
this._positionController.reverse(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool? _value; |
|||
|
|||
public bool tristate { |
|||
get { return this._tristate; } |
|||
set { |
|||
if (value == this._tristate) { |
|||
return; |
|||
} |
|||
|
|||
this._tristate = value; |
|||
} |
|||
} |
|||
|
|||
bool _tristate; |
|||
|
|||
public Color activeColor { |
|||
get { return this._activeColor; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._activeColor) { |
|||
return; |
|||
} |
|||
|
|||
this._activeColor = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _activeColor; |
|||
|
|||
public Color inactiveColor { |
|||
get { return this._inactiveColor; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._inactiveColor) { |
|||
return; |
|||
} |
|||
|
|||
this._inactiveColor = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _inactiveColor; |
|||
|
|||
public ValueChanged<bool?> onChanged { |
|||
get { return this._onChanged; } |
|||
set { |
|||
if (value == this._onChanged) { |
|||
return; |
|||
} |
|||
|
|||
bool wasInteractive = this.isInteractive; |
|||
this._onChanged = value; |
|||
if (wasInteractive != this.isInteractive) { |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
ValueChanged<bool?> _onChanged; |
|||
|
|||
public bool isInteractive { |
|||
get { return this.onChanged != null; } |
|||
} |
|||
|
|||
TapGestureRecognizer _tap; |
|||
Offset _downPosition; |
|||
|
|||
public override void attach(object owner) { |
|||
base.attach(owner); |
|||
if (this.value == false) { |
|||
this._positionController.reverse(); |
|||
} |
|||
else { |
|||
this._positionController.forward(); |
|||
} |
|||
|
|||
if (this.isInteractive) { |
|||
switch (this._reactionController.status) { |
|||
case AnimationStatus.forward: { |
|||
this._reactionController.forward(); |
|||
break; |
|||
} |
|||
case AnimationStatus.reverse: { |
|||
this._reactionController.reverse(); |
|||
break; |
|||
} |
|||
case AnimationStatus.dismissed: |
|||
case AnimationStatus.completed: { |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void detach() { |
|||
this._positionController.stop(); |
|||
this._reactionController.stop(); |
|||
base.detach(); |
|||
} |
|||
|
|||
void _handlePositionStateChanged(AnimationStatus status) { |
|||
if (this.isInteractive && !this.tristate) { |
|||
if (status == AnimationStatus.completed && this._value == false) { |
|||
this.onChanged(true); |
|||
} |
|||
else if (status == AnimationStatus.dismissed && this._value != false) { |
|||
this.onChanged(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void _handleTapDown(TapDownDetails details) { |
|||
if (this.isInteractive) { |
|||
this._downPosition = this.globalToLocal(details.globalPosition); |
|||
this._reactionController.forward(); |
|||
} |
|||
} |
|||
|
|||
void _handleTap() { |
|||
if (!this.isInteractive) { |
|||
return; |
|||
} |
|||
|
|||
switch (this.value) { |
|||
case false: |
|||
this.onChanged(true); |
|||
break; |
|||
case true: |
|||
this.onChanged(this.tristate ? (bool?) null : false); |
|||
break; |
|||
default: |
|||
this.onChanged(false); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void _handleTapUp(TapUpDetails details) { |
|||
this._downPosition = null; |
|||
if (this.isInteractive) { |
|||
this._reactionController.reverse(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapCancel() { |
|||
this._downPosition = null; |
|||
if (this.isInteractive) { |
|||
this._reactionController.reverse(); |
|||
} |
|||
} |
|||
|
|||
protected override bool hitTestSelf(Offset position) { |
|||
return true; |
|||
} |
|||
|
|||
public void handleEvent(PointerEvent pEvent, BoxHitTestEntry entry) { |
|||
D.assert(this.debugHandleEvent(pEvent, entry)); |
|||
if (pEvent is PointerDownEvent && this.isInteractive) { |
|||
this._tap.addPointer((PointerDownEvent) pEvent); |
|||
} |
|||
} |
|||
|
|||
public void paintRadialReaction(Canvas canvas, Offset offset, Offset origin) { |
|||
if (!this._reaction.isDismissed) { |
|||
Paint reactionPaint = new Paint {color = this.activeColor.withAlpha(Constants.kRadialReactionAlpha)}; |
|||
Offset center = Offset.lerp(this._downPosition ?? origin, origin, this._reaction.value); |
|||
float radius = ToggleableUtils._kRadialReactionRadiusTween.evaluate(this._reaction); |
|||
canvas.drawCircle(center + offset, radius, reactionPaint); |
|||
} |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FlagProperty("value", value: this.value, ifTrue: "checked", ifFalse: "unchecked", |
|||
showName: true)); |
|||
properties.add(new FlagProperty("isInteractive", value: this.isInteractive, ifTrue: "enabled", |
|||
ifFalse: "disabled", defaultValue: true)); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using UnityEngine; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public static class ThemeDataUtils { |
|||
public static readonly Color _kLightThemeHighlightColor = new Color(0x66BCBCBC); |
|||
|
|||
public static readonly Color _kLightThemeSplashColor = new Color(0x66C8C8C8); |
|||
|
|||
public static readonly Color _kDarkThemeHighlightColor = new Color(0x40CCCCCC); |
|||
|
|||
public static readonly Color _kDarkThemeSplashColor = new Color(0x40CCCCCC); |
|||
} |
|||
|
|||
public static class ThemeUtils { |
|||
public static readonly TimeSpan kThemeAnimationDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
} |
|||
|
|||
public static class MaterialConstantsUtils { |
|||
public static readonly Dictionary<MaterialType, BorderRadius> kMaterialEdges = |
|||
new Dictionary<MaterialType, BorderRadius> { |
|||
{MaterialType.canvas, null}, |
|||
{MaterialType.card, BorderRadius.circular(2.0f)}, |
|||
{MaterialType.circle, null}, |
|||
{MaterialType.button, BorderRadius.circular(2.0f)}, |
|||
{MaterialType.transparency, null} |
|||
}; |
|||
} |
|||
|
|||
public static class InkHighlightUtils { |
|||
public static readonly TimeSpan _kHighlightFadeDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
} |
|||
|
|||
public static class InkSplashUtils { |
|||
public static readonly TimeSpan _kUnconfirmedSplashDuration = new TimeSpan(0, 0, 0, 1, 0); |
|||
|
|||
public static readonly TimeSpan _kSplashFadeDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
|
|||
public const float _kSplashInitialSize = 0.0f; |
|||
|
|||
public const float _kSplashConfirmedVelocity = 1.0f; |
|||
|
|||
public static RectCallback _getClipCallback(RenderBox referenceBox, bool containedInkWell, |
|||
RectCallback rectCallback) { |
|||
if (rectCallback != null) { |
|||
D.assert(containedInkWell); |
|||
return rectCallback; |
|||
} |
|||
|
|||
if (containedInkWell) { |
|||
return () => Offset.zero & referenceBox.size; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static float _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback rectCallback, |
|||
Offset position) { |
|||
if (containedInkWell) { |
|||
Size size = rectCallback != null ? rectCallback().size : referenceBox.size; |
|||
return _getSplashRadiusForPositionInSize(size, position); |
|||
} |
|||
|
|||
return Material.defaultSplashRadius; |
|||
} |
|||
|
|||
static float _getSplashRadiusForPositionInSize(Size bounds, Offset position) { |
|||
float d1 = (position - bounds.topLeft(Offset.zero)).distance; |
|||
float d2 = (position - bounds.topRight(Offset.zero)).distance; |
|||
float d3 = (position - bounds.bottomLeft(Offset.zero)).distance; |
|||
float d4 = (position - bounds.bottomRight(Offset.zero)).distance; |
|||
return Mathf.Max(Mathf.Max(d1, d2), Mathf.Max(d3, d4)).ceil(); |
|||
} |
|||
} |
|||
|
|||
public static class InkRippleUtils { |
|||
public static readonly TimeSpan _kUnconfirmedRippleDuration = new TimeSpan(0, 0, 1); |
|||
public static readonly TimeSpan _kFadeInDuration = new TimeSpan(0, 0, 0, 0, 75); |
|||
public static readonly TimeSpan _kRadiusDuration = new TimeSpan(0, 0, 0, 0, 225); |
|||
public static readonly TimeSpan _kFadeOutDuration = new TimeSpan(0, 0, 0, 0, 375); |
|||
public static readonly TimeSpan _kCancelDuration = new TimeSpan(0, 0, 0, 0, 75); |
|||
|
|||
public const float _kFadeOutIntervalStart = 225.0f / 375.0f; |
|||
|
|||
public static RectCallback _getClipCallback(RenderBox referenceBox, bool containedInkWell, |
|||
RectCallback rectCallback) { |
|||
if (rectCallback != null) { |
|||
D.assert(containedInkWell); |
|||
return rectCallback; |
|||
} |
|||
|
|||
if (containedInkWell) { |
|||
return () => Offset.zero & referenceBox.size; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static float _getTargetRadius(RenderBox referenceBox, bool containedInkWell, RectCallback rectCallback, |
|||
Offset position) { |
|||
Size size = rectCallback != null ? rectCallback().size : referenceBox.size; |
|||
float d1 = size.bottomRight(Offset.zero).distance; |
|||
float d2 = (size.topRight(Offset.zero) - size.bottomLeft(Offset.zero)).distance; |
|||
return (Mathf.Max(d1, d2) / 2.0f); |
|||
} |
|||
} |
|||
|
|||
public static class ScrollbarUtils { |
|||
public static readonly TimeSpan _kScrollbarFadeDuration = TimeSpan.FromMilliseconds(300); |
|||
|
|||
public static readonly TimeSpan _kScrollbarTimeToFade = TimeSpan.FromMilliseconds(600); |
|||
|
|||
public const float _kScrollbarThickness = 6.0f; |
|||
} |
|||
|
|||
|
|||
public static class ArcUtils { |
|||
public const float _kOnAxisDelta = 2.0f; |
|||
|
|||
public static readonly List<_Diagonal> _allDiagonals = new List<_Diagonal> { |
|||
new _Diagonal(_CornerId.topLeft, _CornerId.bottomRight), |
|||
new _Diagonal(_CornerId.bottomRight, _CornerId.topLeft), |
|||
new _Diagonal(_CornerId.topRight, _CornerId.bottomLeft), |
|||
new _Diagonal(_CornerId.bottomLeft, _CornerId.topRight) |
|||
}; |
|||
|
|||
public delegate float _KeyFunc<T>(T input); |
|||
|
|||
|
|||
public static T _maxBy<T>(List<T> input, _KeyFunc<T> keyFunc) { |
|||
T maxValue = default(T); |
|||
float? maxKey = null; |
|||
foreach (T value in input) { |
|||
float key = keyFunc(value); |
|||
if (maxKey == null || key > maxKey) { |
|||
maxValue = value; |
|||
maxKey = key; |
|||
} |
|||
} |
|||
|
|||
return maxValue; |
|||
} |
|||
} |
|||
|
|||
public static class ExpansionTileUtils { |
|||
public static readonly TimeSpan _kExpand = new TimeSpan(0, 0, 0, 0, 200); |
|||
} |
|||
|
|||
public static class ExpansionPanelUtils { |
|||
public const float _kPanelHeaderCollapsedHeight = 48.0f; |
|||
public const float _kPanelHeaderExpandedHeight = 64.0f; |
|||
} |
|||
|
|||
public static class IconButtonUtils { |
|||
public const float _kMinButtonSize = 48.0f; |
|||
} |
|||
|
|||
public static class DrawerHeaderUtils { |
|||
public const float _kDrawerHeaderHeight = 160.0f + 1.0f; |
|||
} |
|||
|
|||
public static class DrawerUtils { |
|||
public const float _kWidth = 304.0f; |
|||
public const float _kEdgeDragWidth = 20.0f; |
|||
public const float _kMinFlingVelocity = 365.0f; |
|||
public static readonly TimeSpan _kBaseSettleDuration = new TimeSpan(0, 0, 0, 0, 246); |
|||
} |
|||
|
|||
public static class TooltipUtils { |
|||
public static readonly TimeSpan _kFadeDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
public static readonly TimeSpan _kShowDuration = new TimeSpan(0, 0, 0, 0, 1500); |
|||
} |
|||
|
|||
public static class AppUtils { |
|||
public static readonly TextStyle _errorTextStyle = new TextStyle( |
|||
color: new Color(0xD0FF0000), |
|||
fontFamily: "monospace", |
|||
fontSize: 48.0f, |
|||
fontWeight: FontWeight.w700, |
|||
decoration: TextDecoration.underline, |
|||
decorationColor: new Color(0xFFFFFF00), |
|||
decorationStyle: TextDecorationStyle.doubleLine |
|||
); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue