浏览代码

Merge branch 'material' into 'master'

Material Scaffold

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!120
/main
Shenhua Gu 6 年前
当前提交
de6befa5
共有 39 个文件被更改,包括 3664 次插入86 次删除
  1. 42
      Runtime/material/app.cs
  2. 10
      Runtime/material/button_theme.cs
  3. 3
      Runtime/material/list_tile.cs
  4. 5
      Runtime/material/page_transitions_theme.cs
  5. 31
      Runtime/material/popup_menu.cs
  6. 6
      Runtime/material/theme.cs
  7. 107
      Runtime/material/theme_data.cs
  8. 125
      Runtime/rendering/layer.cs
  9. 157
      Runtime/rendering/proxy_box.cs
  10. 16
      Runtime/service/system_chrome.cs
  11. 20
      Runtime/ui/compositing.cs
  12. 126
      Runtime/widgets/app.cs
  13. 2
      Runtime/widgets/framework.cs
  14. 19
      Runtime/widgets/localizations.cs
  15. 36
      Runtime/widgets/transitions.cs
  16. 198
      Samples/UIWidgetSample/MaterialSample.cs
  17. 140
      Samples/UIWidgetSample/UIWidgetSample.unity
  18. 82
      Runtime/flow/physical_shape_layer.cs
  19. 11
      Runtime/flow/physical_shape_layer.cs.meta
  20. 301
      Runtime/material/app_bar.cs
  21. 11
      Runtime/material/app_bar.cs.meta
  22. 60
      Runtime/material/back_button.cs
  23. 11
      Runtime/material/back_button.cs.meta
  24. 127
      Runtime/material/bottom_sheet.cs
  25. 11
      Runtime/material/bottom_sheet.cs.meta
  26. 221
      Runtime/material/flexible_space_bar.cs
  27. 11
      Runtime/material/flexible_space_bar.cs.meta
  28. 282
      Runtime/material/float_action_button.cs
  29. 11
      Runtime/material/float_action_button.cs.meta
  30. 223
      Runtime/material/float_action_button_location.cs
  31. 11
      Runtime/material/float_action_button_location.cs.meta
  32. 1001
      Runtime/material/scaffold.cs
  33. 11
      Runtime/material/scaffold.cs.meta
  34. 220
      Runtime/material/snack_bar.cs
  35. 11
      Runtime/material/snack_bar.cs.meta
  36. 33
      Runtime/widgets/annotated_region.cs
  37. 11
      Runtime/widgets/annotated_region.cs.meta
  38. 36
      Runtime/widgets/perferred_size.cs
  39. 11
      Runtime/widgets/perferred_size.cs.meta

42
Runtime/material/app.cs


string title = "",
Color color = null,
ThemeData theme = null,
Locale locale = null,
List<LocalizationsDelegate<MaterialLocalizations>> localizationsDelegates = null,
LocaleListResolutionCallback localeListResolutionCallback = null,
LocaleResolutionCallback localeResolutionCallback = null,
List<Locale> supportedLocales = null,
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")};
this.navigatorKey = navigatorKey;
this.home = home;
this.routes = routes ?? new Dictionary<string, WidgetBuilder>();

this.title = title;
this.color = color;
this.theme = theme;
this.locale = locale;
this.localizationsDelegates = localizationsDelegates;
this.localeListResolutionCallback = localeListResolutionCallback;
this.localeResolutionCallback = localeResolutionCallback;
this.supportedLocales = supportedLocales;
this.showPerformanceOverlay = showPerformanceOverlay;
}

public readonly ThemeData theme;
public readonly Color color;
public readonly Locale locale;
public readonly List<LocalizationsDelegate<MaterialLocalizations>> localizationsDelegates;
public readonly LocaleListResolutionCallback localeListResolutionCallback;
public readonly LocaleResolutionCallback localeResolutionCallback;
public readonly List<Locale> supportedLocales;
public readonly bool showPerformanceOverlay;

return new MaterialRectArcTween(begin: begin, end: end);
}
List<LocalizationsDelegate> _localizationsDelegates {
get {
List<LocalizationsDelegate<MaterialLocalizations>> _delegates =
new List<LocalizationsDelegate<MaterialLocalizations>>();
if (this.widget.localizationsDelegates != null) {
_delegates.AddRange(this.widget.localizationsDelegates);
}
_delegates.Add(DefaultMaterialLocalizations.del);
return new List<LocalizationsDelegate>(_delegates);
}
}
public override Widget build(BuildContext context) {
ThemeData theme = this.widget.theme ?? ThemeData.fallback();
Widget result = new AnimatedTheme(

onGenerateRoute: this.widget.onGenerateRoute,
onUnknownRoute: this.widget.onUnknownRoute,
builder: this.widget.builder,
textStyle: AppUtils._errorTextStyle
textStyle: AppUtils._errorTextStyle,
locale: this.widget.locale,
localizationsDelegates: this._localizationsDelegates,
localeResolutionCallback: this.widget.localeResolutionCallback,
localeListResolutionCallback: this.widget.localeListResolutionCallback,
supportedLocales: this.widget.supportedLocales,
showPerformanceOverlay: this.widget.showPerformanceOverlay
)
);

10
Runtime/material/button_theme.cs


Key key = null,
ButtonThemeData data = null,
Widget child = null) {
return new ButtonTheme(key, data, child);
return new ButtonTheme(key, data, child);
}
public static ButtonTheme bar(

hashCode = (hashCode * 397) ^ this.padding.GetHashCode();
hashCode = (hashCode * 397) ^ this.shape.GetHashCode();
hashCode = (hashCode * 397) ^ this.alignedDropdown.GetHashCode();
hashCode = (hashCode * 397) ^ this._buttonColor.GetHashCode();
hashCode = (hashCode * 397) ^ this._disabledColor.GetHashCode();
hashCode = (hashCode * 397) ^ this._highlightColor.GetHashCode();
hashCode = (hashCode * 397) ^ this._splashColor.GetHashCode();
hashCode = (hashCode * 397) ^ (this._buttonColor != null ? this._buttonColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this._disabledColor != null ? this._disabledColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this._highlightColor != null ? this._highlightColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this._splashColor != null ? this._splashColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.colorScheme.GetHashCode();
hashCode = (hashCode * 397) ^ this._materialTapTargetSize.GetHashCode();
return hashCode;

3
Runtime/material/list_tile.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;

}
void _mountChild(Widget widget, _ListTileSlot slot) {
Element oldChild = this.slotToChild[slot];
Element oldChild = this.slotToChild.getOrDefault(slot);
Element newChild = this.updateChild(oldChild, widget, slot);
if (oldChild != null) {
this.slotToChild.Remove(slot);

5
Runtime/material/page_transitions_theme.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;

return matchingBuilder.buildTransitions(route, context, animation, secondaryAnimation, child);
}
List<PageTransitionsBuilder> _all(PageTransitionsBuilder builder) {
return new List<PageTransitionsBuilder> {this.builder};
PageTransitionsBuilder _all(PageTransitionsBuilder builder) {
return builder;
}
public bool Equals(PageTransitionsTheme other) {

31
Runtime/material/popup_menu.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public static partial class PopupMenuUtils {
internal static readonly TimeSpan _kMenuDuration = new TimeSpan(0, 0, 0, 0, 300);
internal const float _kBaselineOffsetFromBottom = 20.0f;

public class PopupMenuDivider : PopupMenuEntry<object> {
public PopupMenuDivider(Key key = null, float height = PopupMenuUtils._kMenuDividerHeight) : base(key: key) {
this._height = height;
}
readonly float _height;

protected override void handleTap() {
if (this.widget.isChecked) {
this._controller.reverse();
} else {
}
else {
base.handleTap();
}

child: item
);
}
children.Add(new FadeTransition(
opacity: new CurvedAnimation(
parent: this.route.animation,

float y;
if (this.selectedItemOffset == null) {
y = this.position.top;
} else {
}
else {
y = this.position.top + (size.height - this.position.top - this.position.bottom) / 2.0f -
this.selectedItemOffset.Value;
}

x = size.width - this.position.right - childSize.width;
} else if (this.position.left < this.position.right) {
}
else if (this.position.left < this.position.right) {
} else {
}
else {
} else if (x + childSize.width > size.width - PopupMenuUtils._kMenuScreenPadding) {
}
else if (x + childSize.width > size.width - PopupMenuUtils._kMenuScreenPadding) {
} else if (y + childSize.height > size.height - PopupMenuUtils._kMenuScreenPadding) {
}
else if (y + childSize.height > size.height - PopupMenuUtils._kMenuScreenPadding) {
y = size.height - childSize.height - PopupMenuUtils._kMenuScreenPadding;
}

selectedItemOffset = y + entry.height / 2.0f;
break;
}
y += entry.height;
}
}

Icon icon = null,
Offset offset = null
) : base(key: key) {
offset = offset ?? Offset.zero;
D.assert(itemBuilder != null);
D.assert(offset != null);
D.assert(!(child != null && icon != null));

this.padding = padding ?? EdgeInsets.all(8.0f);
this.child = child;
this.icon = icon;
this.offset = offset ?? Offset.zero;
this.offset = offset;
}

if (!this.mounted) {
return;
}
if (this.widget.onSelected != null) {
this.widget.onSelected(newValue);
}

);
}
}
}
}

6
Runtime/material/theme.cs


