浏览代码

update

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
6a9c08b8
共有 4 个文件被更改,包括 343 次插入37 次删除
  1. 86
      com.unity.uiwidgets/Runtime/material/button_theme.cs
  2. 14
      com.unity.uiwidgets/Runtime/material/material_button.cs
  3. 178
      com.unity.uiwidgets/Runtime/material/theme_data.cs
  4. 102
      com.unity.uiwidgets/Runtime/material/material_state.cs

86
com.unity.uiwidgets/Runtime/material/button_theme.cs


padded
}
public class ButtonTheme : InheritedWidget {
public class ButtonTheme : InheritedTheme {
public ButtonTheme(
Key key = null,
ButtonTextTheme textTheme = ButtonTextTheme.normal,

bool alignedDropdown = false,
Color buttonColor = null,
Color disabledColor = null,
Color focusColor = null,
Color hoverColor = null,
Color highlightColor = null,
Color splashColor = null,
ColorScheme colorScheme = null,

layoutBehavior: layoutBehavior,
buttonColor: buttonColor,
disabledColor: disabledColor,
focusColor: focusColor,
hoverColor: hoverColor,
highlightColor: highlightColor,
splashColor: splashColor,
colorScheme: colorScheme,

bool alignedDropdown = false,
Color buttonColor = null,
Color disabledColor = null,
Color focusColor = null,
Color hoverColor = null,
Color highlightColor = null,
Color splashColor = null,
ColorScheme colorScheme = null,

layoutBehavior: layoutBehavior,
buttonColor: buttonColor,
disabledColor: disabledColor,
focusColor: focusColor,
hoverColor: hoverColor,
highlightColor: highlightColor,
splashColor: splashColor,
colorScheme: colorScheme

public readonly ButtonThemeData data;
public static ButtonThemeData of(BuildContext context) {
ButtonTheme inheritedButtonTheme = (ButtonTheme) context.inheritFromWidgetOfExactType(typeof(ButtonTheme));
ButtonTheme inheritedButtonTheme = (ButtonTheme) context.dependOnInheritedWidgetOfExactType<ButtonTheme>();
ButtonThemeData buttonTheme = inheritedButtonTheme?.data;
if (buttonTheme?.colorScheme == null) {
ThemeData theme = Theme.of(context);

return buttonTheme;
}
public override Widget wrap(BuildContext context, Widget child) {
ButtonTheme ancestorTheme = context.findAncestorWidgetOfExactType<ButtonTheme>();
return ReferenceEquals(this, ancestorTheme)
? child
: ButtonTheme.fromButtonThemeData(data: data, child: child);
}
public override bool updateShouldNotify(InheritedWidget oldWidget) {
return data != ((ButtonTheme) oldWidget).data;
}

bool alignedDropdown = false,
Color buttonColor = null,
Color disabledColor = null,
Color focusColor = null,
Color hoverColor = null,
Color highlightColor = null,
Color splashColor = null,
ColorScheme colorScheme = null,

this.colorScheme = colorScheme;
_buttonColor = buttonColor;
_disabledColor = disabledColor;
_focusColor = focusColor;
_hoverColor = hoverColor;
_highlightColor = highlightColor;
_splashColor = splashColor;
_padding = padding;

readonly Color _disabledColor;
readonly Color _focusColor;
readonly Color _hoverColor;
readonly Color _highlightColor;
readonly Color _splashColor;

return button.textTheme ?? textTheme;
}
Color _getDisabledColor(MaterialButton button) {
return getBrightness(button) == Brightness.dark
? colorScheme.onSurface.withOpacity(0.30f)
: colorScheme.onSurface.withOpacity(0.38f);
}
if (button.textColor is MaterialStateProperty<Color>)
return button.textColor;
return _getDisabledColor(button);
return colorScheme.onSurface.withOpacity(0.38f);
}

return _disabledColor;
}
return _getDisabledColor(button);
return colorScheme.onSurface.withOpacity(0.38f);
}

