浏览代码

Merge branch 'siyaoH/1.17/material' of github.com:Unity-Technologies/com.unity.uiwidgets into zxw/1.17/material

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
2d8ce42f
共有 13 个文件被更改,包括 1555 次插入7 次删除
  1. 64
      com.unity.uiwidgets/Runtime/material/material_button.cs
  2. 28
      com.unity.uiwidgets/Runtime/material/theme_data.cs
  3. 6
      com.unity.uiwidgets/Runtime/widgets/basic.cs
  4. 135
      com.unity.uiwidgets/Runtime/material/banner_theme.cs
  5. 123
      com.unity.uiwidgets/Runtime/material/button_sheet_theme.cs
  6. 144
      com.unity.uiwidgets/Runtime/material/divider_theme.cs
  7. 580
      com.unity.uiwidgets/Runtime/material/navigation_rail.cs
  8. 3
      com.unity.uiwidgets/Runtime/material/navigation_rail.cs.meta
  9. 189
      com.unity.uiwidgets/Runtime/material/navigation_rail_theme.cs
  10. 3
      com.unity.uiwidgets/Runtime/material/navigation_rail_theme.cs.meta
  11. 136
      com.unity.uiwidgets/Runtime/material/popup_menu_theme.cs
  12. 148
      com.unity.uiwidgets/Runtime/material/snack_bar_theme.cs
  13. 3
      com.unity.uiwidgets/Runtime/material/snack_bar_theme.cs.meta

64
com.unity.uiwidgets/Runtime/material/material_button.cs


public MaterialButton(
Key key = null,
VoidCallback onPressed = null,
VoidCallback onLongPress = null,
ValueChanged<bool> onHighlightChanged = null,
ButtonTextTheme? textTheme = null,
Color textColor = null,

Color focusColor = null,
Color hoverColor = null,
float? focusElevation = null,
float? hoverElevation = null,
VisualDensity visualDensity = null,
FocusNode focusNode = null,
bool? autofocus = false,
bool? enableFeedback = true,
D.assert(clipBehavior != null);
D.assert(autofocus != null);
D.assert(elevation == null || elevation >= 0.0f);
D.assert(focusElevation == null || focusElevation >= 0.0f);
D.assert(hoverElevation == null || hoverElevation >= 0.0f);
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(disabledElevation == null || disabledElevation >= 0.0f);
this.onLongPress = onLongPress;
this.onHighlightChanged = onHighlightChanged;
this.textTheme = textTheme;
this.textColor = textColor;

this.focusColor = focusColor;
this.hoverColor = hoverColor;
this.focusElevation = focusElevation;
this.hoverElevation = hoverElevation;
this.visualDensity = visualDensity;
this.focusNode = focusNode;
this.enableFeedback = enableFeedback;
public readonly VoidCallback onLongPress;
public readonly ValueChanged<bool> onHighlightChanged;

public readonly Color focusColor;
public readonly Color hoverColor;
public readonly Color highlightColor;
public readonly float? elevation;

public readonly float? focusElevation;
public readonly float? highlightElevation;
public readonly float? disabledElevation;

}
public readonly EdgeInsets padding;
public readonly VisualDensity visualDensity;
public readonly ShapeBorder shape;

public readonly FocusNode focusNode;
public readonly bool? autofocus;
public readonly TimeSpan? animationDuration;
public readonly MaterialTapTargetSize? materialTapTargetSize;

public readonly float? height;
public readonly bool? enableFeedback;
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
ButtonThemeData buttonTheme = ButtonTheme.of(context);

onLongPress:() => onLongPress(),
enableFeedback: enableFeedback?? true,
focusColor: focusColor ?? buttonTheme.getFocusColor(this) ?? theme.focusColor,
hoverColor: hoverColor ?? buttonTheme.getHoverColor(this) ?? theme.hoverColor,
focusElevation: buttonTheme.getFocusElevation(this),
hoverElevation: buttonTheme.getHoverElevation(this),
visualDensity: visualDensity ?? theme.visualDensity,
focusNode: focusNode,
autofocus: autofocus ?? false,
animationDuration: buttonTheme.getAnimationDuration(this),
child: child,
materialTapTargetSize: materialTapTargetSize ?? theme.materialTapTargetSize);

public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagProperty("enabled", value: enabled, ifFalse: "disabled"));
properties.add(new DiagnosticsProperty<ButtonTextTheme?>("textTheme", textTheme, defaultValue: null));
properties.add(new ColorProperty("textColor", textColor, defaultValue: null));
properties.add(new ColorProperty("disabledTextColor", disabledTextColor, defaultValue: null));
properties.add(new ColorProperty("color", color, defaultValue: null));
properties.add(new ColorProperty("disabledColor", disabledColor, defaultValue: null));
properties.add(new ColorProperty("focusColor", focusColor, defaultValue: null));
properties.add(new ColorProperty("hoverColor", hoverColor, defaultValue: null));
properties.add(new ColorProperty("highlightColor", highlightColor, defaultValue: null));
properties.add(new ColorProperty("splashColor", splashColor, defaultValue: null));
properties.add(
new DiagnosticsProperty<Brightness?>("colorBrightness", colorBrightness, defaultValue: null));
properties.add(new DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding, defaultValue: null));
properties.add(new DiagnosticsProperty<VisualDensity>("visualDensity", visualDensity, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", shape, defaultValue: null));
properties.add(new DiagnosticsProperty<FocusNode>("focusNode", focusNode, defaultValue: null));
properties.add(new DiagnosticsProperty<MaterialTapTargetSize?>("materialTapTargetSize",
materialTapTargetSize, defaultValue: null));
}
}

28
com.unity.uiwidgets/Runtime/material/theme_data.cs


using System.Collections.Generic;
using System.Linq;
using uiwidgets;
using Unity.UIWidgets.cupertino;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;

public readonly Brightness brightness;
public readonly VisualDensity visualDensity;
public readonly Color primaryColor;

public readonly Color cardColor;
public readonly Color dividerColor;
public readonly Color focusColor;
public readonly Color hoverColor;
public readonly Color highlightColor;