return inheritedTheme.theme.data;
}
//todo:xingwei.zhu: material Localizations
return inheritedTheme?.theme?.data ?? _kFallbackTheme;
MaterialLocalizations localizations = MaterialLocalizations.of(context);
ScriptCategory category = ScriptCategory.englishLike;
ThemeData theme = inheritedTheme?.theme?.data ?? _kFallbackTheme;
return ThemeData.localize(theme, theme.typography.geometryThemeFor(category));
}
public override Widget build(BuildContext context) {

107
Runtime/material/theme_data.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
using Unity.UIWidgets.widgets;

);
}
const int _localizedThemeDataCacheSize = 5;
static readonly _FifoCache<_IdentityThemeDataCacheKey, ThemeData> _localizedThemeDataCache =
new _FifoCache<_IdentityThemeDataCacheKey, ThemeData>(_localizedThemeDataCacheSize);
public static ThemeData localize(ThemeData baseTheme, TextTheme localTextGeometry) {
D.assert(baseTheme != null);
D.assert(localTextGeometry != null);
return _localizedThemeDataCache.putIfAbsent(
new _IdentityThemeDataCacheKey(baseTheme, localTextGeometry),
() => {
return baseTheme.copyWith(
primaryTextTheme: localTextGeometry.merge(baseTheme.primaryTextTheme),
accentTextTheme: localTextGeometry.merge(baseTheme.accentTextTheme),
textTheme: localTextGeometry.merge(baseTheme.textTheme)
);
});
}
public static Brightness estimateBrightnessForColor(Color color) {
float relativeLuminance = color.computeLuminance();
float kThreshold = 0.15f;

defaultValue: defaultData.dialogTheme));
properties.add(new DiagnosticsProperty<Typography>("typography", this.typography,
defaultValue: defaultData.typography));
}
}
class _IdentityThemeDataCacheKey : IEquatable<_IdentityThemeDataCacheKey> {
public _IdentityThemeDataCacheKey(
ThemeData baseTheme,
TextTheme localTextGeometry) {
this.baseTheme = baseTheme;
this.localTextGeometry = localTextGeometry;
}
public readonly ThemeData baseTheme;
public readonly TextTheme localTextGeometry;
public bool Equals(_IdentityThemeDataCacheKey other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return this.baseTheme == other.baseTheme &&
this.localTextGeometry == other.localTextGeometry;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((_IdentityThemeDataCacheKey) obj);
}
public static bool operator ==(_IdentityThemeDataCacheKey left, _IdentityThemeDataCacheKey right) {
return Equals(left, right);
}
public static bool operator !=(_IdentityThemeDataCacheKey left, _IdentityThemeDataCacheKey right) {
return !Equals(left, right);
}
public override int GetHashCode() {
var hashCode = this.baseTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.localTextGeometry.GetHashCode();
return hashCode;
}
}
class _FifoCache<K, V> {
public _FifoCache(int maximumSize) {
D.assert(maximumSize > 0);
this._maximumSize = maximumSize;
}
readonly Dictionary<K, V> _cache = new Dictionary<K, V>();
readonly int _maximumSize;
public V putIfAbsent(K key, Func<V> value) {
D.assert(key != null);
D.assert(value != null);
if (this._cache.ContainsKey(key)) {
return this._cache[key];
}
if (this._cache.Count == this._maximumSize) {
this._cache.Remove(this._cache.Keys.First());
}
this._cache[key] = value();
return this._cache[key];
}
}
}

125
Runtime/rendering/layer.cs


using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
namespace Unity.UIWidgets.rendering {

builder.addPerformanceOverlay(this.optionsMask, this.overlayRect.shift(layerOffset));
return null;
}
}
public class AnnotatedRegionLayer<T> : ContainerLayer
where T : class {
public AnnotatedRegionLayer(
T value = null,
Size size = null) {
D.assert(value != null);
this.value = value;
this.size = size;
}
public readonly T value;
public readonly Size size;
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<T>("value", this.value));
properties.add(new DiagnosticsProperty<Size>("size", this.size, defaultValue: null));
}
}
public class PhysicalModelLayer : ContainerLayer {
public PhysicalModelLayer(
Path clipPath = null,
Clip clipBehavior = Clip.none,
float? elevation = null,
Color color = null,
Color shadowColor = null) {
D.assert(clipPath != null);
D.assert(elevation != null);
D.assert(color != null);
D.assert(shadowColor != null);
this._clipPath = clipPath;
this._clipBehavior = clipBehavior;
this._elevation = elevation.Value;
this._color = color;
this.shadowColor = shadowColor;
}
public Path clipPath {
get { return this._clipPath; }
set {
if (value != this._clipPath) {
this._clipPath = value;
this.markNeedsAddToScene();
}
}
}
Path _clipPath;
public Clip clipBehavior {
get { return this._clipBehavior; }
set {
if (value != this._clipBehavior) {
this._clipBehavior = value;
this.markNeedsAddToScene();
}
}
}
Clip _clipBehavior;
public float elevation {
get { return this._elevation; }
set {
if (value != this._elevation) {
this._elevation = value;
this.markNeedsAddToScene();
}
}
}
float _elevation;
public Color color {
get { return this._color; }
set {
if (value != this._color) {
this._color = value;
this.markNeedsAddToScene();
}
}
}
Color _color;
public Color shadowColor {
get { return this._shadowColor; }
set {
if (value != this._shadowColor) {
this._shadowColor = value;
this.markNeedsAddToScene();
}
}
}
Color _shadowColor;
internal override flow.Layer addToScene(SceneBuilder builder, Offset layerOffset = null) {
layerOffset = layerOffset ?? Offset.zero;
builder.pushPhysicalShape(
path: this.clipPath.shift(layerOffset),
elevation: this.elevation,
color: this.color,
shadowColor: this.shadowColor,
clipBehavior: this.clipBehavior);
this.addChildrenToScene(builder, layerOffset);
builder.pop();
return null;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FloatProperty("elevation", this.elevation));
properties.add(new DiagnosticsProperty<Color>("color", this.color));
}
}
}

157
Runtime/rendering/proxy_box.cs


};
context.canvas.drawRect(offset & this.size, paint);
}
return true;
});
}

if (value == this._stepWidth) {
return;
}
this._stepWidth = value;
this.markNeedsLayout();
}

if (value == this._stepHeight) {
return;
}
this._stepHeight = value;
this.markNeedsLayout();
}

if (step == null) {
return input;
}
return (input / step.Value).ceil() * step.Value;
}

if (this.child == null) {
return 0.0f;
}
float width = this.child.getMaxIntrinsicWidth(height);
return _applyStep(width, this._stepWidth);
}

return 0.0f;
}
D.assert(width.isFinite());
float height = this.child.getMinIntrinsicHeight(width);
return _applyStep(height, this._stepHeight);

if (this.child == null) {
return 0.0f;
}
D.assert(width.isFinite());
float height = this.child.getMaxIntrinsicHeight(width);
return _applyStep(height, this._stepHeight);

D.assert(width.isFinite());
childConstraints = childConstraints.tighten(width: _applyStep(width, this._stepWidth));
}
} else {
}
else {
this.performResize();
}
}

if (this.child == null) {
return 0.0f;
}
D.assert(height.isFinite());
return this.child.getMinIntrinsicWidth(height);
}

return 0.0f;
}
D.assert(height.isFinite());
return this.child.getMaxIntrinsicWidth(height);
}

D.assert(height.isFinite());
childConstraints = childConstraints.tighten(height: height);
}
} else {
}
else {
this.performResize();
}
}

return base.hitTest(result, position: position);
}
//todo:xingwei.zhu: implementation shadow + compositeLayer (issue: no color when composite)
//todo:xingwei.zhu: implementation shadow
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();

offsetRRectAsPath.addRRect(offsetRRect);
Canvas canvas = context.canvas;
if (this.elevation != 0.0) {
//draw Shadow
/*canvas.drawRect(
offsetBounds.inflate(20.0),
_RenderPhysicalModelBase<RRect>._transparentPaint
);
canvas.drawShadow(
offsetRRectAsPath,
this.shadowColor,
this.elevation,
this.color.alpha != 0xFF
);*/
if (this.needsCompositing) {
PhysicalModelLayer physicalModel = new PhysicalModelLayer(
clipPath: offsetRRectAsPath,
clipBehavior: this.clipBehavior,
elevation: this.elevation,
color: this.color,
shadowColor: this.shadowColor);
context.pushLayer(physicalModel, base.paint, offset, childPaintBounds: offsetBounds);
else {
Canvas canvas = context.canvas;
if (this.elevation != 0.0) {
//draw Shadow
/*canvas.drawRect(
offsetBounds.inflate(20.0),
_RenderPhysicalModelBase<RRect>._transparentPaint
);
canvas.drawShadow(
offsetRRectAsPath,
this.shadowColor,
this.elevation,
this.color.alpha != 0xFF
);*/
}
if (this.needsCompositing) {
ContainerLayer container = new ContainerLayer();
context.pushLayer(container, base.paint, offset, childPaintBounds: offsetBounds);
return;
Paint paint = new Paint {color = this.color};
canvas.drawRRect(offsetRRect, paint);
context.clipRRectAndPaint(offsetRRect, this.clipBehavior, offsetBounds,
() => base.paint(context, offset));
D.assert(context.canvas == canvas, "canvas changed even though needsCompositing was false");
Paint paint = new Paint {color = this.color};
canvas.drawRRect(offsetRRect, paint);
context.clipRRectAndPaint(offsetRRect, this.clipBehavior, offsetBounds,
() => base.paint(context, offset));
D.assert(context.canvas == canvas, "canvas changed even though needsCompositing was false");
}
}

return base.hitTest(result, position: position);
}
//todo:xingwei.zhu: implementation shadow + compositeLayer (issue: no color when composite)
//todo:xingwei.zhu: implementation shadow
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();

Canvas canvas = context.canvas;
if (this.needsCompositing) {
PhysicalModelLayer physicalModel = new PhysicalModelLayer(
clipPath: offsetPath,
clipBehavior: this.clipBehavior,
elevation: this.elevation,
color: this.color,
shadowColor: this.shadowColor);
context.pushLayer(physicalModel, base.paint, offset, childPaintBounds: offsetBounds);
}
else {
Canvas canvas = context.canvas;
// if (this.elevation != 0.0 && paintShadows) {
// canvas.drawRect(
// offsetBounds.inflate(20.0),

// this.color.alpha != 0xFF,
// );
// }
if (this.needsCompositing) {
ContainerLayer container = new ContainerLayer();
context.pushLayer(container, base.paint, offset, childPaintBounds: offsetBounds);
return;
Paint paint = new Paint {color = this.color, style = PaintingStyle.fill};
canvas.drawPath(offsetPath, paint);
context.clipPathAndPaint(offsetPath, this.clipBehavior,
offsetBounds, () => base.paint(context, offset));
D.assert(context.canvas == canvas, "canvas changed even though needsCompositing was false");
Paint paint = new Paint {color = this.color, style = PaintingStyle.fill};
canvas.drawPath(offsetPath, paint);
context.clipPathAndPaint(offsetPath, this.clipBehavior,
offsetBounds, () => base.paint(context, offset));
D.assert(context.canvas == canvas, "canvas changed even though needsCompositing was false");
}
}

properties.add(new DiagnosticsProperty<bool>("showWhenUnlinked", this.showWhenUnlinked));
properties.add(new DiagnosticsProperty<Offset>("offset", this.offset));
properties.add(new TransformProperty("current transform matrix", this.getCurrentTransform()));
}
}
public class RenderAnnotatedRegion<T> : RenderProxyBox
where T : class {
public RenderAnnotatedRegion(
T value = null,
bool? sized = null,
RenderBox child = null
) : base(child: child) {
D.assert(value != null);
D.assert(sized != null);
this._value = value;
this._sized = sized.Value;
}
public T value {
get { return this._value; }
set {
if (this._value == value) {
return;
}
this._value = value;
this.markNeedsPaint();
}
}
T _value;
public bool sized {
get { return this._sized; }
set {
if (this._sized == value) {
return;
}
this._sized = value;
this.markNeedsPaint();
}
}
bool _sized;
protected override bool alwaysNeedsCompositing {
get { return true; }
}
public override void paint(PaintingContext context, Offset offset) {
AnnotatedRegionLayer<T> layer =
new AnnotatedRegionLayer<T>(value: this.value, size: this.sized ? this.size : null);
context.pushLayer(layer, base.paint, offset);
}
}
}