return getTextColor(button).withOpacity(0.12f);
}
public Color getFocusColor(MaterialButton button) {
return button.focusColor ?? _focusColor ?? getTextColor(button).withOpacity(0.12f);
}
public Color getHoverColor(MaterialButton button) {
return button.hoverColor ?? _hoverColor ?? getTextColor(button).withOpacity(0.04f);
}
public Color getHighlightColor(MaterialButton button) {
if (button.highlightColor != null) {
return button.highlightColor;

return 2.0f;
}
public float getFocusElevation(MaterialButton button) {
if (button.focusElevation != null)
return button.focusElevation.Value;
if (button is FlatButton)
return 0.0f;
if (button is OutlineButton)
return 0.0f;
return 4.0f;
}
public float getHoverElevation(MaterialButton button) {
if (button.hoverElevation != null)
return button.hoverElevation.Value;
if (button is FlatButton)
return 0.0f;
if (button is OutlineButton)
return 0.0f;
return 4.0f;
}
public float getHighlightElevation(MaterialButton button) {
if (button.highlightElevation != null) {

if (button is OutlineButton) {
return 0.0f;
}
return 8.0f;
}

bool? alignedDropdown = null,
Color buttonColor = null,
Color disabledColor = null,
Color focusColor = null,
Color hoverColor = null,
Color highlightColor = null,
Color splashColor = null,
ColorScheme colorScheme = null,

alignedDropdown: alignedDropdown ?? this.alignedDropdown,
buttonColor: buttonColor ?? _buttonColor,
disabledColor: disabledColor ?? _disabledColor,
focusColor: focusColor ?? _focusColor,
hoverColor: hoverColor ?? _hoverColor,
highlightColor: highlightColor ?? _highlightColor,
splashColor: splashColor ?? _splashColor,
colorScheme: colorScheme ?? this.colorScheme,

&& alignedDropdown == other.alignedDropdown
&& _buttonColor == other._buttonColor
&& _disabledColor == other._disabledColor
&& _focusColor == other._focusColor
&& _hoverColor == other._hoverColor
&& _highlightColor == other._highlightColor
&& _splashColor == other._splashColor
&& colorScheme == other.colorScheme

hashCode = (hashCode * 397) ^ alignedDropdown.GetHashCode();
hashCode = (hashCode * 397) ^ (_buttonColor != null ? _buttonColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_disabledColor != null ? _disabledColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_focusColor != null ? _focusColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_hoverColor != null ? _hoverColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_highlightColor != null ? _highlightColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_splashColor != null ? _splashColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ colorScheme.GetHashCode();

defaultValue: defaultTheme.alignedDropdown,
ifTrue: "dropdown width matches button"
));
properties.add(new DiagnosticsProperty<Color>("buttonColor", _buttonColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("disabledColor", _disabledColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("highlightColor", _highlightColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("splashColor", _splashColor, defaultValue: null));
properties.add(new ColorProperty("buttonColor", _buttonColor, 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<ColorScheme>("colorScheme", colorScheme,
defaultValue: defaultTheme.colorScheme));
properties.add(new DiagnosticsProperty<MaterialTapTargetSize?>("materialTapTargetSize",

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


}
public readonly VoidCallback onPressed;
public readonly VoidCallback onLongPress;
public readonly ValueChanged<bool> onHighlightChanged;

public readonly Color splashColor;
public readonly Color focusColor;
public readonly Color hoverColor;
public readonly float? hoverElevation;
public readonly float? focusElevation;
public readonly float? highlightElevation;
public readonly float? disabledElevation;

public readonly Widget child;
public bool enabled {
get { return onPressed != null; }
get { return onPressed != null || onLongPress != null; }
public readonly VisualDensity visualDensity;
public readonly ShapeBorder shape;

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


using System.Linq;
using uiwidgets;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;

dividerColor = dividerColor ?? (isDark ? new Color(0x1FFFFFFF) : new Color(0x1F000000));
colorScheme = colorScheme ?? ColorScheme.fromSwatch(
primarySwatch: primarySwatch,
primaryColorDark: primaryColorDark,
accentColor: accentColor,
cardColor: cardColor,
backgroundColor: backgroundColor,
errorColor: errorColor,
brightness: brightness);
primarySwatch: primarySwatch,
primaryColorDark: primaryColorDark,
accentColor: accentColor,
cardColor: cardColor,
backgroundColor: backgroundColor,
errorColor: errorColor,
brightness: brightness);
splashFactory = splashFactory ?? InkSplash.splashFactory;
selectedRowColor = selectedRowColor ?? Colors.grey[100];

buttonColor = buttonColor ?? (isDark ? primarySwatch[600] : Colors.grey[300]);
buttonTheme = buttonTheme ?? new ButtonThemeData(
colorScheme: colorScheme,
buttonColor: buttonColor,
disabledColor: disabledColor,
highlightColor: highlightColor,
splashColor: splashColor,
materialTapTargetSize: materialTapTargetSize);
colorScheme: colorScheme,
buttonColor: buttonColor,
disabledColor: disabledColor,
highlightColor: highlightColor,
splashColor: splashColor,
materialTapTargetSize: materialTapTargetSize);
disabledColor = disabledColor ?? (isDark ? Colors.white30 : Colors.black38);
highlightColor = highlightColor ??
(isDark

: material_._kLightThemeSplashColor);
sliderTheme = sliderTheme ?? SliderThemeData.fromPrimaryColors(
primaryColor: primaryColor,
primaryColorLight: primaryColorLight,
primaryColorDark: primaryColorDark,
valueIndicatorTextStyle: accentTextTheme.body2);
primaryColor: primaryColor,
primaryColorLight: primaryColorLight,
primaryColorDark: primaryColorDark,
valueIndicatorTextStyle: accentTextTheme.body2);
tabBarTheme = tabBarTheme ?? new TabBarTheme();
cardTheme = cardTheme ?? new CardTheme();

public readonly ButtonThemeData buttonTheme;
public readonly ToggleButtonsThemeData toggleButtonsTheme;
public readonly Color buttonColor;
public readonly Color secondaryHeaderColor;

public readonly MaterialTapTargetSize materialTapTargetSize;
public readonly bool applyElevationOverlayColor;
public readonly FloatingActionButtonThemeData floatingActionButtonTheme;
public readonly Typography typography;

bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t),
colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),
dialogTheme: DialogTheme.lerp(a.dialogTheme, b.dialogTheme, t),
floatingActionButtonTheme: FloatingActionButtonThemeData.lerp(a.floatingActionButtonTheme, b.floatingActionButtonTheme, t),
floatingActionButtonTheme: FloatingActionButtonThemeData.lerp(a.floatingActionButtonTheme,
b.floatingActionButtonTheme, t),
typography: Typography.lerp(a.typography, b.typography, t)
);
}