public readonly IconThemeData accentIconTheme;
public readonly TabBarTheme tabBarTheme;
public readonly TooltipThemeData tooltipTheme;
public readonly CardTheme cardTheme;

public readonly ColorScheme colorScheme;
public readonly SnackBarThemeData snackBarTheme;
public readonly NavigationRailThemeData navigationRailTheme;
public readonly BottomSheetThemeData bottomSheetTheme;
public readonly CupertinoThemeData cupertinoOverrideTheme;
/// A theme for customizing the color, shape, elevation, and text style of
/// popup menus.
public readonly PopupMenuThemeData popupMenuTheme;
/// A theme for customizing the color and text style of a [MaterialBanner].
public readonly MaterialBannerThemeData bannerTheme;
/// A theme for customizing the color, thickness, and indents of [Divider]s,
/// [VerticalDivider]s, etc.
public readonly DividerThemeData dividerTheme;
public readonly ButtonBarThemeData buttonBarTheme;
public ThemeData copyWith(

6
com.unity.uiwidgets/Runtime/widgets/basic.cs


public class Align : SingleChildRenderObjectWidget {
public Align(
Key key = null,
Alignment alignment = null,
AlignmentGeometry alignment = null,
float? widthFactor = null,
float? heightFactor = null,
Widget child = null

this.alignment = alignment ?? Alignment.center;
//TODO: update to AlignmentGeometry
this.alignment = (Alignment) alignment ?? Alignment.center;
this.widthFactor = widthFactor;
this.heightFactor = heightFactor;
}

135
com.unity.uiwidgets/Runtime/material/banner_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public class MaterialBannerThemeData : Diagnosticable, IEquatable<MaterialBannerThemeData> {
public MaterialBannerThemeData(
Color backgroundColor = null,
TextStyle contentTextStyle = null,
EdgeInsetsGeometry padding = null,
EdgeInsetsGeometry leadingPadding = null
) {
this.backgroundColor = backgroundColor;
this.contentTextStyle = contentTextStyle;
this.padding = padding;
this.leadingPadding = leadingPadding;
}
public readonly Color backgroundColor;
public readonly TextStyle contentTextStyle;
public readonly EdgeInsetsGeometry padding;
public readonly EdgeInsetsGeometry leadingPadding;
public MaterialBannerThemeData copyWith(
Color backgroundColor = null,
TextStyle contentTextStyle = null,
EdgeInsetsGeometry padding = null,
EdgeInsetsGeometry leadingPadding = null
) {
return new MaterialBannerThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
contentTextStyle: contentTextStyle ?? this.contentTextStyle,
padding: padding ?? this.padding,
leadingPadding: leadingPadding ?? this.leadingPadding
);
}
public static MaterialBannerThemeData lerp(MaterialBannerThemeData a, MaterialBannerThemeData b, float t) {
return new MaterialBannerThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
leadingPadding: EdgeInsetsGeometry.lerp(a?.leadingPadding, b?.leadingPadding, t)
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ColorProperty("backgroundColor", backgroundColor, defaultValue: null));
properties.add(
new DiagnosticsProperty<TextStyle>("contentTextStyle", contentTextStyle, defaultValue: null));
properties.add(new DiagnosticsProperty<EdgeInsetsGeometry>("padding", padding, defaultValue: null));
properties.add(
new DiagnosticsProperty<EdgeInsetsGeometry>("leadingPadding", leadingPadding, defaultValue: null));
}
public static bool operator ==(MaterialBannerThemeData self, MaterialBannerThemeData other) {
return Equals(self, other);
}
public static bool operator !=(MaterialBannerThemeData self, MaterialBannerThemeData other) {
return !Equals(self, other);
}
public bool Equals(MaterialBannerThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(backgroundColor, other.backgroundColor) && Equals(contentTextStyle, other.contentTextStyle) &&
Equals(padding, other.padding) && Equals(leadingPadding, other.leadingPadding);
}
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((MaterialBannerThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (backgroundColor != null ? backgroundColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (contentTextStyle != null ? contentTextStyle.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (padding != null ? padding.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (leadingPadding != null ? leadingPadding.GetHashCode() : 0);
return hashCode;
}
}
}
public class MaterialBannerTheme : InheritedTheme {
public MaterialBannerTheme(
Key key = null,
MaterialBannerThemeData data = null,
Widget child = null
) : base(key: key, child: child) {
this.data = data;
}
public readonly MaterialBannerThemeData data;
static MaterialBannerThemeData of(BuildContext context) {
MaterialBannerTheme bannerTheme = context.dependOnInheritedWidgetOfExactType<MaterialBannerTheme>();
return bannerTheme?.data ?? Theme.of(context).bannerTheme;
}
public override Widget wrap(BuildContext context, Widget child) {
MaterialBannerTheme ancestorTheme = context.findAncestorWidgetOfExactType<MaterialBannerTheme>();
return ReferenceEquals(this, ancestorTheme) ? child : new MaterialBannerTheme(data: data, child: child);
}
public override bool updateShouldNotify(InheritedWidget oldWidget) =>
oldWidget is MaterialBannerTheme materialBannerTheme && data != materialBannerTheme.data;
}
}

123
com.unity.uiwidgets/Runtime/material/button_sheet_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
public class BottomSheetThemeData : Diagnosticable, IEquatable<BottomSheetThemeData> {
public BottomSheetThemeData(
Color backgroundColor = null,
float? elevation = null,
Color modalBackgroundColor = null,
float? modalElevation = null,
ShapeBorder shape = null,
Clip? clipBehavior = null
) {
this.backgroundColor = backgroundColor;
this.elevation = elevation;
this.modalBackgroundColor = modalBackgroundColor;
this.modalElevation = modalElevation;
this.shape = shape;
this.clipBehavior = clipBehavior;
}
public readonly Color backgroundColor;
public readonly float? elevation;
public readonly Color modalBackgroundColor;
public readonly float? modalElevation;
public readonly ShapeBorder shape;
public readonly Clip? clipBehavior;
public BottomSheetThemeData copyWith(
Color backgroundColor = null,
float? elevation = null,
Color modalBackgroundColor = null,
float? modalElevation = null,
ShapeBorder shape = null,
Clip? clipBehavior = null
) {
return new BottomSheetThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
elevation: elevation ?? this.elevation,
modalBackgroundColor: modalBackgroundColor ?? this.modalBackgroundColor,
modalElevation: modalElevation ?? this.modalElevation,
shape: shape ?? this.shape,
clipBehavior: clipBehavior ?? this.clipBehavior
);
}
public static BottomSheetThemeData lerp(BottomSheetThemeData a, BottomSheetThemeData b, float t) {
D.assert(t != null);
if (a == null && b == null)
return null;
return new BottomSheetThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
elevation: Mathf.Lerp(a?.elevation ?? 0, b?.elevation ?? 0, t),
modalBackgroundColor: Color.lerp(a?.modalBackgroundColor, b?.modalBackgroundColor, t),
modalElevation: Mathf.Lerp(a?.modalElevation ?? 0, b?.modalElevation ?? 0, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, t),
clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ColorProperty("backgroundColor", backgroundColor, defaultValue: null));
properties.add(new FloatProperty("elevation", elevation, defaultValue: null));
properties.add(new ColorProperty("modalBackgroundColor", modalBackgroundColor, defaultValue: null));
properties.add(new FloatProperty("modalElevation", modalElevation, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", shape, defaultValue: null));
properties.add(new DiagnosticsProperty<Clip?>("clipBehavior", clipBehavior, defaultValue: null));
}
public bool Equals(BottomSheetThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(backgroundColor, other.backgroundColor) && Nullable.Equals(elevation, other.elevation) &&
Equals(modalBackgroundColor, other.modalBackgroundColor) &&
Nullable.Equals(modalElevation, other.modalElevation) && Equals(shape, other.shape) &&
clipBehavior == other.clipBehavior;
}
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((BottomSheetThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (backgroundColor != null ? backgroundColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ elevation.GetHashCode();
hashCode = (hashCode * 397) ^ (modalBackgroundColor != null ? modalBackgroundColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ modalElevation.GetHashCode();
hashCode = (hashCode * 397) ^ (shape != null ? shape.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ clipBehavior.GetHashCode();
return hashCode;
}
}
}
}

144
com.unity.uiwidgets/Runtime/material/divider_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
public class DividerThemeData : Diagnosticable, IEquatable<DividerThemeData> {
public DividerThemeData(
Color color = null,
float? space = null,
float? thickness = null,
float? indent = null,
float? endIndent = null
) {
this.color = color;
this.space = space;
this.thickness = thickness;
this.indent = indent;
this.endIndent = endIndent;
}
public readonly Color color;
public readonly float? space;
public readonly float? thickness;
public readonly float? indent;
public readonly float? endIndent;
public DividerThemeData copyWith(
Color color = null,
float? space = null,
float? thickness = null,
float? indent = null,
float? endIndent = null
) {
return new DividerThemeData(
color: color ?? this.color,
space: space ?? this.space,
thickness: thickness ?? this.thickness,
indent: indent ?? this.indent,
endIndent: endIndent ?? this.endIndent
);
}
public static DividerThemeData lerp(DividerThemeData a, DividerThemeData b, float t) {
return new DividerThemeData(
color: Color.lerp(a?.color, b?.color, t),
space: Mathf.Lerp(a?.space ?? 0, b?.space ?? 0, t),
thickness: Mathf.Lerp(a?.thickness ?? 0, b?.thickness ?? 0, t),
indent: Mathf.Lerp(a?.indent ?? 0, b?.indent ?? 0, t),
endIndent: Mathf.Lerp(a?.endIndent ?? 0, b?.endIndent ?? 0, t)
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ColorProperty("color", color, defaultValue: null));
properties.add(new FloatProperty("space", space, defaultValue: null));
properties.add(new FloatProperty("thickness", thickness, defaultValue: null));
properties.add(new FloatProperty("indent", indent, defaultValue: null));
properties.add(new FloatProperty("endIndent", endIndent, defaultValue: null));
}
public static bool operator ==(DividerThemeData self, DividerThemeData other) {
return Equals(self, other);
}
public static bool operator !=(DividerThemeData self, DividerThemeData other) {
return !Equals(self, other);
}
public bool Equals(DividerThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(color, other.color) && Nullable.Equals(space, other.space) &&
Nullable.Equals(thickness, other.thickness) && Nullable.Equals(indent, other.indent) &&
Nullable.Equals(endIndent, other.endIndent);
}
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((DividerThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (color != null ? color.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ space.GetHashCode();
hashCode = (hashCode * 397) ^ thickness.GetHashCode();
hashCode = (hashCode * 397) ^ indent.GetHashCode();
hashCode = (hashCode * 397) ^ endIndent.GetHashCode();
return hashCode;
}
}
}
public class DividerTheme : InheritedTheme {
public DividerTheme(
Key key = null,
DividerThemeData data = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(data != null);
this.data = data;
}
public readonly DividerThemeData data;
public static DividerThemeData of(BuildContext context) {
DividerTheme dividerTheme = context.dependOnInheritedWidgetOfExactType<DividerTheme>();
return dividerTheme?.data ?? Theme.of(context).dividerTheme;
}
public override Widget wrap(BuildContext context, Widget child) {
DividerTheme ancestorTheme = context.findAncestorWidgetOfExactType<DividerTheme>();
return ReferenceEquals(this, ancestorTheme) ? child : new DividerTheme(data: data, child: child);
}
public override bool updateShouldNotify(InheritedWidget oldWidget) =>
oldWidget is DividerTheme dividerTheme && data != dividerTheme.data;
}
}

580
com.unity.uiwidgets/Runtime/material/navigation_rail.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
class NavigationRail : StatefulWidget {
public NavigationRail(
Color backgroundColor = null,
bool? extended = null,
Widget leading = null,
Widget trailing = null,
List<NavigationRailDestination> destinations = null,
int? selectedIndex = null,
ValueChanged<int> onDestinationSelected = null,
float? elevation = null,
float? groupAlignment = null,
NavigationRailLabelType? labelType = null,
TextStyle unselectedLabelTextStyle = null,
TextStyle selectedLabelTextStyle = null,
IconThemeData unselectedIconTheme = null,
IconThemeData selectedIconTheme = null,
float? minWidth = null,
float? minExtendedWidth = null
) {
D.assert(destinations != null && destinations.Count >= 2);
D.assert(selectedIndex != null);
D.assert(0 <= selectedIndex && selectedIndex < destinations.Count);
D.assert(elevation == null || elevation > 0);
D.assert(minWidth == null || minWidth > 0);
D.assert(minExtendedWidth == null || minExtendedWidth > 0);
D.assert((minWidth == null || minExtendedWidth == null) || minExtendedWidth >= minWidth);
D.assert(extended != null);
D.assert(!extended.Value || (labelType == null || labelType == NavigationRailLabelType.none));
this.backgroundColor = backgroundColor;
this.extended = extended;
this.leading = leading;
this.trailing = trailing;
this.destinations = destinations;
this.selectedIndex = selectedIndex;
this.onDestinationSelected = onDestinationSelected;
this.elevation = elevation;
this.groupAlignment = groupAlignment;
this.labelType = labelType;
this.unselectedLabelTextStyle = unselectedLabelTextStyle;
this.selectedLabelTextStyle = selectedLabelTextStyle;
this.unselectedIconTheme = unselectedIconTheme;
this.selectedIconTheme = selectedIconTheme;
this.minWidth = minWidth;
this.minExtendedWidth = minExtendedWidth;
}
public readonly Color backgroundColor;
public readonly bool? extended;
public readonly Widget leading;
public readonly Widget trailing;
public readonly List<NavigationRailDestination> destinations;
public readonly int? selectedIndex;
public readonly ValueChanged<int> onDestinationSelected;
public readonly float? elevation;
public readonly float? groupAlignment;
public readonly NavigationRailLabelType? labelType;
public readonly TextStyle unselectedLabelTextStyle;
public readonly TextStyle selectedLabelTextStyle;
public readonly IconThemeData unselectedIconTheme;
public readonly IconThemeData selectedIconTheme;
public readonly float? minWidth;
public readonly float? minExtendedWidth;
public static Animation<float> extendedAnimation(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<_ExtendedNavigationRailAnimation>().animation;
}
public override State createState() => new _NavigationRailState();
}
class _NavigationRailState : TickerProviderStateMixin<NavigationRail> {
List<AnimationController> _destinationControllers = new List<AnimationController>();
List<Animation<float>> _destinationAnimations;
AnimationController _extendedController;
Animation<float> _extendedAnimation;
public override void initState() {
base.initState();
_initControllers();
}
public override void dispose() {
_disposeControllers();
base.dispose();
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
var checkOldWidget = (NavigationRail) oldWidget;
if (oldWidget is NavigationRail navigationRail) {
if (widget.extended != navigationRail.extended) {
if (widget.extended ?? false) {
_extendedController.forward();
}
else {
_extendedController.reverse();
}
}
if (widget.destinations.Count != navigationRail.destinations.Count) {
_resetState();
return;
}
if (widget.selectedIndex != navigationRail.selectedIndex) {
_destinationControllers[navigationRail.selectedIndex.Value].reverse();
_destinationControllers[widget.selectedIndex.Value].forward();
return;
}
}
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
NavigationRailThemeData navigationRailTheme = NavigationRailTheme.of(context);
MaterialLocalizations localizations = MaterialLocalizations.of(context);
Color backgroundColor =
widget.backgroundColor ?? navigationRailTheme.backgroundColor ?? theme.colorScheme.surface;
float elevation = widget.elevation ?? navigationRailTheme.elevation ?? 0;
float minWidth = widget.minWidth ?? material_._minRailWidth;
float minExtendedWidth = widget.minExtendedWidth ?? material_._minExtendedRailWidth;
Color baseSelectedColor = theme.colorScheme.primary;
Color baseColor = theme.colorScheme.onSurface.withOpacity(0.64f);
IconThemeData defaultUnselectedIconTheme =
widget.unselectedIconTheme ?? navigationRailTheme.unselectedIconTheme;
IconThemeData unselectedIconTheme = new IconThemeData(
size: defaultUnselectedIconTheme?.size ?? 24.0f,
color: defaultUnselectedIconTheme?.color ?? theme.colorScheme.onSurface,
opacity: defaultUnselectedIconTheme?.opacity ?? 1.0f
);
IconThemeData defaultSelectedIconTheme = widget.selectedIconTheme ?? navigationRailTheme.selectedIconTheme;
IconThemeData selectedIconTheme = new IconThemeData(
size: defaultSelectedIconTheme?.size ?? 24.0f,
color: defaultSelectedIconTheme?.color ?? theme.colorScheme.primary,
opacity: defaultSelectedIconTheme?.opacity ?? 0.64f
);
TextStyle unselectedLabelTextStyle = theme.textTheme.bodyText1.copyWith(color: baseColor)
.merge(widget.unselectedLabelTextStyle ?? navigationRailTheme.unselectedLabelTextStyle);
TextStyle selectedLabelTextStyle = theme.textTheme.bodyText1.copyWith(color: baseSelectedColor)
.merge(widget.selectedLabelTextStyle ?? navigationRailTheme.selectedLabelTextStyle);
float groupAlignment = widget.groupAlignment ?? navigationRailTheme.groupAlignment ?? -1.0f;
NavigationRailLabelType labelType =
widget.labelType ?? navigationRailTheme.labelType ?? NavigationRailLabelType.none;
var materialChildren = new List<Widget>();
materialChildren.Add(material_._verticalSpacer);
if (widget.leading != null) {
materialChildren.AddRange(new List<Widget>() {
new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: Mathf.Lerp(minWidth, minExtendedWidth, _extendedAnimation.value)
),
child: widget.leading
),
material_._verticalSpacer,
});
}
var alignChildren = new List<Widget>();
for (int i = 0; i < widget.destinations.Count; i += 1) {
alignChildren.Add(new _RailDestination(
minWidth: minWidth,
minExtendedWidth: minExtendedWidth,
extendedTransitionAnimation: _extendedAnimation,
selected: widget.selectedIndex == i,
icon: widget.selectedIndex == i ? widget.destinations[i].selectedIcon : widget.destinations[i].icon,
label: widget.destinations[i].label,
destinationAnimation: _destinationAnimations[i],
labelType: labelType,
iconTheme: widget.selectedIndex == i ? selectedIconTheme : unselectedIconTheme,
labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle,
onTap: () => { widget.onDestinationSelected(i); },
indexLabel: localizations.tabLabel(
tabIndex: i + 1,
tabCount: widget.destinations.Count
)
));
}
if (widget.trailing != null) {
alignChildren.Add(new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: Mathf.Lerp(minWidth, minExtendedWidth, _extendedAnimation.value)
),
child: widget.trailing
));
}
materialChildren.Add(new Expanded(
child: new Align(
alignment: new Alignment(0, groupAlignment),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: alignChildren
)
)
));
return new _ExtendedNavigationRailAnimation(
animation: _extendedAnimation,
child: new Material(
elevation: elevation,
color: backgroundColor,
child: new Column(
children: materialChildren
)
)
);
}
void _disposeControllers() {
foreach (AnimationController controller in _destinationControllers) {
controller.dispose();
}
_extendedController.dispose();
}
void _initControllers() {
_destinationControllers = widget.destinations.Select((destination, i) => {
var result = new AnimationController(
duration: ThemeUtils.kThemeAnimationDuration,
vsync: this
);
result.addListener(_rebuild);
return result;
}).ToList();
_destinationAnimations = _destinationControllers.Select((AnimationController controller) => controller.view)
.ToList();
_destinationControllers[widget.selectedIndex ?? 0].setValue(1.0f);
_extendedController = new AnimationController(
duration: ThemeUtils.kThemeAnimationDuration,
vsync: this,
value: widget.extended ?? false ? 1.0f : 0.0f
);
_extendedAnimation = new CurvedAnimation(
parent: _extendedController,
curve: Curves.easeInOut
);
_extendedController.addListener(() => { _rebuild(); });
}
void _resetState() {
_disposeControllers();
_initControllers();
}
void _rebuild() {
setState(() => {
// Rebuilding when any of the controllers tick, i.e. when the items are
// animating.
});
}
}
internal class _RailDestination : StatelessWidget {
internal _RailDestination(
float? minWidth = null,
float? minExtendedWidth = null,
Widget icon = null,
Widget label = null,
Animation<float> destinationAnimation = null,
Animation<float> extendedTransitionAnimation = null,
NavigationRailLabelType? labelType = null,
bool? selected = null,
IconThemeData iconTheme = null,
TextStyle labelTextStyle = null,
VoidCallback onTap = null,
string indexLabel = null
) {
D.assert(minWidth != null);
D.assert(minExtendedWidth != null);
D.assert(icon != null);
D.assert(label != null);
D.assert(destinationAnimation != null);
D.assert(extendedTransitionAnimation != null);
D.assert(labelType != null);
D.assert(selected != null);
D.assert(iconTheme != null);
D.assert(labelTextStyle != null);
D.assert(onTap != null);
D.assert(indexLabel != null);
this.minWidth = minWidth;
this.minExtendedWidth = minExtendedWidth;
this.icon = icon;
this.label = label;
this.destinationAnimation = destinationAnimation;
this.extendedTransitionAnimation = extendedTransitionAnimation;
this.labelType = labelType;
this.selected = selected;
this.iconTheme = iconTheme;
this.labelTextStyle = labelTextStyle;
this.onTap = onTap;
this.indexLabel = indexLabel;
_positionAnimation = new CurvedAnimation(
parent: new ReverseAnimation(destinationAnimation),
curve: Curves.easeInOut,
reverseCurve: Curves.easeInOut.flipped
);
}
public readonly float? minWidth;
public readonly float? minExtendedWidth;
public readonly Widget icon;
public readonly Widget label;
public readonly Animation<float> destinationAnimation;
public readonly NavigationRailLabelType? labelType;
public readonly bool? selected;
public readonly Animation<float> extendedTransitionAnimation;
public readonly IconThemeData iconTheme;
public readonly TextStyle labelTextStyle;
public readonly VoidCallback onTap;
public readonly string indexLabel;
public readonly Animation<float> _positionAnimation;
public override Widget build(BuildContext context) {
Widget themedIcon = new IconTheme(
data: iconTheme,
child: icon
);
Widget styledLabel = new DefaultTextStyle(
style: labelTextStyle,
child: label
);
Widget content = null;
switch (labelType) {
case NavigationRailLabelType.none:
Widget iconPart = new SizedBox(
width: minWidth,
height: minWidth,
child: new Align(
alignment: Alignment.center,
child: themedIcon
)
);
if (extendedTransitionAnimation.value == 0) {
content = new Stack(
children: new List<Widget>() {
iconPart,
new SizedBox(
width: 0,
height: 0,
child: new Opacity(
opacity: 0.0f,
child: label
)
)
}
)
;
}
else {
content = new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: Mathf.Lerp(minWidth ?? 0, minExtendedWidth ?? 0,
extendedTransitionAnimation.value)
),
child: new ClipRect(
child: new Row(
children: new List<Widget> {
iconPart,
new Align(
heightFactor: 1.0f,
widthFactor: extendedTransitionAnimation.value,
alignment: AlignmentDirectional.centerStart,
child: new Opacity(
opacity: _extendedLabelFadeValue(),
child: styledLabel
)
),
new SizedBox(width: material_._horizontalDestinationPadding),
}
)
)
);
}
break;
case NavigationRailLabelType.selected:
float appearingAnimationValue = 1 - _positionAnimation.value;
float verticalPadding = Mathf.Lerp(material_._verticalDestinationPaddingNoLabel,
material_._verticalDestinationPaddingWithLabel, appearingAnimationValue);
content = new Container(
constraints: new BoxConstraints(
minWidth: minWidth ?? 0,
minHeight: minWidth ?? 0
),
padding: EdgeInsets.symmetric(horizontal: material_._horizontalDestinationPadding),
child:
new ClipRect(
child: new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget>() {
new SizedBox(height: verticalPadding),
themedIcon,
new Align(
alignment: Alignment.topCenter,
heightFactor: appearingAnimationValue,
widthFactor: 1.0f,
child: new Opacity(
opacity: selected ?? false
? _normalLabelFadeInValue()
: _normalLabelFadeOutValue(),
child: styledLabel
)
),
new SizedBox(height: verticalPadding)
}
)
)
);
break;
case NavigationRailLabelType.all:
content = new Container(
constraints: new BoxConstraints(
minWidth: minWidth ?? 0,
minHeight: minWidth ?? 0
),
padding: EdgeInsets.symmetric(horizontal: material_._horizontalDestinationPadding),
child:
new Column(
children: new List<Widget>() {
new SizedBox(height: material_._verticalDestinationPaddingWithLabel),
themedIcon,
styledLabel,
new SizedBox(height: material_._verticalDestinationPaddingWithLabel),
}
));
break;
}
ColorScheme colors = Theme.of(context).colorScheme;
return new Material(
type: MaterialType.transparency,
clipBehavior: Clip.none,
child: new InkResponse(
onTap: () => onTap(),
onHover: (_) => { },
highlightShape:
BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular((minWidth ?? 0) / 2.0f)),
containedInkWell:
true,
splashColor: colors.primary.withOpacity(0.12f),
hoverColor: colors.primary.withOpacity(0.04f),
child: content
)
);
}
float _normalLabelFadeInValue() {
if (destinationAnimation.value < 0.25f) {
return 0;
}
else if (destinationAnimation.value < 0.75f) {
return (destinationAnimation.value - 0.25f) * 2;
}
else {
return 1;
}
}
float _normalLabelFadeOutValue() {
if (destinationAnimation.value > 0.75f) {
return (destinationAnimation.value - 0.75f) * 4.0f;
}
else {
return 0;
}
}
float _extendedLabelFadeValue() {
return extendedTransitionAnimation.value < 0.25f ? extendedTransitionAnimation.value * 4.0f : 1.0f;
}
}
public enum NavigationRailLabelType {
none,
selected,
all,
}
class NavigationRailDestination {
public NavigationRailDestination(
Widget icon,
Widget selectedIcon = null,
Widget label = null
) {
D.assert(icon != null);
selectedIcon = selectedIcon ?? icon;
this.icon = icon;
this.selectedIcon = selectedIcon;
this.label = label;
}
public readonly Widget icon;
public readonly Widget selectedIcon;
public readonly Widget label;
}
class _ExtendedNavigationRailAnimation : InheritedWidget {
public _ExtendedNavigationRailAnimation(
Key key = null,
Animation<float> animation = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(child != null);
this.animation = animation;
}
public readonly Animation<float> animation;
public override bool updateShouldNotify(InheritedWidget oldWidget) =>
oldWidget is _ExtendedNavigationRailAnimation extendedNavigationRailAnimation
&& animation != extendedNavigationRailAnimation.animation;
}
public partial class material_ {
public static readonly float _minRailWidth = 72.0f;
public static readonly float _minExtendedRailWidth = 256.0f;
public static readonly float _horizontalDestinationPadding = 8.0f;
public static readonly float _verticalDestinationPaddingNoLabel = 24.0f;
public static readonly float _verticalDestinationPaddingWithLabel = 16.0f;
public static readonly Widget _verticalSpacer = new SizedBox(height: 8.0f);
}
}