16
Runtime/service/system_chrome.cs


public override int GetHashCode() {
var hashCode = this.systemNavigationBarColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.systemNavigationBarDividerColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.statusBarColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.statusBarBrightness.GetHashCode();
hashCode = (hashCode * 397) ^ this.statusBarIconBrightness.GetHashCode();
hashCode = (hashCode * 397) ^ this.systemNavigationBarIconBrightness.GetHashCode();
hashCode = (hashCode * 397) ^ (this.systemNavigationBarDividerColor != null
? this.systemNavigationBarDividerColor.GetHashCode()
: 0);
hashCode = (hashCode * 397) ^ (this.statusBarColor != null ? this.statusBarColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(this.statusBarBrightness != null ? this.statusBarBrightness.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(this.statusBarIconBrightness != null ? this.statusBarIconBrightness.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.systemNavigationBarIconBrightness != null
? this.systemNavigationBarIconBrightness.GetHashCode()
: 0);
return hashCode;
}

20
Runtime/ui/compositing.cs


public Layer pushOpacity(int alpha, Offset offset = null) {
offset = offset ?? Offset.zero;
var layer = new OpacityLayer();
layer.alpha = alpha;
layer.offset = offset;

bool isComplexHint = false, bool willChangeHint = false) {
D.assert(offset != null);
D.assert(picture != null);
if (this._currentLayer == null) {
return;
}

if (this._currentLayer == null) {
return;
}
var layer = new TextureLayer();
layer.offset = offset;
layer.size = new Size(width, height);

}
public void addPerformanceOverlay(int enabledOptions, Rect bounds) {
if (this._currentLayer == null) {
return;

bounds.bottom
);
this._currentLayer.add(layer);
}
public Layer pushPhysicalShape(Path path, float elevation, Color color, Color shadowColor, Clip clipBehavior) {
var layer = new PhysicalShapeLayer(clipBehavior);
layer.path = path;
layer.elevation = elevation;
layer.color = color;
layer.shadowColor = shadowColor;
layer.devicePixelRatio = Window.instance.devicePixelRatio;
this._pushLayer(layer);
return layer;
}
}

126
Runtime/widgets/app.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.widgets {
public delegate Locale LocaleListResolutionCallback(List<Locale> locales, List<Locale> supportedLocales);
public delegate Locale LocaleResolutionCallback(Locale locale, List<Locale> supportedLocales);
public delegate PageRoute PageRouteFactory(RouteSettings settings, WidgetBuilder builder);
public class WidgetsApp : StatefulWidget {

public readonly TextStyle textStyle;
public readonly Window window;
public readonly bool showPerformanceoverlay;
public readonly Locale locale;
public readonly List<LocalizationsDelegate> localizationsDelegates;
public readonly LocaleListResolutionCallback localeListResolutionCallback;
public readonly LocaleResolutionCallback localeResolutionCallback;
public readonly List<Locale> supportedLocales;
public WidgetsApp(
Key key = null,

TransitionBuilder builder = null,
TextStyle textStyle = null,
Widget home = null,
Locale locale = null,
List<LocalizationsDelegate> localizationsDelegates = null,
LocaleListResolutionCallback localeListResolutionCallback = null,
LocaleResolutionCallback localeResolutionCallback = null,
List<Locale> supportedLocales = null,
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")};
this.window = Window.instance;
this.home = home;
this.navigatorKey = navigatorKey;

this.initialRoute = initialRoute;
this.builder = builder;
this.textStyle = textStyle;
this.locale = locale;
this.localizationsDelegates = localizationsDelegates;
this.localeListResolutionCallback = localeListResolutionCallback;
this.localeResolutionCallback = localeResolutionCallback;
this.supportedLocales = supportedLocales;
this.showPerformanceoverlay = showPerformanceOverlay;
D.assert(

}
public void didChangeLocales(List<Locale> locale) {
// TODO: support locales.
Locale newLocale = this._resolveLocales(locale, this.widget.supportedLocales);
if (newLocale != this._locale) {
this.setState(() => { this._locale = newLocale; });
}
}
List<LocalizationsDelegate> _localizationsDelegates {
get {
List<LocalizationsDelegate> _delegates = new List<LocalizationsDelegate>();
if (this.widget.localizationsDelegates != null) {
_delegates.AddRange(this.widget.localizationsDelegates);
}
_delegates.Add(DefaultWidgetsLocalizations.del);
return _delegates;
}
//todo: xingwei.zhu: change the default locale to ui.Window.locale
this._locale =
this._resolveLocales(new List<Locale> {new Locale("en", "US")}, this.widget.supportedLocales);
D.assert(() => {
WidgetInspectorService.instance.inspectorShowCallback += this.inspectorShowChanged;
return true;

return result;
}
Locale _locale;
Locale _resolveLocales(List<Locale> preferredLocales, List<Locale> supportedLocales) {
if (this.widget.localeListResolutionCallback != null) {
Locale locale =
this.widget.localeListResolutionCallback(preferredLocales, this.widget.supportedLocales);
if (locale != null) {
return locale;
}
}
if (this.widget.localeResolutionCallback != null) {
Locale locale = this.widget.localeResolutionCallback(
preferredLocales != null && preferredLocales.isNotEmpty() ? preferredLocales.first() : null,
this.widget.supportedLocales
);
if (locale != null) {
return locale;
}
}
return basicLocaleListResolution(preferredLocales, supportedLocales);
}
static Locale basicLocaleListResolution(List<Locale> preferredLocales, List<Locale> supportedLocales) {
if (preferredLocales == null || preferredLocales.isEmpty()) {
return supportedLocales.first();
}
Dictionary<string, Locale> allSupportedLocales = new Dictionary<string, Locale>();
Dictionary<string, Locale> languageLocales = new Dictionary<string, Locale>();
Dictionary<string, Locale> countryLocales = new Dictionary<string, Locale>();
foreach (Locale locale in supportedLocales) {
allSupportedLocales.putIfAbsent(locale.languageCode + "_" + locale.countryCode, () => locale);
languageLocales.putIfAbsent(locale.languageCode, () => locale);
countryLocales.putIfAbsent(locale.countryCode, () => locale);
}
Locale matchesLanguageCode = null;
Locale matchesCountryCode = null;
for (int localeIndex = 0; localeIndex < preferredLocales.Count; localeIndex++) {
Locale userLocale = preferredLocales[localeIndex];
if (allSupportedLocales.ContainsKey(userLocale.languageCode + "_" + userLocale.countryCode)) {
return userLocale;
}
if (matchesLanguageCode != null) {
return matchesLanguageCode;
}
if (languageLocales.ContainsKey(userLocale.languageCode)) {
matchesLanguageCode = languageLocales[userLocale.languageCode];
if (localeIndex == 0 &&
!(localeIndex + 1 < preferredLocales.Count && preferredLocales[localeIndex + 1].languageCode ==
userLocale.languageCode)) {
return matchesLanguageCode;
}
}
if (matchesCountryCode == null && userLocale.countryCode != null) {
if (countryLocales.ContainsKey(userLocale.countryCode)) {
matchesCountryCode = countryLocales[userLocale.countryCode];
}
}
}
Locale resolvedLocale = matchesLanguageCode ?? matchesCountryCode ?? supportedLocales.first();
return resolvedLocale;
}
void inspectorShowChanged() {
this.setState();
}

child: result
);
Locale appLocale = this.widget.locale != null
? this._resolveLocales(new List<Locale> {this.widget.locale}, this.widget.supportedLocales)
: this._locale;
child: result
child: new Localizations(
locale: appLocale,
delegates: this._localizationsDelegates,
child: result)
);
return result;

2
Runtime/widgets/framework.cs


public virtual void didUpdateWidget(StatefulWidget oldWidget) {
}
protected void setState(VoidCallback fn = null) {
public void setState(VoidCallback fn = null) {
D.assert(() => {
if (this._debugLifecycleState == _StateLifecycle.defunct) {
throw new UIWidgetsError(

19
Runtime/widgets/localizations.cs


Type type = del.type;
D.assert(!output.ContainsKey(type));
output[type] = completedValue;
} else {
}
else {
pendingList = pendingList ?? new List<_Pending>();
pendingList.Add(new _Pending(del, futureValue));
}

D.assert(!output.ContainsKey(type));
output[type] = list[i];
}
return output;
});
}

D.assert(locale != null);
D.assert(delegates != null);
D.assert(delegates.Any(del => del is LocalizationsDelegate<WidgetsLocalizations>));
this.locale = locale;
this.delegates = delegates;
this.child = child;
}
public static Localizations overrides(

if (delegates != null) {
mergedDelegates.InsertRange(0, delegates);
}
locale: locale ?? Localizations.localeOf(context),
locale: locale ?? localeOf(context),
delegates: mergedDelegates,
child: child
);

if (nullOk && scope == null) {
return null;
}
D.assert((bool) (scope != null), "a Localizations ancestor was not found");
return scope.localizationsState.locale;
}

return true;
}
}
return false;
}