_cache[key] = value();
return _cache[key];
}
}
public class VisualDensity : Diagnosticable, IEquatable<VisualDensity> {
public VisualDensity(
float horizontal = 0.0f,
float vertical = 0.0f
) {
D.assert(horizontal != null);
D.assert(vertical != null);
D.assert(vertical <= maximumDensity);
D.assert(vertical >= minimumDensity);
D.assert(horizontal <= maximumDensity);
D.assert(horizontal >= minimumDensity);
this.horizontal = horizontal;
this.vertical = vertical;
}
public static readonly float minimumDensity = -4.0f;
public static readonly float maximumDensity = 4.0f;
public static readonly VisualDensity standard = new VisualDensity();
public static readonly VisualDensity comfortable = new VisualDensity(horizontal: -1.0f, vertical: -1.0f);
public static readonly VisualDensity compact = new VisualDensity(horizontal: -2.0f, vertical: -2.0f);
public static VisualDensity adaptivePlatformDensity {
get {
// switch (defaultTargetPlatform) {
// case TargetPlatform.android:
// case TargetPlatform.iOS:
// case TargetPlatform.fuchsia:
// break;
// case TargetPlatform.linux:
// case TargetPlatform.macOS:
// case TargetPlatform.windows:
// return compact;
// }
return new VisualDensity();
}
}
public VisualDensity copyWith(
float? horizontal,
float? vertical
) {
return new VisualDensity(
horizontal: horizontal ?? this.horizontal,
vertical: vertical ?? this.vertical
);
}
public readonly float horizontal;
public readonly float vertical;
Offset baseSizeAdjustment {
get {
float interval = 4.0f;
return new Offset(horizontal, vertical) * interval;
}
}
static VisualDensity lerp(VisualDensity a, VisualDensity b, float t) {
return new VisualDensity(
horizontal: Mathf.Lerp(a.horizontal, b.horizontal, t),
vertical: Mathf.Lerp(a.horizontal, b.horizontal, t)
);
}
BoxConstraints effectiveConstraints(BoxConstraints constraints) {
D.assert(constraints != null && constraints.debugAssertIsValid());
return constraints.copyWith(
minWidth: (constraints.minWidth + baseSizeAdjustment.dx).clamp(0.0f, float.PositiveInfinity),
minHeight: (constraints.minHeight + baseSizeAdjustment.dy).clamp(0.0f, float.PositiveInfinity)
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FloatProperty("horizontal", horizontal, defaultValue: 0.0f));
properties.add(new FloatProperty("vertical", vertical, defaultValue: 0.0f));
}
public override string ToString() {
return $"{base.toStringShort()}(h: {D.debugFormatFloat(horizontal)}, v: {D.debugFormatFloat(vertical)})";
}
public static bool operator ==(VisualDensity self, object other) {
return Equals(self, other);
}
public static bool operator !=(VisualDensity self, object other) {
return Equals(self, other);
}
public bool Equals(VisualDensity other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return horizontal.Equals(other.horizontal) && vertical.Equals(other.vertical);
}
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((VisualDensity) obj);
}
public override int GetHashCode() {
unchecked {
return (horizontal.GetHashCode() * 397) ^ vertical.GetHashCode();
}
}
}
}