3
com.unity.uiwidgets/Runtime/material/navigation_rail.cs.meta


fileFormatVersion: 2
guid: 44154d21b3bb4de8a16fdb712a524a0f
timeCreated: 1611214615

189
com.unity.uiwidgets/Runtime/material/navigation_rail_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public class NavigationRailThemeData : Diagnosticable, IEquatable<NavigationRailThemeData> {
public NavigationRailThemeData(
Color backgroundColor = null,
float? elevation = null,
TextStyle unselectedLabelTextStyle = null,
TextStyle selectedLabelTextStyle = null,
IconThemeData unselectedIconTheme = null,
IconThemeData selectedIconTheme = null,
float? groupAlignment = null,
NavigationRailLabelType? labelType = null
) {
this.backgroundColor = backgroundColor;
this.elevation = elevation;
this.unselectedLabelTextStyle = unselectedLabelTextStyle;
this.selectedLabelTextStyle = selectedLabelTextStyle;
this.unselectedIconTheme = unselectedIconTheme;
this.selectedIconTheme = selectedIconTheme;
this.groupAlignment = groupAlignment;
this.labelType = labelType;
}
public readonly Color backgroundColor;
public readonly float? elevation;
public readonly TextStyle unselectedLabelTextStyle;
public readonly TextStyle selectedLabelTextStyle;
public readonly IconThemeData unselectedIconTheme;
public readonly IconThemeData selectedIconTheme;
public readonly float? groupAlignment;
public readonly NavigationRailLabelType? labelType;
NavigationRailThemeData copyWith(
Color backgroundColor,
float? elevation,
TextStyle unselectedLabelTextStyle,
TextStyle selectedLabelTextStyle,
IconThemeData unselectedIconTheme,
IconThemeData selectedIconTheme,
float? groupAlignment,
NavigationRailLabelType? labelType
) {
return new NavigationRailThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
elevation: elevation ?? this.elevation,
unselectedLabelTextStyle: unselectedLabelTextStyle ?? this.unselectedLabelTextStyle,
selectedLabelTextStyle: selectedLabelTextStyle ?? this.selectedLabelTextStyle,
unselectedIconTheme: unselectedIconTheme ?? this.unselectedIconTheme,
selectedIconTheme: selectedIconTheme ?? this.selectedIconTheme,
groupAlignment: groupAlignment ?? this.groupAlignment,
labelType: labelType ?? this.labelType
);
}
static NavigationRailThemeData lerp(NavigationRailThemeData a, NavigationRailThemeData b, float t) {
if (a == null && b == null)
return null;
return new NavigationRailThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
elevation: Mathf.Lerp(a?.elevation ?? 0, b?.elevation ?? 0, t),
unselectedLabelTextStyle: TextStyle.lerp(a?.unselectedLabelTextStyle, b?.unselectedLabelTextStyle, t),
selectedLabelTextStyle: TextStyle.lerp(a?.selectedLabelTextStyle, b?.selectedLabelTextStyle, t),
unselectedIconTheme: IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t),
selectedIconTheme: IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t),
groupAlignment: Mathf.Lerp(a?.groupAlignment ?? 0, b?.groupAlignment ?? 0, t),
labelType: t < 0.5 ? a?.labelType : b?.labelType
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
NavigationRailThemeData defaultData = new NavigationRailThemeData();
properties.add(new ColorProperty("backgroundColor", backgroundColor,
defaultValue: defaultData.backgroundColor));
properties.add(new FloatProperty("elevation", elevation, defaultValue: defaultData.elevation));
properties.add(new DiagnosticsProperty<TextStyle>("unselectedLabelTextStyle", unselectedLabelTextStyle,
defaultValue: defaultData.unselectedLabelTextStyle));
properties.add(new DiagnosticsProperty<TextStyle>("selectedLabelTextStyle", selectedLabelTextStyle,
defaultValue: defaultData.selectedLabelTextStyle));
properties.add(new DiagnosticsProperty<IconThemeData>("unselectedIconTheme", unselectedIconTheme,
defaultValue: defaultData.unselectedIconTheme));
properties.add(new DiagnosticsProperty<IconThemeData>("selectedIconTheme", selectedIconTheme,
defaultValue: defaultData.selectedIconTheme));
properties.add(
new FloatProperty("groupAlignment", groupAlignment, defaultValue: defaultData.groupAlignment));
properties.add(new DiagnosticsProperty<NavigationRailLabelType?>("labelType", labelType,
defaultValue: defaultData.labelType));
}
public static bool operator ==(NavigationRailThemeData self, NavigationRailThemeData other) {
return Equals(self, other);
}
public static bool operator !=(NavigationRailThemeData self, NavigationRailThemeData other) {
return Equals(self, other);
}
public bool Equals(NavigationRailThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(backgroundColor, other.backgroundColor) && Nullable.Equals(elevation, other.elevation) &&
Equals(unselectedLabelTextStyle, other.unselectedLabelTextStyle) &&
Equals(selectedLabelTextStyle, other.selectedLabelTextStyle) &&
Equals(unselectedIconTheme, other.unselectedIconTheme) &&
Equals(selectedIconTheme, other.selectedIconTheme) &&
Nullable.Equals(groupAlignment, other.groupAlignment) && labelType == other.labelType;
}
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((NavigationRailThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (backgroundColor != null ? backgroundColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ elevation.GetHashCode();
hashCode = (hashCode * 397) ^
(unselectedLabelTextStyle != null ? unselectedLabelTextStyle.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(selectedLabelTextStyle != null ? selectedLabelTextStyle.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (unselectedIconTheme != null ? unselectedIconTheme.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (selectedIconTheme != null ? selectedIconTheme.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ groupAlignment.GetHashCode();
hashCode = (hashCode * 397) ^ labelType.GetHashCode();
return hashCode;
}
}
}
public class NavigationRailTheme : InheritedTheme {
public NavigationRailTheme(
Key key = null,
NavigationRailThemeData data = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(data != null);
this.data = data;
}
public readonly NavigationRailThemeData data;
public static NavigationRailThemeData of(BuildContext context) {
NavigationRailTheme navigationRailTheme =
context.dependOnInheritedWidgetOfExactType<NavigationRailTheme>();
return navigationRailTheme?.data ?? Theme.of(context).navigationRailTheme;
}
public override Widget wrap(BuildContext context, Widget child) {
NavigationRailTheme ancestorTheme = context.findAncestorWidgetOfExactType<NavigationRailTheme>();
return ReferenceEquals(this, ancestorTheme) ? child : new NavigationRailTheme(data: data, child: child);
}
public override bool updateShouldNotify(InheritedWidget oldWidget) =>
oldWidget is NavigationRailTheme navigationRail && data != navigationRail.data;
}
}

3
com.unity.uiwidgets/Runtime/material/navigation_rail_theme.cs.meta


fileFormatVersion: 2
guid: ea446a1e5a704c9faf0c50c5d1f9d5a8
timeCreated: 1611214357

136
com.unity.uiwidgets/Runtime/material/popup_menu_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
public class PopupMenuThemeData : Diagnosticable, IEquatable<PopupMenuThemeData> {
public PopupMenuThemeData(
Color color = null,
ShapeBorder shape = null,
float? elevation = null,
TextStyle textStyle = null
) {
this.color = color;
this.shape = shape;
this.elevation = elevation;
this.textStyle = textStyle;
}
public readonly Color color;
public readonly ShapeBorder shape;
public readonly float? elevation;
public readonly TextStyle textStyle;
PopupMenuThemeData copyWith(
Color color = null,
ShapeBorder shape = null,
float? elevation = null,
TextStyle textStyle = null
) {
return new PopupMenuThemeData(
color: color ?? this.color,
shape: shape ?? this.shape,
elevation: elevation ?? this.elevation,
textStyle: textStyle ?? this.textStyle
);
}
public static PopupMenuThemeData lerp(PopupMenuThemeData a, PopupMenuThemeData b, float t) {
if (a == null && b == null)
return null;
return new PopupMenuThemeData(
color: Color.lerp(a?.color, b?.color, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, t),
elevation: Mathf.Lerp(a?.elevation ?? 0, b?.elevation ?? 0, t),
textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t)
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ColorProperty("color", color, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", shape, defaultValue: null));
properties.add(new FloatProperty("elevation", elevation, defaultValue: null));
properties.add(new DiagnosticsProperty<TextStyle>("text style", textStyle, defaultValue: null));
}
public static bool operator ==(PopupMenuThemeData self, PopupMenuThemeData other) {
return Equals(self, other);
}
public static bool operator !=(PopupMenuThemeData self, PopupMenuThemeData other) {
return Equals(self, other);
}
public bool Equals(PopupMenuThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(color, other.color) && Equals(shape, other.shape) &&
Nullable.Equals(elevation, other.elevation) && Equals(textStyle, other.textStyle);
}
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((PopupMenuThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (color != null ? color.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (shape != null ? shape.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ elevation.GetHashCode();
hashCode = (hashCode * 397) ^ (textStyle != null ? textStyle.GetHashCode() : 0);
return hashCode;
}
}
}
public class PopupMenuTheme : InheritedTheme {
public PopupMenuTheme(
Key key = null,
PopupMenuThemeData data = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(data != null);
}
public readonly PopupMenuThemeData data;
static PopupMenuThemeData of(BuildContext context) {
PopupMenuTheme popupMenuTheme = context.dependOnInheritedWidgetOfExactType<PopupMenuTheme>();
return popupMenuTheme?.data ?? Theme.of(context).popupMenuTheme;
}
public override Widget wrap(BuildContext context, Widget child) {
PopupMenuTheme ancestorTheme = context.findAncestorWidgetOfExactType<PopupMenuTheme>();
return ReferenceEquals(this, ancestorTheme) ? child : new PopupMenuTheme(data: data, child: child);
}
public override bool updateShouldNotify(InheritedWidget oldWidget) =>
oldWidget is PopupMenuTheme popupMenuTheme && data != popupMenuTheme.data;
}
}

148
com.unity.uiwidgets/Runtime/material/snack_bar_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Object = UnityEngine.Object;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public enum SnackBarBehavior {
fix,
floating,
}
public class SnackBarThemeData : Diagnosticable, IEquatable<SnackBarThemeData> {
public SnackBarThemeData(
Color backgroundColor,
Color actionTextColor,
Color disabledActionTextColor,
TextStyle contentTextStyle,
float? elevation,
ShapeBorder shape,
SnackBarBehavior behavior
) {
D.assert(elevation == null || elevation >= 0.0f);
this.backgroundColor = backgroundColor;
this.actionTextColor = actionTextColor;
this.disabledActionTextColor = disabledActionTextColor;
this.contentTextStyle = contentTextStyle;
this.elevation = elevation;
this.shape = shape;
this.behavior = behavior;
}
public readonly Color backgroundColor;
public readonly Color actionTextColor;
public readonly Color disabledActionTextColor;
public readonly TextStyle contentTextStyle;
public readonly float? elevation;
public readonly ShapeBorder shape;
public readonly SnackBarBehavior behavior;
public SnackBarThemeData copyWith(
Color backgroundColor,
Color actionTextColor,
Color disabledActionTextColor,
TextStyle contentTextStyle,
float? elevation,
ShapeBorder shape,
SnackBarBehavior? behavior
) {
return new SnackBarThemeData(
backgroundColor: backgroundColor ?? this.backgroundColor,
actionTextColor: actionTextColor ?? this.actionTextColor,
disabledActionTextColor: disabledActionTextColor ?? this.disabledActionTextColor,
contentTextStyle: contentTextStyle ?? this.contentTextStyle,
elevation: elevation ?? this.elevation,
shape: shape ?? this.shape,
behavior: behavior ?? this.behavior
);
}
static SnackBarThemeData lerp(SnackBarThemeData a, SnackBarThemeData b, float t) {
return new SnackBarThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
actionTextColor: Color.lerp(a?.actionTextColor, b?.actionTextColor, t),
disabledActionTextColor: Color.lerp(a?.disabledActionTextColor, b?.disabledActionTextColor, t),
contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t),
elevation: Mathf.Lerp(a?.elevation ?? 0, b?.elevation ?? 0, t),
shape: ShapeBorder.lerp(a?.shape, b?.shape, t),
behavior: t < 0.5 ? a.behavior : b.behavior
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new ColorProperty("backgroundColor", backgroundColor, defaultValue: null));
properties.add(new ColorProperty("actionTextColor", actionTextColor, defaultValue: null));
properties.add(new ColorProperty("disabledActionTextColor", disabledActionTextColor, defaultValue: null));
properties.add(
new DiagnosticsProperty<TextStyle>("contentTextStyle", contentTextStyle, defaultValue: null));
properties.add(new FloatProperty("elevation", elevation, defaultValue: null));
properties.add(new DiagnosticsProperty<ShapeBorder>("shape", shape, defaultValue: null));
properties.add(new DiagnosticsProperty<SnackBarBehavior>("behavior", behavior, defaultValue: null));
}
public static bool operator ==(SnackBarThemeData self, SnackBarThemeData other) {
return Equals(self, other);
}
public static bool operator !=(SnackBarThemeData self, SnackBarThemeData other) {
return Equals(self, other);
}
public bool Equals(SnackBarThemeData other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(backgroundColor, other.backgroundColor) && Equals(actionTextColor, other.actionTextColor) &&
Equals(disabledActionTextColor, other.disabledActionTextColor) &&
Equals(contentTextStyle, other.contentTextStyle) && Nullable.Equals(elevation, other.elevation) &&
Equals(shape, other.shape) && behavior == other.behavior;
}
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((SnackBarThemeData) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (backgroundColor != null ? backgroundColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (actionTextColor != null ? actionTextColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(disabledActionTextColor != null ? disabledActionTextColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (contentTextStyle != null ? contentTextStyle.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ elevation.GetHashCode();
hashCode = (hashCode * 397) ^ (shape != null ? shape.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int) behavior;
return hashCode;
}
}
}
}

3
com.unity.uiwidgets/Runtime/material/snack_bar_theme.cs.meta


fileFormatVersion: 2
guid: e778095633af486ebf85e2dc802baf55
timeCreated: 1611212714
正在加载...
取消
保存