if (typeToResources != null) {
this._typeToResources = typeToResources;
this._locale = locale;
} else {
}
else {
// WidgetsBinding.instance.deferFirstFrameReport();
typeToResourcesFuture.Then(value => {
// WidgetsBinding.instance.allowFirstFrameReport();

this.setState(() => {
this._typeToResources = value;
this._locale = locale;

if (this._locale == null) {
return new Container();
}
return new _LocalizationsScope(
key: this._localizedResourcesScopeKey,
locale: this._locale,

);
}
}
}
}

36
Runtime/widgets/transitions.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;

return new FractionalTranslation(
translation: offset,
transformHitTests: this.transformHitTests,
child: this.child
);
}
}
public class ScaleTransition : AnimatedWidget {
public ScaleTransition(
Key key = null,
Animation<float> scale = null,
Alignment alignment = null,
Widget child = null
) : base(key: key, listenable: scale) {
alignment = alignment ?? Alignment.center;
D.assert(scale != null);
this.alignment = alignment;
this.child = child;
}
public Animation<float> scale {
get { return (Animation<float>) this.listenable; }
}
public readonly Alignment alignment;
public readonly Widget child;
protected internal override Widget build(BuildContext context) {
float scaleValue = this.scale.value;
Matrix3 transform = Matrix3.makeScale(scaleValue, scaleValue);
return new Transform(
transform: transform,
alignment: this.alignment,
child: this.child
);
}

198
Samples/UIWidgetSample/MaterialSample.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
int testCaseId = 0;
int testCaseId = 2;
new MaterialInkWellWidget()
new MaterialInkWellWidget(),
new MaterialAppBarWidget()
showPerformanceOverlay: true,
protected override void OnEnable() {
base.OnEnable();
FontManager.instance.addFont(Resources.Load<Font>(path: "MaterialIcons-Regular"));
}
}
class MaterialAppBarWidget : StatefulWidget {
public MaterialAppBarWidget(Key key = null) : base(key) {
}
public override State createState() {
return new MaterialAppBarWidgetState();
}
}
class MaterialAppBarWidgetState : State<MaterialAppBarWidget> {
Choice _selectedChoice = Choice.choices[0];
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
VoidCallback _showBottomSheetCallback;
public override void initState() {
base.initState();
this._showBottomSheetCallback = this._showBottomSheet;
}
void _showBottomSheet() {
this.setState(() => { this._showBottomSheetCallback = null; });
this._scaffoldKey.currentState.showBottomSheet((BuildContext subContext) => {
ThemeData themeData = Theme.of(subContext);
return new Container(
decoration: new BoxDecoration(
border: new Border(
top: new BorderSide(
color: themeData.disabledColor))),
child: new Padding(
padding: EdgeInsets.all(32.0f),
child: new Text("This is a Material persistent bottom sheet. Drag downwards to dismiss it.",
textAlign: TextAlign.center,
style: new TextStyle(
color: themeData.accentColor,
fontSize: 16.0f))
)
);
}).closed.Then((object obj) => {
if (this.mounted) {
this.setState(() => { this._showBottomSheetCallback = this._showBottomSheet; });
}
return null;
});
}
void _select(Choice choice) {
this.setState(() => { this._selectedChoice = choice; });
}
public override Widget build(BuildContext context) {
return new Scaffold(
key: this._scaffoldKey,
appBar: new AppBar(
title: new Text("Basic AppBar"),
actions: new List<Widget> {
new IconButton(
icon: new Icon(Choice.choices[0].icon),
//color: Colors.blue,
onPressed: () => { this._select((Choice.choices[0])); }
),
new IconButton(
icon: new Icon(Choice.choices[1].icon),
//color: Colors.blue,
onPressed: () => { this._select((Choice.choices[1])); }
),
new PopupMenuButton<Choice>(
onSelected: this._select,
itemBuilder: (BuildContext subContext) => {
List<PopupMenuEntry<Choice>> popupItems = new List<PopupMenuEntry<Choice>>();
for (int i = 2; i < Choice.choices.Count; i++) {
popupItems.Add(new PopupMenuItem<Choice>(
value: Choice.choices[i],
child: new Text(Choice.choices[i].title)));
}
return popupItems;
}
)
}
),
body: new Padding(
padding: EdgeInsets.all(16.0f),
child: new ChoiceCard(choice: this._selectedChoice)
),
floatingActionButton: new FloatingActionButton(
backgroundColor: Colors.redAccent,
child: new Icon(Unity.UIWidgets.material.Icons.add_alert),
onPressed: this._showBottomSheetCallback
),
drawer: new Drawer(
child: new ListView(
padding: EdgeInsets.zero,
children: new List<Widget> {
new ListTile(
leading: new Icon(Unity.UIWidgets.material.Icons.account_circle),
title: new Text("Login"),
onTap: () => { }
),
new Divider(
height: 2.0f),
new ListTile(
leading: new Icon(Unity.UIWidgets.material.Icons.account_balance_wallet),
title: new Text("Wallet"),
onTap: () => { }
),
new Divider(
height: 2.0f),
new ListTile(
leading: new Icon(Unity.UIWidgets.material.Icons.accessibility),
title: new Text("Balance"),
onTap: () => { }
)
}
)
)
);
}
}
class Choice {
public Choice(string title, IconData icon) {
this.title = title;
this.icon = icon;
}
public readonly string title;
public readonly IconData icon;
public static List<Choice> choices = new List<Choice> {
new Choice("Car", Unity.UIWidgets.material.Icons.directions_car),
new Choice("Bicycle", Unity.UIWidgets.material.Icons.directions_bike),
new Choice("Boat", Unity.UIWidgets.material.Icons.directions_boat),
new Choice("Bus", Unity.UIWidgets.material.Icons.directions_bus),
new Choice("Train", Unity.UIWidgets.material.Icons.directions_railway),
new Choice("Walk", Unity.UIWidgets.material.Icons.directions_walk)
};
}
class ChoiceCard : StatelessWidget {
public ChoiceCard(Key key = null, Choice choice = null) : base(key: key) {
this.choice = choice;
}
public readonly Choice choice;
public override Widget build(BuildContext context) {
TextStyle textStyle = Theme.of(context).textTheme.display1;
return new Card(
color: Colors.white,
child: new Center(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget> {
new Icon(this.choice.icon, size: 128.0f, color: textStyle.color),
new RaisedButton(
child: new Text(this.choice.title, style: textStyle),
onPressed: () => {
SnackBar snackBar = new SnackBar(
content: new Text(this.choice.title + " is chosen !"),
action: new SnackBarAction(
label: "Ok",
onPressed: () => { }));
Scaffold.of(context).showSnackBar(snackBar);
})
}
)
)
);
}
}
class MaterialInkWellWidget : StatefulWidget {

class MaterialInkWidgetState : State<MaterialInkWellWidget> {
public override Widget build(BuildContext context) {
return new Material(
//color: Colors.blue,
width: 30,
height: 30,
width: 200,
height: 200,
child: new InkWell(
borderRadius: BorderRadius.circular(2.0f),
highlightColor: new Color(0xAAFF0000),

140
Samples/UIWidgetSample/UIWidgetSample.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.37311947, g: 0.38074, b: 0.35872698, a: 1}
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074, b: 0.35872698, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &304189371
MonoBehaviour:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1148735784}
m_CullTransparentMesh: 0
--- !u!1 &1155767695
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1155767701}
- component: {fileID: 1155767700}
- component: {fileID: 1155767699}
- component: {fileID: 1155767698}
- component: {fileID: 1155767697}
- component: {fileID: 1155767696}
m_Layer: 5
m_Name: Canvas2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1155767696
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1155767695}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d7c3be43dd8b94a349f26e3e7173c3f6, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
devicePixelRatioOverride: 0
--- !u!222 &1155767697
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1155767695}
m_CullTransparentMesh: 0
--- !u!114 &1155767698
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1155767695}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1155767699
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1155767695}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &1155767700
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1155767695}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &1155767701
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1155767695}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1 &1199742531
GameObject:
m_ObjectHideFlags: 0

82
Runtime/flow/physical_shape_layer.cs


using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.flow {
public class PhysicalShapeLayer : ContainerLayer {
public PhysicalShapeLayer(
Clip clipBehavior) {
this._isRect = false;
this._clip_behavior = clipBehavior;
}
float _elevation;
Color _color;
Color _shadow_color;
float _device_pixel_ratio;
Path _path;
bool _isRect;
Rect _frameRRect;
Clip _clip_behavior;
public Path path {
set {
//todo: xingwei.zhu : try to do path => rect transfer
this._path = value;
this._isRect = false;
this._frameRRect = value.getBounds();
}
}
public float elevation {
set { this._elevation = value; }
}
public Color color {
set { this._color = value; }
}
public Color shadowColor {
set { this._shadow_color = value; }
}
public float devicePixelRatio {
set { this._device_pixel_ratio = value; }
}
public override void preroll(PrerollContext context, Matrix3 matrix) {
Rect child_paint_bounds = Rect.zero;
this.prerollChildren(context, matrix, ref child_paint_bounds);
if (this._elevation == 0) {
this.paintBounds = this._path.getBounds();
}
else {
Rect bounds = this._path.getBounds();
//todo xingwei.zhu: outter set shadow
//bounds.outset(20.0f, 20.0f);
this.paintBounds = bounds;
}
}
public override void paint(PaintContext context) {
if (this._elevation != 0) {
this.drawShadow(context.canvas, this._path, this._shadow_color, this._elevation,
this._color.alpha != 255, this._device_pixel_ratio);
}
Paint paint = new Paint {color = this._color};
//todo: xingwei.zhu: process according to different clipBehavior, currently use antiAlias as default
context.canvas.drawPath(this._path, paint);
context.canvas.save();
context.canvas.clipPath(this._path);
this.paintChildren(context);
context.canvas.restore();
}
void drawShadow(Canvas canvas, Path path, Color color, float elevation, bool transparentOccluder, float dpr) {
//todo xingwei.zhu: to be implemented
}
}
}