102
com.unity.uiwidgets/Runtime/material/material_state.cs


using System.Collections.Generic;
using Unity.UIWidgets.material;
using Unity.UIWidgets.ui;
using UnityEditor.VersionControl;
namespace Unity.UIWidgets.material {
public enum MaterialState {
hovered,
focused,
pressed,
dragged,
selected,
disabled,
error,
}
public partial class material_ {
public delegate T MaterialPropertyResolver<T>(HashSet<MaterialState> states);
}
abstract class MaterialStateColor : Color {
public MaterialStateColor(uint defaultValue) : base(defaultValue) {
}
static MaterialStateColor resolveWith(material_.MaterialPropertyResolver<Color> callback) =>
new material._MaterialStateColor(callback);
public abstract Color resolve(HashSet<MaterialState> states);
public static Color resolveAs<Color>(Color value, HashSet<MaterialState> states) {
if (value is MaterialStateProperty<Color> materialStateProperty) {
MaterialStateProperty<Color> property = materialStateProperty;
return property.resolve(states);
}
return value;
}
public static MaterialStateProperty<Color> resolveWith<Color>(
material_.MaterialPropertyResolver<Color> callback) => new _MaterialStateProperty<Color>(callback);
}
class _MaterialStateColor : MaterialStateColor {
internal _MaterialStateColor(material_.MaterialPropertyResolver<Color> _resolve) : base(_resolve(_defaultStates)
.value) {
this._resolve = _resolve;
}
readonly material_.MaterialPropertyResolver<Color> _resolve;
public static readonly HashSet<MaterialState> _defaultStates = new HashSet<MaterialState>();
public override Color resolve(HashSet<MaterialState> states) => _resolve(states);
}
abstract class MaterialStateProperty<T> {
public abstract T resolve(HashSet<MaterialState> states);
public static T resolveAs<T>(T value, HashSet<MaterialState> states) {
if (value is MaterialStateProperty<T> materialStateProperty) {
MaterialStateProperty<T> property = materialStateProperty;
return property.resolve(states);
}
return value;
}
public static MaterialStateProperty<T> resolveWith<T>(material_.MaterialPropertyResolver<T> callback) =>
new _MaterialStateProperty<T>(callback);
}
class _MaterialStateProperty<T> : MaterialStateProperty<T> {
internal _MaterialStateProperty(material_.MaterialPropertyResolver<T> _resolve) {
this._resolve = _resolve;
}
readonly material_.MaterialPropertyResolver<T> _resolve;
public override T resolve(HashSet<MaterialState> states) => _resolve(states);
public static T resolveAs<T>(T value, HashSet<MaterialState> states) {
if (value is MaterialStateProperty<T> materialStateProperty) {
MaterialStateProperty<T> property = materialStateProperty;
return property.resolve(states);
}
return value;
}
public static MaterialStateProperty<T> resolveWith<T>(material_.MaterialPropertyResolver<T> callback) =>
new _MaterialStateProperty<T>(callback);
}
}
正在加载...
取消
保存