浏览代码

add toggle_button stuffs

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
b8432d5a
共有 2 个文件被更改,包括 392 次插入19 次删除
  1. 159
      com.unity.uiwidgets/Runtime/material/toggleable.cs
  2. 252
      com.unity.uiwidgets/Runtime/material/toggle_buttons_theme.cs

159
com.unity.uiwidgets/Runtime/material/toggleable.cs


public static readonly Animatable<float> _kRadialReactionRadiusTween =
new FloatTween(begin: 0.0f, end: Constants.kRadialReactionRadius);
public static readonly TimeSpan _kReactionFadeDuration = new TimeSpan(0, 0, 0, 0, 50);
}
public abstract class RenderToggleable : RenderConstrainedBox {

Color activeColor = null,
Color inactiveColor = null,
Color hoverColor = null,
Color focusColor = null,
TickerProvider vsync = null
TickerProvider vsync = null,
bool hasFocus = false,
bool hovering = false
) : base(additionalConstraints: additionalConstraints) {
D.assert(tristate || value != null);
D.assert(activeColor != null);

_tristate = tristate;
_activeColor = activeColor;
_inactiveColor = inactiveColor;
_hoverColor = hoverColor ?? activeColor.withAlpha(Constants.kRadialReactionAlpha);
_focusColor = focusColor ?? activeColor.withAlpha(Constants.kRadialReactionAlpha);
_hasFocus = hasFocus;
_hovering = hovering;
_vsync = vsync;
_tap = new TapGestureRecognizer {

parent: _positionController,
curve: Curves.linear);
_position.addListener(markNeedsPaint);
_position.addStatusListener(_handlePositionStateChanged);
_reactionHoverFadeController = new AnimationController(
duration: ToggleableUtils._kReactionFadeDuration,
value: hovering || hasFocus ? 1.0f : 0.0f,
vsync: vsync
);
_reactionHoverFade = new CurvedAnimation(
parent: _reactionHoverFadeController,
curve: Curves.fastOutSlowIn
);
_reactionHoverFade.addListener(markNeedsPaint);
_reactionFocusFadeController = new AnimationController(
duration: ToggleableUtils._kReactionFadeDuration,
value: hovering || hasFocus ? 1.0f : 0.0f,
vsync: vsync
);
_reactionFocusFade = new CurvedAnimation(
parent: _reactionFocusFadeController,
curve: Curves.fastOutSlowIn
);
_reactionFocusFade.addListener(markNeedsPaint);
}
protected AnimationController positionController {

}
AnimationController _reactionController;
Animation<float> _reaction;
Animation<float> _reaction;
protected AnimationController reactionFocusFadeController {
get { return _reactionFocusFadeController; }
}
AnimationController _reactionFocusFadeController;
Animation<float> _reactionFocusFade;
protected AnimationController reactionHoverFadeController {
get { return _reactionHoverFadeController; }
}
AnimationController _reactionHoverFadeController;
Animation<float> _reactionHoverFade;
public bool hasFocus {
get { return _hasFocus; }
set {
if (value == _hasFocus) {
return;
}
_hasFocus = value;
if (_hasFocus) {
_reactionFocusFadeController.forward();
}
else {
_reactionFocusFadeController.reverse();
}
markNeedsPaint();
}
}
bool _hasFocus;
public bool hovering {
get { return _hovering; }
set {
if (value == _hovering) {
return;
}
_hovering = value;
if (_hovering) {
_reactionHoverFadeController.forward();
}
else {
_reactionHoverFadeController.reverse();
}
markNeedsPaint();
}
}
bool _hovering;
public TickerProvider vsync {
get { return _vsync; }

}
}
public Color hoverColor {
get { return _hoverColor; }
set {
if (value == _hoverColor) {
return;
}
_hoverColor = value;
markNeedsPaint();
}
}
Color _hoverColor;
public Color focusColor {
get { return _focusColor; }
set {
if (value == _focusColor) {
return;
}
_focusColor = value;
markNeedsPaint();
}
}
Color _focusColor;
public Color reactionColor {
get { return _reactionColor; }
set {
if (value == _reactionColor) {
return;
}
_reactionColor = value;
markNeedsPaint();
}
}
Color _reactionColor;
ValueChanged<bool?> _onChanged;
public bool isInteractive {

base.detach();
}
void _handlePositionStateChanged(AnimationStatus status) {
if (isInteractive && !tristate) {
if (status == AnimationStatus.completed && _value == false) {
onChanged(true);
}
else if (status == AnimationStatus.dismissed && _value != false) {
onChanged(false);
}
}
}
void _handleTapDown(TapDownDetails details) {
if (isInteractive) {
_downPosition = globalToLocal(details.globalPosition);

}
public void paintRadialReaction(Canvas canvas, Offset offset, Offset origin) {
if (!_reaction.isDismissed) {
Paint reactionPaint = new Paint {color = activeColor.withAlpha(Constants.kRadialReactionAlpha)};
if (!_reaction.isDismissed || !_reactionFocusFade.isDismissed || !_reactionHoverFade.isDismissed) {
Paint reactionPaint = new Paint();
reactionPaint.color = Color.lerp(
Color.lerp(activeColor.withAlpha(Constants.kRadialReactionAlpha), hoverColor,
_reactionHoverFade.value),
focusColor,
_reactionFocusFade.value);
float radius = ToggleableUtils._kRadialReactionRadiusTween.evaluate(_reaction);
canvas.drawCircle(center + offset, radius, reactionPaint);
float reactionRadius = hasFocus || hovering
? Constants.kRadialReactionRadius
: ToggleableUtils._kRadialReactionRadiusTween.evaluate(_reaction);
if (reactionRadius > 0.0f) {
canvas.drawCircle(center + offset, reactionRadius, reactionPaint);
}
}
}

252
com.unity.uiwidgets/Runtime/material/toggle_buttons_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public class ToggleButtonsThemeData : Diagnosticable,IEquatable<ToggleButtonsThemeData> {
public ToggleButtonsThemeData(
TextStyle textStyle = null,
BoxConstraints constraints = null,
Color color = null,
Color selectedColor = null,
Color disabledColor = null,
Color fillColor = null,
Color focusColor = null,
Color highlightColor = null,
Color hoverColor = null,
Color splashColor = null,
Color borderColor = null,
Color selectedBorderColor = null,
Color disabledBorderColor = null,
BorderRadius borderRadius = null,
float? borderWidth = null
) {
this.textStyle = textStyle;
this.constraints = constraints;
this.color = color;
this.selectedColor = selectedColor;
this.disabledColor = disabledColor;
this.fillColor = fillColor;
this.focusColor = focusColor;
this.highlightColor = highlightColor;
this.hoverColor = hoverColor;
this.splashColor = splashColor;
this.borderColor = borderColor;
this.selectedBorderColor = selectedBorderColor;
this.disabledBorderColor = disabledBorderColor;
this.borderRadius = borderRadius;
this.borderWidth = borderWidth;
}
public readonly TextStyle textStyle;
public readonly BoxConstraints constraints;
public readonly Color color;
public readonly Color selectedColor;
public readonly Color disabledColor;
public readonly Color fillColor;
public readonly Color focusColor;
public readonly Color highlightColor;
public readonly Color splashColor;
public readonly Color hoverColor;
public readonly Color borderColor;
public readonly Color selectedBorderColor;
public readonly Color disabledBorderColor;
public readonly float? borderWidth;
public readonly BorderRadius borderRadius;
public ToggleButtonsThemeData copyWith(
TextStyle textStyle = null,
BoxConstraints constraints = null,
Color color = null,
Color selectedColor = null,
Color disabledColor = null,
Color fillColor = null,
Color focusColor = null,
Color highlightColor = null,
Color splashColor = null,
Color hoverColor = null,
Color borderColor = null,
Color selectedBorderColor = null,
Color disabledBorderColor = null,
BorderRadius borderRadius = null,
float? borderWidth = null) {
return new ToggleButtonsThemeData(
textStyle: textStyle ?? this.textStyle,
constraints: constraints ?? this.constraints,
color: color ?? this.color,
selectedColor: selectedColor ?? this.selectedColor,
disabledColor: disabledColor ?? this.disabledColor,
fillColor: fillColor ?? this.fillColor,
focusColor: focusColor ?? this.focusColor,
highlightColor: highlightColor ?? this.highlightColor,
hoverColor: hoverColor ?? this.hoverColor,
splashColor: splashColor ?? this.splashColor,
borderColor: borderColor ?? this.borderColor,
selectedBorderColor: selectedBorderColor ?? this.selectedBorderColor,
disabledBorderColor: disabledBorderColor ?? this.disabledBorderColor,
borderRadius: borderRadius ?? this.borderRadius,
borderWidth: borderWidth ?? this.borderWidth
);
}
public static ToggleButtonsThemeData lerp(ToggleButtonsThemeData a, ToggleButtonsThemeData b, float t) {
if (a == null && b == null) {
return null;
}
return new ToggleButtonsThemeData(
textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t),
constraints: BoxConstraints.lerp(a?.constraints, b?.constraints, t),
color: Color.lerp(a?.color, b?.color, t),
selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t),
disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t),
fillColor: Color.lerp(a?.fillColor, b?.fillColor, t),
focusColor: Color.lerp(a?.focusColor, b?.focusColor, t),
highlightColor: Color.lerp(a?.highlightColor, b?.highlightColor, t),
hoverColor: Color.lerp(a?.hoverColor, b?.hoverColor, t),
splashColor: Color.lerp(a?.splashColor, b?.splashColor, t),
borderColor: Color.lerp(a?.borderColor, b?.borderColor, t),
selectedBorderColor: Color.lerp(a?.selectedBorderColor, b?.selectedBorderColor, t),
disabledBorderColor: Color.lerp(a?.disabledBorderColor, b?.disabledBorderColor, t),
borderRadius: BorderRadius.lerp(a?.borderRadius, b?.borderRadius, t),
borderWidth: MathUtils.lerpNullableFloat(a?.borderWidth, b?.borderWidth, t)
);
}
public bool Equals(ToggleButtonsThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return textStyle.Equals(other.textStyle)
&& constraints.Equals(other.constraints)
&& color.Equals(other.color)
&& selectedColor.Equals(other.selectedColor)
&& disabledColor.Equals(other.disabledColor)
&& fillColor.Equals(other.fillColor)
&& focusColor.Equals(other.focusColor)
&& highlightColor.Equals(other.highlightColor)
&& hoverColor.Equals(other.hoverColor)
&& splashColor.Equals(other.splashColor)
&& borderColor.Equals(other.borderColor)
&& selectedBorderColor.Equals(other.selectedBorderColor)
&& disabledBorderColor.Equals(other.disabledBorderColor)
&& borderRadius.Equals(other.borderRadius)
&& borderWidth.Equals(other.borderWidth);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((ToggleButtonsThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (textStyle != null ? textStyle.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (constraints != null ? constraints.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (color != null ? color.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (selectedColor != null ? selectedColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (disabledColor != null ? disabledColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (fillColor != null ? fillColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (focusColor != null ? focusColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (highlightColor != null ? highlightColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (hoverColor != null ? hoverColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (splashColor != null ? splashColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (borderColor != null ? borderColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (selectedBorderColor != null ? selectedBorderColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (disabledBorderColor != null ? disabledBorderColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (borderRadius != null ? borderRadius.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (borderWidth != null ? borderWidth.GetHashCode() : 0);
return hashCode;
}
}
public static bool operator ==(ToggleButtonsThemeData left, ToggleButtonsThemeData right) {
return Equals(left, right);
}
public static bool operator !=(ToggleButtonsThemeData left, ToggleButtonsThemeData right) {
return !Equals(left, right);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
textStyle?.debugFillProperties(properties, prefix: "textStyle.");
properties.add( new DiagnosticsProperty<BoxConstraints>("constraints", constraints, defaultValue: null));
properties.add( new ColorProperty("color", color, defaultValue: null));
properties.add( new ColorProperty("selectedColor", selectedColor, defaultValue: null));
properties.add( new ColorProperty("disabledColor", disabledColor, defaultValue: null));
properties.add( new ColorProperty("fillColor", fillColor, defaultValue: null));
properties.add( new ColorProperty("focusColor", focusColor, defaultValue: null));
properties.add( new ColorProperty("highlightColor", highlightColor, defaultValue: null));
properties.add( new ColorProperty("hoverColor", hoverColor, defaultValue: null));
properties.add( new ColorProperty("splashColor", splashColor, defaultValue: null));
properties.add( new ColorProperty("borderColor", borderColor, defaultValue: null));
properties.add( new ColorProperty("selectedBorderColor", selectedBorderColor, defaultValue: null));
properties.add( new ColorProperty("disabledBorderColor", disabledBorderColor, defaultValue: null));
properties.add( new DiagnosticsProperty<BorderRadius>("borderRadius", borderRadius, defaultValue: null));
properties.add( new FloatProperty("borderWidth", borderWidth, defaultValue: null));
}
}
public class ToggleButtonsTheme : InheritedTheme {
public ToggleButtonsTheme(
Key key = null,
ToggleButtonsThemeData data = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(data != null);
this.data = data;
}
public readonly ToggleButtonsThemeData data;
static ToggleButtonsThemeData of(BuildContext context) {
ToggleButtonsTheme toggleButtonsTheme = context.dependOnInheritedWidgetOfExactType<ToggleButtonsTheme>();
return toggleButtonsTheme?.data ?? Theme.of(context).toggleButtonsTheme;
}
public override Widget wrap(BuildContext context, Widget child) {
ToggleButtonsTheme ancestorTheme = context.findAncestorWidgetOfExactType<ToggleButtonsTheme>();
return ReferenceEquals(this, ancestorTheme) ? child : new ToggleButtonsTheme(data: data, child: child);
}
public override bool updateShouldNotify(InheritedWidget oldWidget) {
D.assert(oldWidget is ToggleButtonsTheme);
return data != ((ToggleButtonsTheme)oldWidget).data;
}
}
}
正在加载...
取消
保存