11
Runtime/flow/physical_shape_layer.cs.meta


fileFormatVersion: 2
guid: e4609617e4ba5483b811e8cc9d60ce15
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

301
Runtime/material/app_bar.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
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 {
static class AppBarUtils {
internal const float _kLeadingWidth = Constants.kToolbarHeight;
}
class _ToolbarContainerLayout : SingleChildLayoutDelegate {
public _ToolbarContainerLayout() {
}
public override BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
return constraints.tighten(height: Constants.kToolbarHeight);
}
public override Size getSize(BoxConstraints constraints) {
return new Size(constraints.maxWidth, Constants.kToolbarHeight);
}
public override Offset getPositionForChild(Size size, Size childSize) {
return new Offset(0.0f, size.height - childSize.height);
}
public override bool shouldRelayout(SingleChildLayoutDelegate oldDelegate) {
return false;
}
}
public class AppBar : PreferredSizeWidget {
public AppBar(
Key key = null,
Widget leading = null,
bool automaticallyImplyLeading = true,
Widget title = null,
List<Widget> actions = null,
Widget flexibleSpace = null,
PreferredSizeWidget bottom = null,
float elevation = 4.0f,
Color backgroundColor = null,
Brightness? brightness = null,
IconThemeData iconTheme = null,
TextTheme textTheme = null,
bool primary = true,
bool? centerTitle = null,
float titleSpacing = NavigationToolbar.kMiddleSpacing,
float toolbarOpacity = 1.0f,
float bottomOpacity = 1.0f
) : base(key: key) {
this.leading = leading;
this.automaticallyImplyLeading = automaticallyImplyLeading;
this.title = title;
this.actions = actions;
this.flexibleSpace = flexibleSpace;
this.bottom = bottom;
this.elevation = elevation;
this.backgroundColor = backgroundColor;
this.brightness = brightness;
this.iconTheme = iconTheme;
this.textTheme = textTheme;
this.primary = primary;
this.centerTitle = centerTitle;
this.titleSpacing = titleSpacing;
this.toolbarOpacity = toolbarOpacity;
this.bottomOpacity = bottomOpacity;
this.preferredSize = Size.fromHeight(Constants.kToolbarHeight + (bottom?.preferredSize?.height ?? 0.0f));
}
public readonly Widget leading;
public readonly bool automaticallyImplyLeading;
public readonly Widget title;
public readonly List<Widget> actions;
public readonly Widget flexibleSpace;
public readonly PreferredSizeWidget bottom;
public readonly float elevation;
public readonly Color backgroundColor;
public readonly Brightness? brightness;
public readonly IconThemeData iconTheme;
public readonly TextTheme textTheme;
public readonly bool primary;
public readonly bool? centerTitle;
public readonly float titleSpacing;
public readonly float toolbarOpacity;
public readonly float bottomOpacity;
public override Size preferredSize { get; }
public bool? _getEffectiveCenterTitle(ThemeData themeData) {
if (this.centerTitle != null) {
return this.centerTitle;
}
D.assert(themeData.platform != null);
switch (themeData.platform) {
case RuntimePlatform.IPhonePlayer:
return this.actions == null || this.actions.Count < 2;
default:
return false;
}
return null;
}
public override State createState() {
return new _AppBarState();
}
}
class _AppBarState : State<AppBar> {
void _handleDrawerButton() {
Scaffold.of(this.context).openDrawer();
}
void _handleDrawerButtonEnd() {
Scaffold.of(this.context).openEndDrawer();
}
public override Widget build(BuildContext context) {
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
ThemeData themeData = Theme.of(context);
ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
ModalRoute parentRoute = ModalRoute.of(context);
bool hasDrawer = scaffold?.hasDrawer ?? false;
bool hasEndDrawer = scaffold?.hasEndDrawer ?? false;
bool canPop = parentRoute?.canPop ?? false;
bool useCloseButton = parentRoute is PageRoute && ((PageRoute) parentRoute).fullscreenDialog;
IconThemeData appBarIconTheme = this.widget.iconTheme ?? themeData.primaryIconTheme;
TextStyle centerStyle = this.widget.textTheme?.title ?? themeData.primaryTextTheme.title;
TextStyle sideStyle = this.widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1;
if (this.widget.toolbarOpacity != 1.0f) {
float opacity =
new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.widget.toolbarOpacity);
if (centerStyle?.color != null) {
centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity));
}
if (sideStyle?.color != null) {
sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity));
}
appBarIconTheme = appBarIconTheme.copyWith(
opacity: opacity * (appBarIconTheme.opacity ?? 1.0f)
);
}
Widget leading = this.widget.leading;
if (leading == null && this.widget.automaticallyImplyLeading) {
if (hasDrawer) {
leading = new IconButton(
icon: new Icon(Icons.menu),
onPressed: this._handleDrawerButton,
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip);
}
else {
if (canPop) {
leading = useCloseButton ? (Widget) new CloseButton() : new BackButton();
}
}
}
if (leading != null) {
leading = new ConstrainedBox(
constraints: BoxConstraints.tightFor(width: AppBarUtils._kLeadingWidth),
child: leading);
}
Widget title = this.widget.title;
if (title != null) {
bool namesRoute = false;
switch (Application.platform) {
case RuntimePlatform.IPhonePlayer:
break;
default:
namesRoute = true;
break;
}
title = new DefaultTextStyle(
style: centerStyle,
softWrap: false,
overflow: TextOverflow.ellipsis,
child: title);
}
Widget actions = null;
if (this.widget.actions != null && this.widget.actions.isNotEmpty()) {
actions = new Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: this.widget.actions);
}
else if (hasEndDrawer) {
actions = new IconButton(
icon: new Icon(Icons.menu),
onPressed: this._handleDrawerButtonEnd,
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip);
}
Widget toolbar = new NavigationToolbar(
leading: leading,
middle: title,
trailing: actions,
centerMiddle: this.widget._getEffectiveCenterTitle(themeData).Value,
middleSpacing: this.widget.titleSpacing);
Widget appBar = new ClipRect(
child: new CustomSingleChildLayout(
layoutDelegate: new _ToolbarContainerLayout(),
child: IconTheme.merge(
data: appBarIconTheme,
child: new DefaultTextStyle(
style: sideStyle,
child: toolbar)
)
)
);
if (this.widget.bottom != null) {
appBar = new Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: new List<Widget> {
new Flexible(
child: new ConstrainedBox(
constraints: new BoxConstraints(maxHeight: Constants.kToolbarHeight),
child: appBar
)
),
this.widget.bottomOpacity == 1.0f
? (Widget) this.widget.bottom
: new Opacity(
opacity: new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.widget
.bottomOpacity),
child: this.widget.bottom
)
}
);
}
if (this.widget.primary) {
appBar = new SafeArea(
top: true,
child: appBar);
}
appBar = new Align(
alignment: Alignment.topCenter,
child: appBar);
if (this.widget.flexibleSpace != null) {
appBar = new Stack(
fit: StackFit.passthrough,
children: new List<Widget> {
this.widget.flexibleSpace,
appBar
}
);
}
Brightness brightness = this.widget.brightness ?? themeData.primaryColorBrightness;
SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark;
return new AnnotatedRegion<SystemUiOverlayStyle>(
value: overlayStyle,
child: new Material(
color: this.widget.backgroundColor ?? themeData.primaryColor,
elevation: this.widget.elevation,
child: appBar
));
}
}
}

11
Runtime/material/app_bar.cs.meta


fileFormatVersion: 2
guid: da897030c4af84749a3ac5494e45c359
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

60
Runtime/material/back_button.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
public class BackButtonIcon : StatelessWidget {
public BackButtonIcon(
Key key = null) : base(key: key) {
}
static IconData _getIconData(RuntimePlatform platform) {
switch (platform) {
case RuntimePlatform.IPhonePlayer:
return Icons.arrow_back_ios;
default:
return Icons.arrow_back;
}
D.assert(false);
return null;
}
public override Widget build(BuildContext context) {
return new Icon(_getIconData(Theme.of(context).platform));
}
}
public class BackButton : StatelessWidget {
public BackButton(
Key key = null,
Color color = null) : base(key: key) {
this.color = color;
}
public readonly Color color;
public override Widget build(BuildContext context) {
return new IconButton(
icon: new BackButtonIcon(),
color: this.color,
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
onPressed: () => { Navigator.maybePop(context); });
}
}
public class CloseButton : StatelessWidget {
public CloseButton(
Key key = null) : base(key: key) {
}
public override Widget build(BuildContext context) {
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
return new IconButton(
icon: new Icon(Icons.close),
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
onPressed: () => { Navigator.maybePop(context); });
}
}
}

11
Runtime/material/back_button.cs.meta


fileFormatVersion: 2
guid: 485e2aa6981384670925d74e140d54b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

127
Runtime/material/bottom_sheet.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;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class BottomSheetUtils {
public static readonly TimeSpan _kBottomSheetDuration = new TimeSpan(0, 0, 0, 0, 200);
public const float _kMinFlingVelocity = 700.0f;
public const float _kCloseProgressThreshold = 0.5f;
}
public class BottomSheet : StatefulWidget {
public BottomSheet(
Key key = null,
AnimationController animationController = null,
bool enableDrag = true,
float elevation = 0.0f,
VoidCallback onClosing = null,
WidgetBuilder builder = null
) : base(key: key) {
D.assert(onClosing != null);
D.assert(builder != null);
this.animationController = animationController;
this.enableDrag = enableDrag;
this.elevation = elevation;
this.onClosing = onClosing;
this.builder = builder;
}
public readonly AnimationController animationController;
public readonly VoidCallback onClosing;
public readonly WidgetBuilder builder;
public readonly bool enableDrag;
public readonly float elevation;
public override State createState() {
return new _BottomSheetState();
}
public static AnimationController createAnimationController(TickerProvider vsync) {
return new AnimationController(
duration: BottomSheetUtils._kBottomSheetDuration,
debugLabel: "BottomSheet",
vsync: vsync
);
}
}
class _BottomSheetState : State<BottomSheet> {
readonly GlobalKey _childKey = GlobalKey.key(debugLabel: "BottomSheet child");
float? _childHeight {
get {
RenderBox renderBox = (RenderBox) this._childKey.currentContext.findRenderObject();
return renderBox.size.height;
}
}
bool _dismissUnderway {
get { return this.widget.animationController.status == AnimationStatus.reverse; }
}
void _handleDragUpdate(DragUpdateDetails details) {
if (this._dismissUnderway) {
return;
}
this.widget.animationController.setValue(
this.widget.animationController.value -
details.primaryDelta.Value / (this._childHeight ?? details.primaryDelta.Value));
}
void _handleDragEnd(DragEndDetails details) {
if (this._dismissUnderway) {
return;
}
if (details.velocity.pixelsPerSecond.dy > BottomSheetUtils._kMinFlingVelocity) {
float flingVelocity = -details.velocity.pixelsPerSecond.dy / this._childHeight.Value;
if (this.widget.animationController.value > 0.0f) {
this.widget.animationController.fling(velocity: flingVelocity);
}
if (flingVelocity < 0.0f) {
this.widget.onClosing();
}
}
else if (this.widget.animationController.value < BottomSheetUtils._kCloseProgressThreshold) {
if (this.widget.animationController.value > 0.0f) {
this.widget.animationController.fling(velocity: -1.0f);
}
this.widget.onClosing();
}
else {
this.widget.animationController.forward();
}
}
public override Widget build(BuildContext context) {
Widget bottomSheet = new Material(
key: this._childKey,
elevation: this.widget.elevation,
child: this.widget.builder(context)
);
return !this.widget.enableDrag
? bottomSheet
: new GestureDetector(
onVerticalDragUpdate: this._handleDragUpdate,
onVerticalDragEnd: this._handleDragEnd,
child: bottomSheet
);
}
}
}

11
Runtime/material/bottom_sheet.cs.meta


fileFormatVersion: 2
guid: 5219593daa853417ebb5f7835c74a969
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

221
Runtime/material/flexible_space_bar.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
using Transform = Unity.UIWidgets.widgets.Transform;
namespace Unity.UIWidgets.material {
public enum CollapseMode {
parallax,
pin,
none
}
public class FlexibleSpaceBar : StatefulWidget {
public FlexibleSpaceBar(
Key key = null,
Widget title = null,
Widget background = null,
bool? centerTitle = null,
CollapseMode collapseMode = CollapseMode.parallax
) : base(key: key) {
this.title = title;
this.background = background;
this.centerTitle = centerTitle;
this.collapseMode = collapseMode;
}
public readonly Widget title;
public readonly Widget background;
public readonly bool? centerTitle;
public readonly CollapseMode collapseMode;
public static Widget createSettings(
float? toolbarOpacity = null,
float? minExtent = null,
float? maxExtent = null,
float? currentExtent = null,
Widget child = null) {
D.assert(currentExtent != null);
D.assert(child != null);
return new FlexibleSpaceBarSettings(
toolbarOpacity: toolbarOpacity ?? 1.0f,
minExtent: minExtent ?? currentExtent,
maxExtent: maxExtent ?? currentExtent,
currentExtent: currentExtent,
child: child
);
}
public override State createState() {
return new _FlexibleSpaceBarState();
}
}
class _FlexibleSpaceBarState : State<FlexibleSpaceBar> {
bool? _getEffectiveCenterTitle(ThemeData themeData) {
if (this.widget.centerTitle != null) {
return this.widget.centerTitle;
}
D.assert(themeData.platform != null);
switch (themeData.platform) {
case RuntimePlatform.IPhonePlayer:
return true;
default:
return false;
}
return null;
}
Alignment _getTitleAlignment(bool effectiveCenterTitle) {
if (effectiveCenterTitle) {
return Alignment.bottomCenter;
}
return Alignment.bottomLeft;
}
float? _getCollapsePadding(float t, FlexibleSpaceBarSettings settings) {
switch (this.widget.collapseMode) {
case CollapseMode.pin:
return -(settings.maxExtent.Value - settings.currentExtent.Value);
case CollapseMode.none:
return 0.0f;
case CollapseMode.parallax:
float deltaExtent = settings.maxExtent.Value - settings.minExtent.Value;
return -new FloatTween(begin: 0.0f, end: deltaExtent / 4.0f).lerp(t);
}
return null;
}
public override Widget build(BuildContext context) {
FlexibleSpaceBarSettings settings =
(FlexibleSpaceBarSettings) context.inheritFromWidgetOfExactType(typeof(FlexibleSpaceBarSettings));
D.assert(settings != null,
"A FlexibleSpaceBar must be wrapped in the widget returned by FlexibleSpaceBar.createSettings().");
List<Widget> children = new List<Widget>();
float deltaExtent = settings.maxExtent.Value - settings.minExtent.Value;
float t = (1.0f - (settings.currentExtent.Value - settings.minExtent.Value) / deltaExtent)
.clamp(0.0f, 1.0f);
if (this.widget.background != null) {
float fadeStart = Mathf.Max(0.0f, 1.0f - Constants.kToolbarHeight / deltaExtent);
float fadeEnd = 1.0f;
D.assert(fadeStart <= fadeEnd);
float opacity = 1.0f - new Interval(fadeStart, fadeEnd).transform(t);
if (opacity > 0.0f) {
children.Add(new Positioned(
top: this._getCollapsePadding(t, settings),
left: 0.0f,
right: 0.0f,
height: settings.maxExtent,
child: new Opacity(
opacity: opacity,
child: this.widget.background)
)
);
}
}
Widget title = null;
if (this.widget.title != null) {
switch (Application.platform) {
case RuntimePlatform.IPhonePlayer:
title = this.widget.title;
break;
default:
title = this.widget.title;
break;
}
}
ThemeData theme = Theme.of(context);
float toolbarOpacity = settings.toolbarOpacity.Value;
if (toolbarOpacity > 0.0f) {
TextStyle titleStyle = theme.primaryTextTheme.title;
titleStyle = titleStyle.copyWith(
color: titleStyle.color.withOpacity(toolbarOpacity));
bool effectiveCenterTitle = this._getEffectiveCenterTitle(theme).Value;
float scaleValue = new FloatTween(begin: 1.5f, end: 1.0f).lerp(t);
Matrix3 scaleTransform = Matrix3.makeScale(scaleValue, scaleValue);
Alignment titleAlignment = this._getTitleAlignment(effectiveCenterTitle);
children.Add(new Container(
padding: EdgeInsets.fromLTRB(
effectiveCenterTitle ? 0.0f : 72.0f,
0f,
0f,
16.0f),
child: new Transform(
alignment: titleAlignment,
transform: scaleTransform,
child: new Align(
alignment: titleAlignment,
child: new DefaultTextStyle(
style: titleStyle,
child: title)
)
)
)
);
}
return new ClipRect(
child: new Stack(
children: children)
);
}
}
public class FlexibleSpaceBarSettings : InheritedWidget {
public FlexibleSpaceBarSettings(
Key key = null,
float? toolbarOpacity = null,
float? minExtent = null,
float? maxExtent = null,
float? currentExtent = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(currentExtent != null);
D.assert(child != null);
this.toolbarOpacity = toolbarOpacity;
this.minExtent = minExtent;
this.maxExtent = maxExtent;
this.currentExtent = currentExtent;
}
public readonly float? toolbarOpacity;
public readonly float? minExtent;
public readonly float? maxExtent;
public readonly float? currentExtent;
public override bool updateShouldNotify(InheritedWidget oldWidget) {
FlexibleSpaceBarSettings _oldWidget = (FlexibleSpaceBarSettings) oldWidget;
return this.toolbarOpacity != _oldWidget.toolbarOpacity
|| this.minExtent != _oldWidget.minExtent
|| this.maxExtent != _oldWidget.maxExtent
|| this.currentExtent != _oldWidget.currentExtent;
}
}
}

11
Runtime/material/flexible_space_bar.cs.meta


fileFormatVersion: 2
guid: ae1ab951014d2444da9ac1419a3f111b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

282
Runtime/material/float_action_button.cs


using System.Collections.Generic;
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;
namespace Unity.UIWidgets.material {
static class FloatActionButtonUtils {
public static readonly BoxConstraints _kSizeConstraints = BoxConstraints.tightFor(width: 56.0f, height: 56.0f);
public static readonly BoxConstraints _kMiniSizeConstraints =
BoxConstraints.tightFor(width: 40.0f, height: 40.0f);
public static readonly BoxConstraints _kExtendedSizeConstraints =
new BoxConstraints(minHeight: 48.0f, maxHeight: 48.0f);
}
class _DefaultHeroTag {
public _DefaultHeroTag() {
}
public override string ToString() {
return "<default FloatingActionButton tag>";
}
}
public class FloatingActionButton : StatefulWidget {
FloatingActionButton(
Key key = null,
Widget child = null,
string tooltip = null,
Color foregroundColor = null,
Color backgroundColor = null,
object heroTag = null,
float elevation = 6.0f,
float highlightElevation = 12.0f,
VoidCallback onPressed = null,
bool mini = false,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize? materialTapTargetSize = null,
bool isExtended = false,
BoxConstraints _sizeConstraints = null
) : base(key: key) {
heroTag = heroTag ?? new _DefaultHeroTag();
shape = shape ?? new CircleBorder();
this.child = child;
this.tooltip = tooltip;
this.foregroundColor = foregroundColor;
this.backgroundColor = backgroundColor;
this.heroTag = heroTag;
this.elevation = elevation;
this.highlightElevation = highlightElevation;
this.onPressed = onPressed;
this.mini = mini;
this.shape = shape;
this.clipBehavior = clipBehavior;
this.materialTapTargetSize = materialTapTargetSize;
this.isExtended = isExtended;
this._sizeConstraints = _sizeConstraints ??
(mini
? FloatActionButtonUtils._kMiniSizeConstraints
: FloatActionButtonUtils._kSizeConstraints);
}
public FloatingActionButton(
Key key = null,
Widget child = null,
string tooltip = null,
Color foregroundColor = null,
Color backgroundColor = null,
object heroTag = null,
float elevation = 6.0f,
float highlightElevation = 12.0f,
VoidCallback onPressed = null,
bool mini = false,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize? materialTapTargetSize = null,
bool isExtended = false
) : this(key: key,
child: child,
tooltip: tooltip,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
heroTag: heroTag,
elevation: elevation,
highlightElevation: highlightElevation,
onPressed: onPressed,
mini: mini,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
isExtended: isExtended,
_sizeConstraints: null) {
}
public static FloatingActionButton extended(
Key key = null,
string tooltip = null,
Color foregroundColor = null,
Color backgroundColor = null,
object heroTag = null,
float elevation = 6.0f,
float highlightElevation = 12.0f,
VoidCallback onPressed = null,
ShapeBorder shape = null,
bool isExtended = true,
MaterialTapTargetSize? materialTapTargetSize = null,
Clip clipBehavior = Clip.none,
Widget icon = null,
Widget label = null
) {
heroTag = heroTag ?? new _DefaultHeroTag();
shape = shape ?? new StadiumBorder();
D.assert(icon != null);
D.assert(label != null);
BoxConstraints _sizeConstraints = FloatActionButtonUtils._kExtendedSizeConstraints;
bool mini = false;
Widget child = new _ChildOverflowBox(
child: new Row(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new SizedBox(width: 16.0f),
icon,
new SizedBox(width: 8.0f),
label,
new SizedBox(width: 20.0f)
}));
return new FloatingActionButton(
key: key,
child: child,
tooltip: tooltip,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
heroTag: heroTag,
elevation: elevation,
highlightElevation: highlightElevation,
onPressed: onPressed,
mini: mini,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
isExtended: isExtended,
_sizeConstraints: _sizeConstraints
);
}
public readonly Widget child;
public readonly string tooltip;
public readonly Color foregroundColor;
public readonly Color backgroundColor;
public readonly object heroTag;
public readonly VoidCallback onPressed;
public readonly float elevation;
public readonly float highlightElevation;
public readonly bool mini;
public readonly ShapeBorder shape;
public readonly Clip clipBehavior;
public readonly bool isExtended;
public readonly MaterialTapTargetSize? materialTapTargetSize;
public readonly BoxConstraints _sizeConstraints;
public override State createState() {
return new _FloatingActionButtonState();
}
}
public class _FloatingActionButtonState : State<FloatingActionButton> {
bool _highlight = false;
void _handleHighlightChanged(bool value) {
this.setState(() => { this._highlight = value; });
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
Color foregroundColor = this.widget.foregroundColor ?? theme.accentIconTheme.color;
Widget result = null;
if (this.widget.child != null) {
result = IconTheme.merge(
data: new IconThemeData(
color: foregroundColor),
child: this.widget.child
);
}
result = new RawMaterialButton(
onPressed: this.widget.onPressed,
onHighlightChanged: this._handleHighlightChanged,
elevation: this._highlight ? this.widget.highlightElevation : this.widget.elevation,
constraints: this.widget._sizeConstraints,
materialTapTargetSize: this.widget.materialTapTargetSize ?? theme.materialTapTargetSize,
fillColor: this.widget.backgroundColor ?? theme.accentColor,
textStyle: theme.accentTextTheme.button.copyWith(
color: foregroundColor,
letterSpacing: 1.2f),
shape: this.widget.shape,
clipBehavior: this.widget.clipBehavior,
child: result);
if (this.widget.tooltip != null) {
result = new Tooltip(
message: this.widget.tooltip,
child: result);
}
//todo: xingwei.zhu: Hero widget
// if (this.widget.heroTag != null) {
// result = new Hero(
// tag: this.widget.heroTag,
// child: result);
// }
return result;
}
}
class _ChildOverflowBox : SingleChildRenderObjectWidget {
public _ChildOverflowBox(
Key key = null,
Widget child = null) : base(key: key, child: child) {
}
public override RenderObject createRenderObject(BuildContext context) {
return new _RenderChildOverflowBox();
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
}
}
class _RenderChildOverflowBox : RenderAligningShiftedBox {
public _RenderChildOverflowBox(
RenderBox child = null) : base(child: child, alignment: Alignment.center) {
}
protected override float computeMinIntrinsicWidth(float height) {
return 0.0f;
}
protected override float computeMinIntrinsicHeight(float width) {
return 0.0f;
}
protected override void performLayout() {
if (this.child != null) {
this.child.layout(new BoxConstraints(), parentUsesSize: true);
this.size = new Size(
Mathf.Max(this.constraints.minWidth, Mathf.Min(this.constraints.maxWidth, this.child.size.width)),
Mathf.Max(this.constraints.minHeight, Mathf.Min(this.constraints.maxHeight, this.child.size.height))
);
this.alignChild();
}
else {
this.size = this.constraints.biggest;
}
}
}
}

11
Runtime/material/float_action_button.cs.meta


fileFormatVersion: 2
guid: 274f3c1005cd046a28b169d8048c0292
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

223
Runtime/material/float_action_button_location.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.ui;
using UnityEngine;
namespace Unity.UIWidgets.material {
public static class FloatingActionButtonLocationUtils {
public const float kFloatingActionButtonMargin = 16.0f;
public static readonly TimeSpan kFloatingActionButtonSegue = new TimeSpan(0, 0, 0, 0, 200);
public const float kFloatingActionButtonTurnInterval = 0.125f;
}
public abstract class FloatingActionButtonLocation {
protected FloatingActionButtonLocation() {
}
public static readonly FloatingActionButtonLocation endFloat = new _EndFloatFabLocation();
public static readonly FloatingActionButtonLocation centerFloat = new _CenterFloatFabLocation();
public static readonly FloatingActionButtonLocation endDocked = new _EndDockedFloatingActionButtonLocation();
public static readonly FloatingActionButtonLocation centerDocked =
new _CenterDockedFloatingActionButtonLocation();
public abstract Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry);
public override string ToString() {
return this.GetType().ToString();
}
}
class _CenterFloatFabLocation : FloatingActionButtonLocation {
public _CenterFloatFabLocation() {
}
public override Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
float fabX = (scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width) / 2.0f;
float contentBottom = scaffoldGeometry.contentBottom;
float bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height;
float fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
float snackBarHeight = scaffoldGeometry.snackBarSize.height;
float fabY = contentBottom - fabHeight - FloatingActionButtonLocationUtils.kFloatingActionButtonMargin;
if (snackBarHeight > 0.0f) {
fabY = Mathf.Min(fabY,
contentBottom - snackBarHeight - fabHeight -
FloatingActionButtonLocationUtils.kFloatingActionButtonMargin);
}
if (bottomSheetHeight > 0.0f) {
fabY = Mathf.Min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0f);
}
return new Offset(fabX, fabY);
}
}
class _EndFloatFabLocation : FloatingActionButtonLocation {
public _EndFloatFabLocation() {
}
public override Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
float endPadding = scaffoldGeometry.minInsets.right;
float fabX = scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width -
FloatingActionButtonLocationUtils.kFloatingActionButtonMargin - endPadding;
float contentBottom = scaffoldGeometry.contentBottom;
float bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height;
float fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
float snackBarHeight = scaffoldGeometry.snackBarSize.height;
float fabY = contentBottom - fabHeight - FloatingActionButtonLocationUtils.kFloatingActionButtonMargin;
if (snackBarHeight > 0.0f) {
fabY = Mathf.Min(fabY,
contentBottom - snackBarHeight - fabHeight -
FloatingActionButtonLocationUtils.kFloatingActionButtonMargin);
}
if (bottomSheetHeight > 0.0f) {
fabY = Mathf.Min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0f);
}
return new Offset(fabX, fabY);
}
}
abstract class _DockedFloatingActionButtonLocation : FloatingActionButtonLocation {
protected _DockedFloatingActionButtonLocation() {
}
protected float getDockedY(ScaffoldPrelayoutGeometry scaffoldGeometry) {
float contentBottom = scaffoldGeometry.contentBottom;
float bottomSheetHeight = scaffoldGeometry.bottomSheetSize.height;
float fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
float snackBarHeight = scaffoldGeometry.snackBarSize.height;
float fabY = contentBottom - fabHeight / 2.0f;
if (snackBarHeight > 0.0f) {
fabY = Mathf.Min(fabY,
contentBottom - snackBarHeight - fabHeight -
FloatingActionButtonLocationUtils.kFloatingActionButtonMargin);
}
if (bottomSheetHeight > 0.0f) {
fabY = Mathf.Min(fabY, contentBottom - bottomSheetHeight - fabHeight / 2.0f);
}
float maxFabY = scaffoldGeometry.scaffoldSize.height - fabHeight;
return Mathf.Min(maxFabY, fabY);
}
}
class _EndDockedFloatingActionButtonLocation : _DockedFloatingActionButtonLocation {
public _EndDockedFloatingActionButtonLocation() {
}
public override Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
float endPadding = scaffoldGeometry.minInsets.right;
float fabX = scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width -
FloatingActionButtonLocationUtils.kFloatingActionButtonMargin - endPadding;
return new Offset(fabX, this.getDockedY(scaffoldGeometry));
}
}
class _CenterDockedFloatingActionButtonLocation : _DockedFloatingActionButtonLocation {
public _CenterDockedFloatingActionButtonLocation() {
}
public override Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
float fabX = (scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width) / 2.0f;
return new Offset(fabX, this.getDockedY(scaffoldGeometry));
}
}
public abstract class FloatingActionButtonAnimator {
protected FloatingActionButtonAnimator() {
}
public static readonly FloatingActionButtonAnimator scaling = new _ScalingFabMotionAnimator();
public abstract Offset getOffset(Offset begin, Offset end, float progress);
public abstract Animation<float> getScaleAnimation(Animation<float> parent);
public abstract Animation<float> getRotationAnimation(Animation<float> parent);
public virtual float getAnimationRestart(float previousValue) {
return 0.0f;
}
public override string ToString() {
return this.GetType().ToString();
}
}
class _ScalingFabMotionAnimator : FloatingActionButtonAnimator {
public _ScalingFabMotionAnimator() {
}
public override Offset getOffset(Offset begin, Offset end, float progress) {
if (progress < 0.5f) {
return begin;
}
else {
return end;
}
}
public override Animation<float> getScaleAnimation(Animation<float> parent) {
Curve curve = new Interval(0.5f, 1.0f, curve: Curves.ease);
return new _AnimationSwap<float>(
new ReverseAnimation(parent.drive(new CurveTween(curve: curve.flipped))),
parent.drive(new CurveTween(curve: curve)),
parent,
0.5f
);
}
static readonly Animatable<float> _rotationTween = new FloatTween(
begin: 1.0f - FloatingActionButtonLocationUtils.kFloatingActionButtonTurnInterval * 2.0f,
end: 1.0f
);
static readonly Animatable<float> _thresholdCenterTween = new CurveTween(curve: new Threshold(0.5f));
public override Animation<float> getRotationAnimation(Animation<float> parent) {
return new _AnimationSwap<float>(
parent.drive(_rotationTween),
new ReverseAnimation(parent.drive(_thresholdCenterTween)),
parent,
0.5f
);
}
public override float getAnimationRestart(float previousValue) {
return Mathf.Min(1.0f - previousValue, previousValue);
}
}
class _AnimationSwap<T> : CompoundAnimation<T> {
public _AnimationSwap(
Animation<T> first,
Animation<T> next,
Animation<float> parent,
float swapThreshold
) : base(first: first, next: next) {
this.parent = parent;
this.swapThreshold = swapThreshold;
}
public readonly Animation<float> parent;
public readonly float swapThreshold;
public override T value {
get { return this.parent.value < this.swapThreshold ? this.first.value : this.next.value; }
}
}
}

11
Runtime/material/float_action_button_location.cs.meta


fileFormatVersion: 2
guid: cfa1c894caa2a46b19d419f6f53ae91f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Runtime/material/scaffold.cs
文件差异内容过多而无法显示
查看文件

11
Runtime/material/scaffold.cs.meta


fileFormatVersion: 2
guid: 2ed8ea3a4f90842e7884a5aff0ca6ec3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

220
Runtime/material/snack_bar.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class SnackBarUtils {
public const float _kSnackBarPadding = 24.0f;
public const float _kSingleLineVerticalPadding = 14.0f;
public static readonly Color _kSnackBackground = new Color(0xFF323232);
public static readonly TimeSpan _kSnackBarTransitionDuration = new TimeSpan(0, 0, 0, 0, 250);
public static readonly TimeSpan _kSnackBarDisplayDuration = new TimeSpan(0, 0, 0, 0, 4000);
public static readonly Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
public static readonly Curve _snackBarFadeCurve = new Interval(0.72f, 1.0f, curve: Curves.fastOutSlowIn);
}
public enum SnackBarClosedReason {
action,
dismiss,
swipe,
hide,
remove,
timeout
}
public class SnackBarAction : StatefulWidget {
public SnackBarAction(
Key key = null,
Color textColor = null,
Color disabledTextColor = null,
string label = null,
VoidCallback onPressed = null
) : base(key: key) {
D.assert(label != null);
D.assert(onPressed != null);
this.textColor = textColor;
this.disabledTextColor = disabledTextColor;
this.label = label;
this.onPressed = onPressed;
}
public readonly Color textColor;
public readonly Color disabledTextColor;
public readonly string label;
public readonly VoidCallback onPressed;
public override State createState() {
return new _SnackBarActionState();
}
}
class _SnackBarActionState : State<SnackBarAction> {
bool _haveTriggeredAction = false;
void _handlePressed() {
if (this._haveTriggeredAction) {
return;
}
this.setState(() => { this._haveTriggeredAction = true; });
this.widget.onPressed();
Scaffold.of(this.context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
}
public override Widget build(BuildContext context) {
return new FlatButton(
onPressed: this._haveTriggeredAction ? (VoidCallback) null : this._handlePressed,
child: new Text(this.widget.label),
textColor: this.widget.textColor,
disabledTextColor: this.widget.disabledTextColor
);
}
}
public class SnackBar : StatelessWidget {
public SnackBar(
Key key = null,
Widget content = null,
Color backgroundColor = null,
SnackBarAction action = null,
TimeSpan? duration = null,
Animation<float> animation = null
) : base(key: key) {
duration = duration ?? SnackBarUtils._kSnackBarDisplayDuration;
D.assert(content != null);
this.content = content;
this.backgroundColor = backgroundColor;
this.action = action;
this.duration = duration.Value;
this.animation = animation;
}
public readonly Widget content;
public readonly Color backgroundColor;
public readonly SnackBarAction action;
public readonly TimeSpan duration;
public readonly Animation<float> animation;
public override Widget build(BuildContext context) {
MediaQueryData mediaQueryData = MediaQuery.of(context);
D.assert(this.animation != null);
ThemeData theme = Theme.of(context);
ThemeData darkTheme = new ThemeData(
brightness: Brightness.dark,
accentColor: theme.accentColor,
accentColorBrightness: theme.accentColorBrightness
);
List<Widget> children = new List<Widget> {
new SizedBox(width: SnackBarUtils._kSnackBarPadding),
new Expanded(
child: new Container(
padding: EdgeInsets.symmetric(vertical: SnackBarUtils._kSingleLineVerticalPadding),
child: new DefaultTextStyle(
style: darkTheme.textTheme.subhead,
child: this.content)
)
)
};
if (this.action != null) {
children.Add(ButtonTheme.bar(
padding: EdgeInsets.symmetric(horizontal: SnackBarUtils._kSnackBarPadding),
textTheme: ButtonTextTheme.accent,
child: this.action
));
}
else {
children.Add(new SizedBox(width: SnackBarUtils._kSnackBarPadding));
}
CurvedAnimation heightAnimation =
new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarHeightCurve);
CurvedAnimation fadeAnimation = new CurvedAnimation(parent: this.animation,
curve: SnackBarUtils._snackBarFadeCurve, reverseCurve: new Threshold(0.0f));
Widget snackbar = new SafeArea(
top: false,
child: new Row(
children: children,
crossAxisAlignment: CrossAxisAlignment.center
)
);
snackbar = new Dismissible(
key: Key.key("dismissible"),
direction: DismissDirection.down,
resizeDuration: null,
onDismissed: (DismissDirection? direction) => {
Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
},
child: new Material(
elevation: 6.0f,
color: this.backgroundColor ?? SnackBarUtils._kSnackBackground,
child: new Theme(
data: darkTheme,
child: mediaQueryData.accessibleNavigation
? snackbar
: new FadeTransition(
opacity: fadeAnimation,
child: snackbar
)
)
)
);
return new ClipRect(
child: mediaQueryData.accessibleNavigation
? snackbar
: new AnimatedBuilder(
animation: heightAnimation,
builder: (BuildContext subContext, Widget child) => {
return new Align(
alignment: Alignment.topLeft,
heightFactor: heightAnimation.value,
child: child
);
},
child: snackbar
)
);
}
public static AnimationController createAnimationController(TickerProvider vsync) {
return new AnimationController(
duration: SnackBarUtils._kSnackBarTransitionDuration,
debugLabel: "SnackBar",
vsync: vsync
);
}
public SnackBar withAnimation(Animation<float> newAnimation, Key fallbackKey = null) {
return new SnackBar(
key: this.key ?? fallbackKey,
content: this.content,
backgroundColor: this.backgroundColor,
action: this.action,
duration: this.duration,
animation: newAnimation
);
}
}
}

11
Runtime/material/snack_bar.cs.meta


fileFormatVersion: 2
guid: f7d31af27df5e4deea4b02f89109f9fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

33
Runtime/widgets/annotated_region.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
namespace Unity.UIWidgets.widgets {
public class AnnotatedRegion<T> : SingleChildRenderObjectWidget
where T : class {
public AnnotatedRegion(
Key key = null,
Widget child = null,
T value = null,
bool sized = true
) : base(key: key, child: child) {
D.assert(value != null);
D.assert(child != null);
this.value = value;
this.sized = sized;
}
public readonly T value;
public readonly bool sized;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderAnnotatedRegion<T>(value: this.value, sized: this.sized);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
RenderAnnotatedRegion<T> _renderObject = (RenderAnnotatedRegion<T>) renderObject;
_renderObject.value = this.value;
_renderObject.sized = this.sized;
}
}
}

11
Runtime/widgets/annotated_region.cs.meta


fileFormatVersion: 2
guid: b7edf2448377d4d3b9b9f63eb136266b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

36
Runtime/widgets/perferred_size.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.widgets {
public interface SizePreferred {
Size preferredSize { get; }
}
public abstract class PreferredSizeWidget : StatefulWidget, SizePreferred {
protected PreferredSizeWidget(Key key = null) : base(key: key) {
}
public virtual Size preferredSize { get; }
}
public class PreferredSize : StatelessWidget, SizePreferred {
public PreferredSize(
Key key = null,
Widget child = null,
Size preferredSize = null) : base(key: key) {
D.assert(child != null);
D.assert(preferredSize != null);
this.child = child;
this.preferredSize = preferredSize;
}
public readonly Widget child;
public Size preferredSize { get; }
public override Widget build(BuildContext context) {
return this.child;
}
}
}

11
Runtime/widgets/perferred_size.cs.meta


fileFormatVersion: 2
guid: 60513bb9173ce47ad8d4c7840bcfe836
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存