浏览代码

Merge branch 'gallery' into 'master'

Gallery

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!137
/main
Xingwei Zhu 6 年前
当前提交
fc08aae4
共有 55 个文件被更改,包括 5949 次插入176 次删除
  1. 4
      Runtime/foundation/node.mixin.gen.cs
  2. 3
      Runtime/material/button.cs
  3. 14
      Runtime/material/button_theme.cs
  4. 2
      Runtime/material/list_tile.cs
  5. 3
      Runtime/material/outline_button.cs
  6. 2
      Runtime/material/tab_controller.cs
  7. 3
      Runtime/material/tabs.cs
  8. 23
      Runtime/rendering/stack.cs
  9. 11
      Runtime/widgets/transitions.cs
  10. 11
      Samples/UIWidgetsGallery/gallery/app.cs
  11. 32
      Samples/UIWidgetsGallery/gallery/demos.cs
  12. 262
      Samples/UIWidgetsGallery/gallery/home.cs
  13. 8
      Runtime/material/animated_icons.meta
  14. 241
      Runtime/widgets/animated_switcher.cs
  15. 11
      Runtime/widgets/animated_switcher.cs.meta
  16. 239
      Runtime/widgets/banner.cs
  17. 3
      Runtime/widgets/banner.cs.meta
  18. 91
      Runtime/widgets/visibility.cs
  19. 3
      Runtime/widgets/visibility.cs.meta
  20. 20
      Samples/UIWidgetsGallery/GalleryMain.cs
  21. 8
      Samples/UIWidgetsGallery/demo.meta
  22. 365
      Samples/UIWidgetsGallery/gallery/backdrop.cs
  23. 3
      Samples/UIWidgetsGallery/gallery/backdrop.cs.meta
  24. 215
      Samples/UIWidgetsGallery/gallery/demo.cs
  25. 3
      Samples/UIWidgetsGallery/gallery/demo.cs.meta
  26. 53
      Samples/UIWidgetsGallery/gallery/example_code_parser.cs
  27. 3
      Samples/UIWidgetsGallery/gallery/example_code_parser.cs.meta
  28. 427
      Samples/UIWidgetsGallery/gallery/syntax_highlighter.cs
  29. 3
      Samples/UIWidgetsGallery/gallery/syntax_highlighter.cs.meta
  30. 14
      Tests/Resources/GalleryIcons.ttf
  31. 22
      Tests/Resources/GalleryIcons.ttf.meta
  32. 25
      Tests/Resources/unity.png
  33. 88
      Tests/Resources/unity.png.meta
  34. 11
      Runtime/material/animated_icons/animated_icons.cs.meta
  35. 3
      Runtime/material/animated_icons/animated_icons_data.cs.meta
  36. 8
      Runtime/material/animated_icons/data.meta
  37. 1001
      Runtime/material/animated_icons/data/add_event.g.cs
  38. 11
      Runtime/material/animated_icons/data/add_event.g.cs.meta
  39. 1001
      Runtime/material/animated_icons/data/arrow_menu.g.cs
  40. 3
      Runtime/material/animated_icons/data/arrow_menu.g.cs.meta
  41. 1001
      Runtime/material/animated_icons/data/close_menu.g.cs
  42. 3
      Runtime/material/animated_icons/data/close_menu.g.cs.meta
  43. 223
      Runtime/material/animated_icons/animated_icons.cs
  44. 54
      Runtime/material/animated_icons/animated_icons_data.cs
  45. 8
      Samples/UIWidgetsGallery/demo/material.meta
  46. 11
      Samples/UIWidgetsGallery/demo/material/buttons_demo.cs.meta
  47. 382
      Samples/UIWidgetsGallery/demo/material/buttons_demo.cs
  48. 172
      Samples/UIWidgetsGallery/demo/colors_demo.cs
  49. 11
      Samples/UIWidgetsGallery/demo/colors_demo.cs.meta
  50. 7
      Samples/UIWidgetsGallery/main.cs
  51. 0
      /Samples/UIWidgetsGallery/GalleryMain.cs.meta

4
Runtime/foundation/node.mixin.gen.cs


static readonly Dictionary<_DependencyList, WeakReference> _canonicalObjects =
new Dictionary<_DependencyList, WeakReference>();
public bool alwaysUpdate { get; set; } // if canonicalEquals should not be used.
public bool alwaysUpdate { get; set; } = true; // if canonicalEquals should not be used.
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {

3
Runtime/material/button.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;

onHighlightChanged: this._handleHighlightChanged,
splashColor: this.widget.splashColor,
highlightColor: this.widget.highlightColor,
onTap: () => {
onTap: this.widget.onPressed == null ? (GestureTapCallback) null : () => {
if (this.widget.onPressed != null) {
this.widget.onPressed();
}

14
Runtime/material/button_theme.cs


return fillColor;
}
//todo:xingwei.zhu: uncomment these when OutlineButton are ready
if (button is FlatButton /* || button is OutlineButton*/) {
if (button is FlatButton || button is OutlineButton) {
return null;
}

return Colors.white;
}
//todo:xingwei.zhu: uncomment these when OutlineButton are ready
if (button is FlatButton /* || button is OutlineButton*/) {
if (button is FlatButton || button is OutlineButton) {
return this.colorScheme.primary;
}

return button.splashColor;
}
//todo:xingwei.zhu: uncomment these when OutlineButton is ready
if (this._splashColor != null && (button is RaisedButton /* || button is OutlineButton*/)) {
if (this._splashColor != null && (button is RaisedButton || button is OutlineButton)) {
return this._splashColor;
}

return 0.0f;
}
//todo:xingwei.zhu: uncomment these when OutlineButton are ready
// if (button is OutlineButton)
// return 2.0;
if (button is OutlineButton)
return 2.0f;
return 8.0f;
}

2
Runtime/material/list_tile.cs


}
void _updateChild(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.childToSlot.Remove(oldChild);

3
Runtime/material/outline_button.cs


child: child
) {
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(onPressed != null);
this.highlightedBorderColor = highlightedBorderColor;
this.disabledBorderColor = disabledBorderColor;
this.borderSide = borderSide;

}
)
) {
D.assert(onPressed != null);
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(icon != null);
D.assert(label != null);

) : base(key: key) {
D.assert(highlightElevation != null && highlightElevation >= 0.0f);
D.assert(highlightedBorderColor != null);
D.assert(this.onPressed != null);
this.onPressed = onPressed;
this.brightness = brightness;
this.textTheme = textTheme;

2
Runtime/material/tab_controller.cs


}
}
class DefaultTabController : StatefulWidget {
public class DefaultTabController : StatefulWidget {
public DefaultTabController(
Key key = null,
int? length = null,

3
Runtime/material/tabs.cs


int tabCount = this.widget.tabs.Count;
for (int index = 0; index < tabCount; index++) {
int tabIndex = index;
onTap: () => { this._handleTap(index); },
onTap: () => { this._handleTap(tabIndex); },
child: new Padding(
padding: EdgeInsets.only(bottom: this.widget.indicatorWeight),
child: wrappedTabs[index]

23
Runtime/rendering/stack.cs


container.height - this.bottom);
}
public static RelativeRect lerp(RelativeRect a, RelativeRect b, float t) {
D.assert(t != null);
if (a == null && b == null) {
return null;
}
if (a == null) {
return fromLTRB(b.left * t, b.top * t, b.right * t, b.bottom * t);
}
if (b == null) {
float k = 1.0f - t;
return fromLTRB(b.left * k, b.top * k, b.right * k, b.bottom * k);
}
return fromLTRB(
MathUtils.lerpFloat(a.left, b.left, t),
MathUtils.lerpFloat(a.top, b.top, t),
MathUtils.lerpFloat(a.right, b.right, t),
MathUtils.lerpFloat(a.bottom, b.bottom, t)
);
}
public bool Equals(RelativeRect other) {
if (ReferenceEquals(null, other)) {
return false;

11
Runtime/widgets/transitions.cs


}
}
public class RelativeRectTween : Tween<RelativeRect> {
public RelativeRectTween(RelativeRect begin = null, RelativeRect end = null) : base(begin: begin, end: end) {
}
public override RelativeRect lerp(float t) {
return RelativeRect.lerp(this.begin, this.end, t);
}
}
public class PositionedTransition : AnimatedWidget {
public PositionedTransition(

D.assert(rect != null);
D.assert(size != null);
D.assert(child != null);
this.size = size;
this.child = child;
}
Animation<Rect> rect {

11
Samples/UIWidgetsGallery/gallery/app.cs


VoidCallback onSendFeedback = null,
bool testMode = false
) : base(key: key) {
this.updateUrlFetcher = updateUrlFetcher;
this.enablePerformanceOverlay = enablePerformanceOverlay;
this.enableRasterCacheImagesCheckerboard = enableRasterCacheImagesCheckerboard;
this.enableOffscreenLayersCheckerboard = enableOffscreenLayersCheckerboard;
this.onSendFeedback = onSendFeedback;
this.testMode = testMode;
}
public readonly UpdateUrlFetcher updateUrlFetcher;

if (this._options.timeDilation != newOptions.timeDilation) {
this._timeDilationTimer?.cancel();
this._timeDilationTimer = null;
if (newOptions.timeDilation > 1.0) {
// We delay the time dilation change long enough that the user can see
// that UI has started reacting and then we slam on the brakes so that
// they see that the time is in fact now dilated.
if (newOptions.timeDilation > 1.0f) {
this._timeDilationTimer = Window.instance.run(new TimeSpan(0, 0, 0, 0, 150),
() => { SchedulerBinding.instance.timeDilation = newOptions.timeDilation; });
} else {

32
Samples/UIWidgetsGallery/gallery/demos.cs


// ),
//
// // Style
// new GalleryDemo(
// title: "Colors",
// subtitle: "All of the predefined colors",
// icon: GalleryIcons.colors,
// category: GalleryDemoCategory._kStyle,
// routeName: ColorsDemo.routeName,
// buildRoute: (BuildContext context) => ColorsDemo()
// ),
new GalleryDemo(
title: "Colors",
subtitle: "All of the predefined colors",
icon: GalleryIcons.colors,
category: DemoUtils._kStyle,
routeName: ColorsDemo.routeName,
buildRoute: (BuildContext context) => new ColorsDemo()
),
// new GalleryDemo(
// title: "Typography",
// subtitle: "All of the predefined text styles",

// documentationUrl: "https://docs.flutter.io/flutter/material/ScaffoldState/showBottomSheet.html",
// buildRoute: (BuildContext context) => PersistentBottomSheetDemo()
// ),
// new GalleryDemo(
// title: "Buttons",
// subtitle: "Flat, raised, dropdown, and more",
// icon: GalleryIcons.generic_buttons,
// category: GalleryDemoCategory._kMaterialComponents,
// routeName: ButtonsDemo.routeName,
// buildRoute: (BuildContext context) => ButtonsDemo()
// ),
new GalleryDemo(
title: "Buttons",
subtitle: "Flat, raised, dropdown, and more",
icon: GalleryIcons.generic_buttons,
category: DemoUtils._kMaterialComponents,
routeName: ButtonsDemo.routeName,
buildRoute: (BuildContext context) => new ButtonsDemo()
),
// new GalleryDemo(
// title: "Buttons: Floating Action Button",
// subtitle: "FAB with transitions",

262
Samples/UIWidgetsGallery/gallery/home.cs


decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage(
"logos/unity.png")
"unity")
)
)
)

public static bool showPreviewBanner = true;
public override State createState() {
// return new _GalleryHomeState();
return null;
return new _GalleryHomeState();
// class _GalleryHomeState : SingleTickerProviderStateMixin<GalleryHome> {
// static readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
// AnimationController _controller;
// GalleryDemoCategory _category;
//
// static Widget _topHomeLayout(Widget currentChild, List<Widget> previousChildren) {
// List<Widget> children = previousChildren;
// if (currentChild != null) {
// children = children.ToList();
// children.Add(currentChild);
// }
//
// return new Stack(
// children: children,
// alignment: Alignment.topCenter
// );
// }
//
// static const AnimatedSwitcherLayoutBuilder _centerHomeLayout = AnimatedSwitcher.defaultLayoutBuilder;
//
// public override void initState() {
// base.initState();
// this._controller = new AnimationController(
// duration: new TimeSpan(0, 0, 0, 0, 600),
// debugLabel: "preview banner",
// vsync: this
// );
// this._controller.forward();
// }
//
// public override void dispose() {
// this._controller.dispose();
// base.dispose();
// }
//
// public override Widget build(BuildContext context) {
// ThemeData theme = Theme.of(context);
// bool isDark = theme.brightness == Brightness.dark;
// MediaQueryData media = MediaQuery.of(context);
// bool centerHome = media.orientation == Orientation.portrait && media.size.height < 800.0;
//
// Curve switchOutCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
// Curve switchInCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
//
// Widget home = new Scaffold(
// key: _scaffoldKey,
// backgroundColor: isDark ? HomeUtils._kUIWidgetsBlue : theme.primaryColor,
// body: new SafeArea(
// bottom: false,
// child: new WillPopScope(
// onWillPop: () => {
// // Pop the category page if Android back button is pressed.
// if (this._category != null) {
// this.setState(() => this._category = null);
// return Promise<bool>.Resolved(false);
// }
// return Promise<bool>.Resolved(true);
// },
// child: new Backdrop(
// backTitle: new Text("Options"),
// backLayer: this.widget.optionsPage,
// frontAction: new AnimatedSwitcher(
// duration: HomeUtils._kFrontLayerSwitchDuration,
// switchOutCurve: switchOutCurve,
// switchInCurve: switchInCurve,
// child: this._category == null
// ? new _UIWidgetsLogo()
// : new IconButton(
// icon: new BackButtonIcon(),
// tooltip: "Back",
// onPressed: () => this.setState(() => this._category = null)
// )
// ),
// frontTitle: new AnimatedSwitcher(
// duration: HomeUtils._kFrontLayerSwitchDuration,
// child: this._category == null
// ? new Text("Flutter gallery")
// : new Text(this._category.name)
// ),
// frontHeading: this.widget.testMode ? null : new Container(height: 24.0f),
// frontLayer: new AnimatedSwitcher(
// duration: HomeUtils._kFrontLayerSwitchDuration,
// switchOutCurve: switchOutCurve,
// switchInCurve: switchInCurve,
// layoutBuilder: centerHome ? _centerHomeLayout : _topHomeLayout,
// child: this._category != null
// ? new _DemosPage(_category)
// : new _CategoriesPage(
// categories: DemoUtils.kAllGalleryDemoCategories,
// onCategoryTap: (GalleryDemoCategory category) => {
// this.setState(() => this._category = category);
// }
// )
// )
// )
// )
// )
// );
//
// D.assert(() => {
// GalleryHome.showPreviewBanner = false;
// return true;
// });
//
// if (GalleryHome.showPreviewBanner) {
// home = new Stack(
// fit: StackFit.expand,
// children: new List<Widget> {
// home,
// new FadeTransition(
// opacity: new CurvedAnimation(parent: this._controller, curve: Curves.easeInOut),
// child: new Banner(
// message: "PREVIEW",
// location: BannerLocation.topEnd
// )
// )
// }
// );
// }
// home = new AnnotatedRegion<SystemUiOverlayStyle>(
// child: home,
// value: SystemUiOverlayStyle.light
// );
//
// return home;
// }
// }
}
class _GalleryHomeState : SingleTickerProviderStateMixin<GalleryHome> {
readonly GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>.key();
AnimationController _controller;
GalleryDemoCategory _category;
static Widget _topHomeLayout(Widget currentChild, List<Widget> previousChildren) {
List<Widget> children = previousChildren;
if (currentChild != null) {
children = children.ToList();
children.Add(currentChild);
}
return new Stack(
children: children,
alignment: Alignment.topCenter
);
}
public static AnimatedSwitcherLayoutBuilder _centerHomeLayout = AnimatedSwitcher.defaultLayoutBuilder;
public override void initState() {
base.initState();
this._controller = new AnimationController(
duration: new TimeSpan(0, 0, 0, 0, 600),
debugLabel: "preview banner",
vsync: this
);
this._controller.forward();
}
public override void dispose() {
this._controller.dispose();
base.dispose();
}
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
bool isDark = theme.brightness == Brightness.dark;
MediaQueryData media = MediaQuery.of(context);
bool centerHome = media.orientation == Orientation.portrait && media.size.height < 800.0;
Curve switchOutCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
Curve switchInCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
Widget home = new Scaffold(
key: this._scaffoldKey,
backgroundColor: isDark ? HomeUtils._kUIWidgetsBlue : theme.primaryColor,
body: new SafeArea(
bottom: false,
child: new WillPopScope(
onWillPop: () => {
if (this._category != null) {
this.setState(() => this._category = null);
return Promise<bool>.Resolved(false);
}
return Promise<bool>.Resolved(true);
},
child: new Backdrop(
backTitle: new Text("Options"),
backLayer: this.widget.optionsPage,
frontAction: new AnimatedSwitcher(
duration: HomeUtils._kFrontLayerSwitchDuration,
switchOutCurve: switchOutCurve,
switchInCurve: switchInCurve,
child: this._category == null
? (Widget) new _UIWidgetsLogo()
: new IconButton(
icon: new BackButtonIcon(),
tooltip: "Back",
onPressed: () => this.setState(() => this._category = null)
)
),
frontTitle: new AnimatedSwitcher(
duration: HomeUtils._kFrontLayerSwitchDuration,
child: this._category == null
? new Text("UIWidgets gallery")
: new Text(this._category.name)
),
frontHeading: this.widget.testMode ? null : new Container(height: 24.0f),
frontLayer: new AnimatedSwitcher(
duration: HomeUtils._kFrontLayerSwitchDuration,
switchOutCurve: switchOutCurve,
switchInCurve: switchInCurve,
layoutBuilder: centerHome ? _centerHomeLayout : _topHomeLayout,
child: this._category != null
? (Widget) new _DemosPage(this._category)
: new _CategoriesPage(
categories: DemoUtils.kAllGalleryDemoCategories,
onCategoryTap: (GalleryDemoCategory category) => {
this.setState(() => this._category = category);
}
)
)
)
)
)
);
D.assert(() => {
GalleryHome.showPreviewBanner = false;
return true;
});
if (GalleryHome.showPreviewBanner) {
home = new Stack(
fit: StackFit.expand,
children: new List<Widget> {
home,
new FadeTransition(
opacity: new CurvedAnimation(parent: this._controller, curve: Curves.easeInOut),
child: new Banner(
message: "PREVIEW",
location: BannerLocation.topEnd
)
)
}
);
}
home = new AnnotatedRegion<SystemUiOverlayStyle>(
child: home,
value: SystemUiOverlayStyle.light
);
return home;
}
}
}

8
Runtime/material/animated_icons.meta


fileFormatVersion: 2
guid: fe9d2309a41964cba855171391dab665
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

241
Runtime/widgets/animated_switcher.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RSG.Promises;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
namespace Unity.UIWidgets.widgets {
class _ChildEntry {
public _ChildEntry(
AnimationController controller,
Animation<float> animation,
Widget transition,
Widget widgetChild
) {
D.assert(animation != null);
D.assert(transition != null);
D.assert(controller != null);
this.controller = controller;
this.animation = animation;
this.transition = transition;
this.widgetChild = widgetChild;
}
public readonly AnimationController controller;
public readonly Animation<float> animation;
public Widget transition;
public Widget widgetChild;
public override string ToString() {
return "Entry#${shortHash(this)}($widgetChild)";
}
}
public delegate Widget AnimatedSwitcherTransitionBuilder(Widget child, Animation<float> animation);
public delegate Widget AnimatedSwitcherLayoutBuilder(Widget currentChild, List<Widget> previousChildren);
public class AnimatedSwitcher : StatefulWidget {
public AnimatedSwitcher(
Key key = null,
Widget child = null,
TimeSpan? duration = null,
Curve switchInCurve = null,
Curve switchOutCurve = null,
AnimatedSwitcherTransitionBuilder transitionBuilder = null,
AnimatedSwitcherLayoutBuilder layoutBuilder = null
) : base(key: key) {
D.assert(duration != null);
this.switchInCurve = switchInCurve ?? Curves.linear;
this.switchOutCurve = switchOutCurve ?? Curves.linear;
this.transitionBuilder = transitionBuilder ?? defaultTransitionBuilder;
this.layoutBuilder = layoutBuilder ?? defaultLayoutBuilder;
this.child = child;
this.duration = duration;
}
public readonly Widget child;
public readonly TimeSpan? duration;
public readonly Curve switchInCurve;
public readonly Curve switchOutCurve;
public readonly AnimatedSwitcherTransitionBuilder transitionBuilder;
public readonly AnimatedSwitcherLayoutBuilder layoutBuilder;
public override State createState() {
return new _AnimatedSwitcherState();
}
public static Widget defaultTransitionBuilder(Widget child, Animation<float> animation) {
return new FadeTransition(
opacity: animation,
child: child
);
}
public static Widget defaultLayoutBuilder(Widget currentChild, List<Widget> previousChildren) {
List<Widget> children = previousChildren;
if (currentChild != null) {
children = children.ToList();
children.Add(currentChild);
}
return new Stack(
children: children,
alignment: Alignment.center
);
}
}
class _AnimatedSwitcherState : TickerProviderStateMixin<AnimatedSwitcher> {
_ChildEntry _currentEntry;
HashSet<_ChildEntry> _outgoingEntries = new HashSet<_ChildEntry>();
List<Widget> _outgoingWidgets = new List<Widget>();
int _childNumber = 0;
public override void initState() {
base.initState();
this._addEntryForNewChild(animate: false);
}
public override void didUpdateWidget(StatefulWidget _oldWidget) {
base.didUpdateWidget(_oldWidget);
AnimatedSwitcher oldWidget = _oldWidget as AnimatedSwitcher;
if (this.widget.transitionBuilder != oldWidget.transitionBuilder) {
this._outgoingEntries.Each(this._updateTransitionForEntry);
if (this._currentEntry != null) {
this._updateTransitionForEntry(this._currentEntry);
}
this._markChildWidgetCacheAsDirty();
}
bool hasNewChild = this.widget.child != null;
bool hasOldChild = this._currentEntry != null;
if (hasNewChild != hasOldChild ||
hasNewChild && !Widget.canUpdate(this.widget.child, this._currentEntry.widgetChild)) {
this._childNumber += 1;
this._addEntryForNewChild(animate: true);
}
else if (this._currentEntry != null) {
D.assert(hasOldChild && hasNewChild);
D.assert(Widget.canUpdate(this.widget.child, this._currentEntry.widgetChild));
this._currentEntry.widgetChild = this.widget.child;
this._updateTransitionForEntry(this._currentEntry);
this._markChildWidgetCacheAsDirty();
}
}
void _addEntryForNewChild(bool animate) {
D.assert(animate || this._currentEntry == null);
if (this._currentEntry != null) {
D.assert(animate);
D.assert(!this._outgoingEntries.Contains(this._currentEntry));
this._outgoingEntries.Add(this._currentEntry);
this._currentEntry.controller.reverse();
this._markChildWidgetCacheAsDirty();
this._currentEntry = null;
}
if (this.widget.child == null) {
return;
}
AnimationController controller = new AnimationController(
duration: this.widget.duration,
vsync: this
);
Animation<float> animation = new CurvedAnimation(
parent: controller,
curve: this.widget.switchInCurve,
reverseCurve: this.widget.switchOutCurve
);
this._currentEntry = this._newEntry(
child: this.widget.child,
controller: controller,
animation: animation,
builder: this.widget.transitionBuilder
);
if (animate) {
controller.forward();
}
else {
D.assert(this._outgoingEntries.isEmpty);
controller.setValue(1.0f);
}
}
_ChildEntry _newEntry(
Widget child,
AnimatedSwitcherTransitionBuilder builder,
AnimationController controller,
Animation<float> animation
) {
_ChildEntry entry = new _ChildEntry(
widgetChild: child,
transition: KeyedSubtree.wrap(builder(child, animation), this._childNumber),
animation: animation,
controller: controller
);
animation.addStatusListener((AnimationStatus status) => {
if (status == AnimationStatus.dismissed) {
this.setState(() => {
D.assert(this.mounted);
D.assert(this._outgoingEntries.Contains(entry));
this._outgoingEntries.Remove(entry);
this._markChildWidgetCacheAsDirty();
});
controller.dispose();
}
});
return entry;
}
void _markChildWidgetCacheAsDirty() {
this._outgoingWidgets = null;
}
void _updateTransitionForEntry(_ChildEntry entry) {
entry.transition = new KeyedSubtree(
key: entry.transition.key,
child: this.widget.transitionBuilder(entry.widgetChild, entry.animation)
);
}
void _rebuildOutgoingWidgetsIfNeeded() {
this._outgoingWidgets = this._outgoingWidgets ?? new List<Widget>(
this._outgoingEntries.Select((_ChildEntry entry) => entry.transition)
);
D.assert(this._outgoingEntries.Count == this._outgoingWidgets.Count);
D.assert(this._outgoingEntries.isEmpty() ||
this._outgoingEntries.Last().transition == this._outgoingWidgets.Last());
}
public override void dispose() {
if (this._currentEntry != null) {
this._currentEntry.controller.dispose();
}
foreach (_ChildEntry entry in this._outgoingEntries) {
entry.controller.dispose();
}
base.dispose();
}
public override Widget build(BuildContext context) {
this._rebuildOutgoingWidgetsIfNeeded();
return this.widget.layoutBuilder(this._currentEntry?.transition, this._outgoingWidgets);
}
}
}

11
Runtime/widgets/animated_switcher.cs.meta


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

239
Runtime/widgets/banner.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.widgets {
class BannerConstants {
public const float _kOffset = 40.0f;
public const float _kHeight = 12.0f;
public const float _kBottomOffset = _kOffset + 0.707f * _kHeight;
public static readonly Rect _kRect = Rect.fromLTWH(-_kOffset, _kOffset - _kHeight, _kOffset * 2.0f, _kHeight);
public static readonly Color _kColor = new Color(0xA0B71C1C);
public static readonly TextStyle _kTextStyle = new TextStyle(
color: new Color(0xFFFFFFFF),
fontSize: _kHeight * 0.85f,
fontWeight: FontWeight.w700,
height: 1.0f
);
}
public enum BannerLocation {
topStart,
topEnd,
bottomStart,
bottomEnd,
}
public class BannerPainter : AbstractCustomPainter {
public BannerPainter(
string message,
BannerLocation? location,
Color color = null,
TextStyle textStyle = null
) {
D.assert(message != null);
D.assert(location != null);
this.color = color ?? BannerConstants._kColor;
this.message = message;
this.location = location;
this.textStyle = textStyle ?? BannerConstants._kTextStyle;
}
public readonly string message;
public readonly BannerLocation? location;
public readonly Color color;
public readonly TextStyle textStyle;
readonly BoxShadow _shadow = new BoxShadow(
color: new Color(0x7F000000),
blurRadius: 6.0f
);
bool _prepared = false;
TextPainter _textPainter;
Paint _paintShadow;
Paint _paintBanner;
void _prepare() {
this._paintShadow = this._shadow.toPaint();
this._paintBanner = new Paint();
this._paintBanner.color = this.color;
this._textPainter = new TextPainter(
text: new TextSpan(style: this.textStyle, text: this.message),
textAlign: TextAlign.center
);
this._prepared = true;
}
public override void paint(Canvas canvas, Size size) {
if (!this._prepared) {
this._prepare();
}
canvas.translate(this._translationX(size.width), this._translationY(size.height));
canvas.rotate(this._rotation);
canvas.drawRect(BannerConstants._kRect, this._paintShadow);
canvas.drawRect(BannerConstants._kRect, this._paintBanner);
const float width = BannerConstants._kOffset * 2.0f;
this._textPainter.layout(minWidth: width, maxWidth: width);
this._textPainter.paint(canvas,
BannerConstants._kRect.topLeft + new Offset(0.0f,
(BannerConstants._kRect.height - this._textPainter.height) / 2.0f));
}
public override bool shouldRepaint(CustomPainter _oldDelegate) {
BannerPainter oldDelegate = _oldDelegate as BannerPainter;
return this.message != oldDelegate.message
|| this.location != oldDelegate.location
|| this.color != oldDelegate.color
|| this.textStyle != oldDelegate.textStyle;
}
public override bool? hitTest(Offset position) {
return false;
}
float _translationX(float width) {
switch (this.location) {
case BannerLocation.bottomEnd:
return width - BannerConstants._kBottomOffset;
case BannerLocation.topEnd:
return width;
case BannerLocation.bottomStart:
return BannerConstants._kBottomOffset;
case BannerLocation.topStart:
return 0.0f;
default:
throw new Exception("Unknown location: " + this.location);
}
}
float _translationY(float height) {
D.assert(this.location != null);
switch (this.location) {
case BannerLocation.bottomStart:
case BannerLocation.bottomEnd:
return height - BannerConstants._kBottomOffset;
case BannerLocation.topStart:
case BannerLocation.topEnd:
return 0.0f;
default:
throw new Exception("Unknown location: " + this.location);
}
}
float _rotation {
get {
switch (this.location) {
case BannerLocation.bottomStart:
case BannerLocation.topEnd:
return Mathf.PI / 4.0f;
case BannerLocation.bottomEnd:
case BannerLocation.topStart:
return -Mathf.PI / 4.0f;
default:
throw new Exception("Unknown location: " + this.location);
}
}
}
}
public class Banner : StatelessWidget {
public Banner(
Key key = null,
Widget child = null,
string message = null,
BannerLocation? location = null,
Color color = null,
TextStyle textStyle = null
) : base(key: key) {
D.assert(message != null);
this.child = child;
this.message = message;
this.location = location;
this.color = color ?? BannerConstants._kColor;
this.textStyle = textStyle ?? BannerConstants._kTextStyle;
}
public readonly Widget child;
public readonly string message;
public readonly BannerLocation? location;
public readonly Color color;
public readonly TextStyle textStyle;
public override Widget build(BuildContext context) {
D.assert(WidgetsD.debugCheckHasDirectionality(context));
return new CustomPaint(
foregroundPainter: new BannerPainter(
message: this.message,
location: this.location,
color: this.color,
textStyle: this.textStyle
),
child: this.child
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new StringProperty("message", this.message, showName: false));
properties.add(new EnumProperty<BannerLocation?>("location", this.location));
properties.add(new DiagnosticsProperty<Color>("color", this.color, showName: false));
this.textStyle?.debugFillProperties(properties);
}
}
public class CheckedModeBanner : StatelessWidget {
public CheckedModeBanner(
Key key = null,
Widget child = null
) : base(key: key) {
D.assert(child != null);
this.child = child;
}
public readonly Widget child;
public override Widget build(BuildContext context) {
Widget result = this.child;
D.assert(() => {
result = new Banner(
child: result,
message: "DEBUG",
location: BannerLocation.topEnd
);
return true;
});
return result;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
string message = "disabled";
D.assert(() => {
message = "'DEBUG'";
return true;
});
properties.add(DiagnosticsNode.message(message));
}
}
}

3
Runtime/widgets/banner.cs.meta


fileFormatVersion: 2
guid: e2e859ca92594b5d98bcce5ce505ca7b
timeCreated: 1552882905

91
Runtime/widgets/visibility.cs


using Unity.UIWidgets.foundation;
namespace Unity.UIWidgets.widgets {
public class Visibility : StatelessWidget {
public Visibility(
Key key = null,
Widget child = null,
Widget replacement = null,
bool visible = true,
bool maintainState = false,
bool maintainAnimation = false,
bool maintainSize = false,
bool maintainInteractivity = false
) : base(key: key) {
D.assert(child != null);
D.assert(maintainState == true || maintainAnimation == false,
"Cannot maintain animations if the state is not also maintained.");
D.assert(maintainAnimation == true || maintainSize == false,
"Cannot maintain size if animations are not maintained.");
D.assert(maintainSize == true || maintainInteractivity == false,
"Cannot maintain interactivity if size is not maintained.");
this.replacement = replacement ?? SizedBox.shrink();
this.child = child;
this.visible = visible;
this.maintainState = maintainState;
this.maintainAnimation = maintainAnimation;
this.maintainSize = maintainSize;
this.maintainInteractivity = maintainInteractivity;
}
public readonly Widget child;
public readonly Widget replacement;
public readonly bool visible;
public readonly bool maintainState;
public readonly bool maintainAnimation;
public readonly bool maintainSize;
public readonly bool maintainInteractivity;
public override Widget build(BuildContext context) {
if (this.maintainSize) {
Widget result = this.child;
if (!this.maintainInteractivity) {
result = new IgnorePointer(
child: this.child,
ignoring: !this.visible
);
}
return new Opacity(
opacity: this.visible ? 1.0f : 0.0f,
child: result
);
}
D.assert(!this.maintainInteractivity);
D.assert(!this.maintainSize);
if (this.maintainState) {
Widget result = this.child;
if (!this.maintainAnimation) {
result = new TickerMode(child: this.child, enabled: this.visible);
}
return new Offstage(
child: result,
offstage: !this.visible
);
}
D.assert(!this.maintainAnimation);
D.assert(!this.maintainState);
return this.visible ? this.child : this.replacement;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagProperty("visible", value: this.visible, ifFalse: "hidden", ifTrue: "visible"));
properties.add(new FlagProperty("maintainState", value: this.maintainState, ifFalse: "maintainState"));
properties.add(new FlagProperty("maintainAnimation", value: this.maintainAnimation,
ifFalse: "maintainAnimation"));
properties.add(new FlagProperty("maintainSize", value: this.maintainSize, ifFalse: "maintainSize"));
properties.add(new FlagProperty("maintainInteractivity", value: this.maintainInteractivity,
ifFalse: "maintainInteractivity"));
}
}
}

3
Runtime/widgets/visibility.cs.meta


fileFormatVersion: 2
guid: f24846c5a2354d9a8b02bf83f3e8398e
timeCreated: 1552895385

20
Samples/UIWidgetsGallery/GalleryMain.cs


using UIWidgetsGallery.gallery;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.material;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace UIWidgetsGallery {
public class GalleryMain : UIWidgetsPanel {
protected override Widget createWidget() {
return new GalleryApp();
}
protected override void Start() {
base.Start();
FontManager.instance.addFont(Resources.Load<Font>("MaterialIcons-Regular"));
FontManager.instance.addFont(Resources.Load<Font>("GalleryIcons"));
}
}
}

8
Samples/UIWidgetsGallery/demo.meta


fileFormatVersion: 2
guid: 5159692a5f76049d49b05fb717c096e3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

365
Samples/UIWidgetsGallery/gallery/backdrop.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace UIWidgetsGallery.gallery {
class BackdropConstants {
public const float _kFrontHeadingHeight = 32.0f;
public const float _kFrontClosedHeight = 92.0f;
public const float _kBackAppBarHeight = 56.0f;
public static readonly Animatable<BorderRadius> _kFrontHeadingBevelRadius = new BorderRadiusTween(
begin: BorderRadius.only(
topLeft: Radius.circular(12.0f),
topRight: Radius.circular(12.0f)
),
end: BorderRadius.only(
topLeft: Radius.circular(_kFrontHeadingHeight),
topRight: Radius.circular(_kFrontHeadingHeight)
)
);
}
class _TappableWhileStatusIs : StatefulWidget {
public _TappableWhileStatusIs(
AnimationStatus status,
Key key = null,
AnimationController controller = null,
Widget child = null
) : base(key: key) {
this.controller = controller;
this.status = status;
this.child = child;
}
public readonly AnimationController controller;
public readonly AnimationStatus status;
public readonly Widget child;
public override State createState() {
return new _TappableWhileStatusIsState();
}
}
class _TappableWhileStatusIsState : State<_TappableWhileStatusIs> {
bool _active;
public override void initState() {
base.initState();
this.widget.controller.addStatusListener(this._handleStatusChange);
this._active = this.widget.controller.status == this.widget.status;
}
public override void dispose() {
this.widget.controller.removeStatusListener(this._handleStatusChange);
base.dispose();
}
void _handleStatusChange(AnimationStatus status) {
bool value = this.widget.controller.status == this.widget.status;
if (this._active != value) {
this.setState(() => { this._active = value; });
}
}
public override Widget build(BuildContext context) {
return new AbsorbPointer(
absorbing: !this._active,
child: this.widget.child
);
}
}
class _CrossFadeTransition : AnimatedWidget {
public _CrossFadeTransition(
Key key = null,
Alignment alignment = null,
Animation<float> progress = null,
Widget child0 = null,
Widget child1 = null
) : base(key: key, listenable: progress) {
this.alignment = alignment ?? Alignment.center;
this.child0 = child0;
this.child1 = child1;
}
public readonly Alignment alignment;
public readonly Widget child0;
public readonly Widget child1;
protected override Widget build(BuildContext context) {
Animation<float> progress = this.listenable as Animation<float>;
float opacity1 = new CurvedAnimation(
parent: new ReverseAnimation(progress),
curve: new Interval(0.5f, 1.0f)
).value;
float opacity2 = new CurvedAnimation(
parent: progress,
curve: new Interval(0.5f, 1.0f)
).value;
return new Stack(
alignment: this.alignment,
children: new List<Widget> {
new Opacity(
opacity: opacity1,
child: this.child1
),
new Opacity(
opacity: opacity2,
child: this.child0
)
}
);
}
}
class _BackAppBar : StatelessWidget {
public _BackAppBar(
Key key = null,
Widget leading = null,
Widget title = null,
Widget trailing = null
) : base(key: key) {
D.assert(title != null);
this.leading = leading ?? new SizedBox(width: 56.0f);
this.title = title;
this.trailing = trailing;
}
public readonly Widget leading;
public readonly Widget title;
public readonly Widget trailing;
public override Widget build(BuildContext context) {
List<Widget> children = new List<Widget> {
new Container(
alignment: Alignment.center,
width: 56.0f,
child: this.leading
),
new Expanded(
child: this.title
),
};
if (this.trailing != null) {
children.Add(
new Container(
alignment: Alignment.center,
width: 56.0f,
child: this.trailing
)
);
}
ThemeData theme = Theme.of(context);
return IconTheme.merge(
data: theme.primaryIconTheme,
child: new DefaultTextStyle(
style: theme.primaryTextTheme.title,
child: new SizedBox(
height: BackdropConstants._kBackAppBarHeight,
child: new Row(children: children)
)
)
);
}
}
public class Backdrop : StatefulWidget {
public Backdrop(
Widget frontAction = null,
Widget frontTitle = null,
Widget frontHeading = null,
Widget frontLayer = null,
Widget backTitle = null,
Widget backLayer = null
) {
this.frontAction = frontAction;
this.frontTitle = frontTitle;
this.frontHeading = frontHeading;
this.frontLayer = frontLayer;
this.backTitle = backTitle;
this.backLayer = backLayer;
}
public readonly Widget frontAction;
public readonly Widget frontTitle;
public readonly Widget frontLayer;
public readonly Widget frontHeading;
public readonly Widget backTitle;
public readonly Widget backLayer;
public override State createState() {
return new _BackdropState();
}
}
class _BackdropState : SingleTickerProviderStateMixin<Backdrop> {
GlobalKey _backdropKey = GlobalKey.key(debugLabel: "Backdrop");
AnimationController _controller;
Animation<float> _frontOpacity;
static Animatable<float> _frontOpacityTween = new FloatTween(begin: 0.2f, end: 1.0f)
.chain(new CurveTween(curve: new Interval(0.0f, 0.4f, curve: Curves.easeInOut)));
public override void initState() {
base.initState();
this._controller = new AnimationController(
duration: new TimeSpan(0, 0, 0, 0, 300),
value: 1.0f,
vsync: this
);
this._frontOpacity = this._controller.drive(_frontOpacityTween);
}
public override void dispose() {
this._controller.dispose();
base.dispose();
}
float? _backdropHeight {
get {
RenderBox renderBox = (RenderBox) this._backdropKey.currentContext.findRenderObject();
return Mathf.Max(0.0f,
renderBox.size.height - BackdropConstants._kBackAppBarHeight -
BackdropConstants._kFrontClosedHeight);
}
}
void _handleDragUpdate(DragUpdateDetails details) {
this._controller.setValue(this._controller.value -
details.primaryDelta / (this._backdropHeight ?? details.primaryDelta) ?? 0.0f);
}
void _handleDragEnd(DragEndDetails details) {
if (this._controller.isAnimating || this._controller.status == AnimationStatus.completed) {
return;
}
float? flingVelocity = details.velocity.pixelsPerSecond.dy / this._backdropHeight;
if (flingVelocity < 0.0f) {
this._controller.fling(velocity: Mathf.Max(2.0f, -flingVelocity ?? 0.0f));
}
else if (flingVelocity > 0.0f) {
this._controller.fling(velocity: Mathf.Min(-2.0f, -flingVelocity ?? 0.0f));
}
else {
this._controller.fling(velocity: this._controller.value < 0.5 ? -2.0f : 2.0f);
}
}
void _toggleFrontLayer() {
AnimationStatus status = this._controller.status;
bool isOpen = status == AnimationStatus.completed || status == AnimationStatus.forward;
this._controller.fling(velocity: isOpen ? -2.0f : 2.0f);
}
Widget _buildStack(BuildContext context, BoxConstraints constraints) {
Animation<RelativeRect> frontRelativeRect = this._controller.drive(new RelativeRectTween(
begin: RelativeRect.fromLTRB(0.0f, constraints.biggest.height - BackdropConstants._kFrontClosedHeight,
0.0f, 0.0f),
end: RelativeRect.fromLTRB(0.0f, BackdropConstants._kBackAppBarHeight, 0.0f, 0.0f)
));
List<Widget> layers = new List<Widget> {
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: new List<Widget> {
new _BackAppBar(
leading: this.widget.frontAction,
title: new _CrossFadeTransition(
progress: this._controller,
alignment: Alignment.centerLeft,
child0: this.widget.frontTitle,
child1: this.widget.backTitle
),
trailing: new IconButton(
onPressed: this._toggleFrontLayer,
tooltip: "Toggle options page",
icon: new AnimatedIcon(
icon: AnimatedIcons.close_menu,
progress: this._controller
)
)
),
new Expanded(
child: new Visibility(
child: this.widget.backLayer,
visible: this._controller.status != AnimationStatus.completed,
maintainState: true
)
)
}
),
new PositionedTransition(
rect: frontRelativeRect,
child: new AnimatedBuilder(
animation: this._controller,
builder: (BuildContext _context, Widget child) => {
return new PhysicalShape(
elevation: 12.0f,
color: Theme.of(_context).canvasColor,
clipper: new ShapeBorderClipper(
shape: new BeveledRectangleBorder(
borderRadius: BackdropConstants._kFrontHeadingBevelRadius.evaluate(
this._controller)
)
),
clipBehavior: Clip.antiAlias,
child: child
);
},
child: new _TappableWhileStatusIs(
AnimationStatus.completed,
controller: this._controller,
child: new FadeTransition(
opacity: this._frontOpacity,
child: this.widget.frontLayer
)
)
)
)
};
if (this.widget.frontHeading != null) {
layers.Add(
new PositionedTransition(
rect: frontRelativeRect,
child: new Container(
alignment: Alignment.topLeft,
child: new GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: this._toggleFrontLayer,
onVerticalDragUpdate: this._handleDragUpdate,
onVerticalDragEnd: this._handleDragEnd,
child: this.widget.frontHeading
)
)
)
);
}
return new Stack(
key: this._backdropKey,
children: layers
);
}
public override Widget build(BuildContext context) {
return new LayoutBuilder(builder: this._buildStack);
}
}
}

3
Samples/UIWidgetsGallery/gallery/backdrop.cs.meta


fileFormatVersion: 2
guid: f3ee24c4986845abb1356402632d8524
timeCreated: 1552886622

215
Samples/UIWidgetsGallery/gallery/demo.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.gallery {
class ComponentDemoTabData {
public ComponentDemoTabData(
Widget demoWidget = null,
string exampleCodeTag = null,
string description = null,
string tabName = null,
string documentationUrl = null
) {
this.demoWidget = demoWidget;
this.exampleCodeTag = exampleCodeTag;
this.description = description;
this.tabName = tabName;
this.documentationUrl = documentationUrl;
}
public readonly Widget demoWidget;
public readonly string exampleCodeTag;
public readonly string description;
public readonly string tabName;
public readonly string documentationUrl;
public static bool operator ==(ComponentDemoTabData left, ComponentDemoTabData right) {
return right.tabName == left.tabName
&& right.description == left.description
&& right.documentationUrl == left.documentationUrl;
}
public static bool operator !=(ComponentDemoTabData left, ComponentDemoTabData right) {
return right.tabName != left.tabName
|| right.description != left.description
|| right.documentationUrl != left.documentationUrl;
}
public override int GetHashCode() {
unchecked {
var hashCode = this.tabName.GetHashCode();
hashCode = (hashCode * 397) ^ this.description.GetHashCode();
hashCode = (hashCode * 397) ^ this.documentationUrl.GetHashCode();
return hashCode;
}
}
}
class TabbedComponentDemoScaffold : StatelessWidget {
public TabbedComponentDemoScaffold(
string title = null,
List<ComponentDemoTabData> demos = null,
List<Widget> actions = null
) {
this.title = title;
this.demos = demos;
this.actions = actions;
}
public readonly List<ComponentDemoTabData> demos;
public readonly string title;
public readonly List<Widget> actions;
void _showExampleCode(BuildContext context) {
string tag = this.demos[DefaultTabController.of(context).index].exampleCodeTag;
if (tag != null) {
Navigator.push(context, new MaterialPageRoute(
builder: (BuildContext _context) => new FullScreenCodeDialog(exampleCodeTag: tag)
));
}
}
void _showApiDocumentation(BuildContext context) {
string url = this.demos[DefaultTabController.of(context).index].documentationUrl;
if (url != null) {
// TODO: find Unity equivalent
// Open the URL in browser
// launch(url, forceWebView: true);
}
}
public override Widget build(BuildContext context) {
List<Widget> actions = this.actions ?? new List<Widget> { };
actions.AddRange(
new List<Widget> {
new Builder(
builder: (BuildContext _context) => {
return new IconButton(
icon: new Icon(Icons.library_books),
onPressed: () => this._showApiDocumentation(_context)
);
}
),
new Builder(
builder: (BuildContext _context) => {
return new IconButton(
icon: new Icon(Icons.code),
tooltip: "Show example code",
onPressed: () => this._showExampleCode(_context)
);
}
)
}
);
return new DefaultTabController(
length: this.demos.Count,
child: new Scaffold(
appBar: new AppBar(
title: new Text(this.title),
actions: actions,
bottom: new TabBar(
isScrollable: true,
tabs: this.demos.Select<ComponentDemoTabData, Widget>(
(ComponentDemoTabData data) => new Tab(text: data.tabName))
.ToList()
)
),
body: new TabBarView(
children: this.demos.Select<ComponentDemoTabData, Widget>((ComponentDemoTabData demo) => {
return new SafeArea(
top: false,
bottom: false,
child: new Column(
children: new List<Widget> {
new Padding(
padding: EdgeInsets.all(16.0f),
child: new Text(demo.description,
style: Theme.of(context).textTheme.subhead
)
),
new Expanded(child: demo.demoWidget)
}
)
);
}).ToList()
)
)
);
}
}
class FullScreenCodeDialog : StatefulWidget {
public FullScreenCodeDialog(Key key = null, string exampleCodeTag = null) : base(key: key) {
this.exampleCodeTag = exampleCodeTag;
}
public readonly string exampleCodeTag;
public override State createState() {
return new FullScreenCodeDialogState();
}
}
class FullScreenCodeDialogState : State<FullScreenCodeDialog> {
public FullScreenCodeDialogState() {
}
string _exampleCode;
public override void didChangeDependencies() {
base.didChangeDependencies();
string code = new ExampleCodeParser().getExampleCode(this.widget.exampleCodeTag, DefaultAssetBundle.of(this.context));
if (this.mounted) {
this.setState(() => { this._exampleCode = code; });
}
}
public override Widget build(BuildContext context) {
SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark
? SyntaxHighlighterStyle.darkThemeStyle()
: SyntaxHighlighterStyle.lightThemeStyle();
Widget body;
if (this._exampleCode == null) {
body = new Center(
child: new CircularProgressIndicator()
);
}
else {
body = new SingleChildScrollView(
child: new Padding(
padding: EdgeInsets.all(16.0f),
child: new RichText(
text: new TextSpan(
style: new TextStyle(fontFamily: "monospace", fontSize: 10.0f),
children: new List<TextSpan> {
new DartSyntaxHighlighter(style).format(this._exampleCode)
}
)
)
)
);
}
return new Scaffold(
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(
Icons.clear
),
onPressed: () => { Navigator.pop(context); }
),
title: new Text("Example code")
),
body: body
);
}
}
}

3
Samples/UIWidgetsGallery/gallery/demo.cs.meta


fileFormatVersion: 2
guid: 3c8404e1b03d43aba2e91d19f124de5e
timeCreated: 1552462303

53
Samples/UIWidgetsGallery/gallery/example_code_parser.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RSG;
using Unity.UIWidgets.foundation;
using UnityEngine;
namespace UIWidgetsGallery.gallery {
public class ExampleCodeParser {
const string _kStartTag = "// START ";
const string _kEndTag = "// END";
Dictionary<string, string> _exampleCode;
public string getExampleCode(string tag, AssetBundle bundle) {
if (this._exampleCode == null)
this._parseExampleCode(bundle);
return this._exampleCode.getOrDefault(tag);
}
void _parseExampleCode(AssetBundle bundle) {
string code = Resources.Load<TextAsset>("example_code.cs")?.text ??
"// example_code.cs not found\n";
this._exampleCode = new Dictionary<string, string>{};
List<String> lines = code.Split('\n').ToList();
List<String> codeBlock = null;
string codeTag = null;
foreach (string line in lines) {
if (codeBlock == null) {
if (line.StartsWith(_kStartTag)) {
codeBlock = new List<String>();
codeTag = line.Substring(_kStartTag.Length).Trim();
} else {
}
} else {
if (line.StartsWith(_kEndTag)) {
this._exampleCode[codeTag] = string.Join("\n", codeBlock);
codeBlock = null;
codeTag = null;
} else {
codeBlock.Add(line.TrimEnd());
}
}
}
}
}
}

3
Samples/UIWidgetsGallery/gallery/example_code_parser.cs.meta


fileFormatVersion: 2
guid: 57879fd6125746699974c2e0bc8762b8
timeCreated: 1552468268

427
Samples/UIWidgetsGallery/gallery/syntax_highlighter.cs


using System.Collections.Generic;
using System.Text.RegularExpressions;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.gallery {
public class SyntaxHighlighterStyle {
public SyntaxHighlighterStyle(
TextStyle baseStyle = null,
TextStyle numberStyle = null,
TextStyle commentStyle = null,
TextStyle keywordStyle = null,
TextStyle stringStyle = null,
TextStyle punctuationStyle = null,
TextStyle classStyle = null,
TextStyle constantStyle = null
) {
this.baseStyle = baseStyle;
this.numberStyle = numberStyle;
this.commentStyle = commentStyle;
this.keywordStyle = keywordStyle;
this.stringStyle = stringStyle;
this.punctuationStyle = punctuationStyle;
this.classStyle = classStyle;
this.constantStyle = constantStyle;
}
public static SyntaxHighlighterStyle lightThemeStyle() {
return new SyntaxHighlighterStyle(
baseStyle: new TextStyle(color: new Color(0xFF000000)),
numberStyle: new TextStyle(color: new Color(0xFF1565C0)),
commentStyle: new TextStyle(color: new Color(0xFF9E9E9E)),
keywordStyle: new TextStyle(color: new Color(0xFF9C27B0)),
stringStyle: new TextStyle(color: new Color(0xFF43A047)),
punctuationStyle: new TextStyle(color: new Color(0xFF000000)),
classStyle: new TextStyle(color: new Color(0xFF512DA8)),
constantStyle: new TextStyle(color: new Color(0xFF795548))
);
}
public static SyntaxHighlighterStyle darkThemeStyle() {
return new SyntaxHighlighterStyle(
baseStyle: new TextStyle(color: new Color(0xFFFFFFFF)),
numberStyle: new TextStyle(color: new Color(0xFF1565C0)),
commentStyle: new TextStyle(color: new Color(0xFF9E9E9E)),
keywordStyle: new TextStyle(color: new Color(0xFF80CBC4)),
stringStyle: new TextStyle(color: new Color(0xFF009688)),
punctuationStyle: new TextStyle(color: new Color(0xFFFFFFFF)),
classStyle: new TextStyle(color: new Color(0xFF009688)),
constantStyle: new TextStyle(color: new Color(0xFF795548))
);
}
public readonly TextStyle baseStyle;
public readonly TextStyle numberStyle;
public readonly TextStyle commentStyle;
public readonly TextStyle keywordStyle;
public readonly TextStyle stringStyle;
public readonly TextStyle punctuationStyle;
public readonly TextStyle classStyle;
public readonly TextStyle constantStyle;
}
public abstract class SyntaxHighlighter {
// ignore: one_member_abstracts
public abstract TextSpan format(string src);
}
public class DartSyntaxHighlighter : SyntaxHighlighter {
public DartSyntaxHighlighter(SyntaxHighlighterStyle _style = null) {
this._spans = new List<_HighlightSpan> { };
this._style = _style ?? SyntaxHighlighterStyle.darkThemeStyle();
}
SyntaxHighlighterStyle _style;
readonly List<string> _keywords = new List<string> {
"abstract", "as", "assert", "async", "await", "break", "case", "catch",
"class", "const", "continue", "default", "deferred", "do", "dynamic", "else",
"enum", "export", "external", "extends", "factory", "false", "final",
"finally", "for", "get", "if", "implements", "import", "in", "is", "library",
"new", "null", "operator", "part", "rethrow", "return", "set", "static",
"super", "switch", "sync", "this", "throw", "true", "try", "typedef", "var",
"void", "while", "with", "yield"
};
readonly List<string> _builtInTypes = new List<string> {
"int", "double", "num", "bool"
};
string _src;
StringScanner _scanner;
List<_HighlightSpan> _spans;
public override TextSpan format(string src) {
this._src = src;
this._scanner = new StringScanner(this._src);
if (this._generateSpans()) {
List<TextSpan> formattedText = new List<TextSpan> { };
int currentPosition = 0;
foreach (_HighlightSpan span in this._spans) {
if (currentPosition != span.start) {
formattedText.Add(new TextSpan(text: this._src.Substring(currentPosition, span.start)));
}
formattedText.Add(new TextSpan(style: span.textStyle(this._style),
text: span.textForSpan(this._src)));
currentPosition = span.end;
}
if (currentPosition != this._src.Length) {
formattedText.Add(new TextSpan(text: this._src.Substring(currentPosition, this._src.Length)));
}
return new TextSpan(style: this._style.baseStyle, children: formattedText);
}
else {
return new TextSpan(style: this._style.baseStyle, text: src);
}
}
bool _generateSpans() {
int lastLoopPosition = this._scanner.position;
while (!this._scanner.isDone) {
this._scanner.scan(new Regex(@"\s+"));
// Block comments
if (this._scanner.scan(new Regex(@"/\*(.|\n)*\*/"))) {
this._spans.Add(new _HighlightSpan(
_HighlightType.comment,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Line comments
if (this._scanner.scan(new Regex(@"//"))) {
int startComment = this._scanner.lastMatch.Index;
bool eof = false;
int endComment;
if (this._scanner.scan(new Regex(@".*\n"))) {
endComment = this._scanner.lastMatch.Index + this._scanner.lastMatch.Length - 1;
}
else {
eof = true;
endComment = this._src.Length;
}
this._spans.Add(new _HighlightSpan(
_HighlightType.comment,
startComment,
endComment
));
if (eof) {
break;
}
continue;
}
// Raw r"String"
if (this._scanner.scan(new Regex(@"r"".*"""))) {
this._spans.Add(new _HighlightSpan(
_HighlightType._string,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Raw r"String"
if (this._scanner.scan(new Regex(@"r"".*"""))) {
this._spans.Add(new _HighlightSpan(
_HighlightType._string,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Multiline """String"""
if (this._scanner.scan(new Regex(@"""""""(?:[^""\\]|\\(.|\n))*"""""""))) {
this._spans.Add(new _HighlightSpan(
_HighlightType._string,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Multiline '''String'''
if (this._scanner.scan(new Regex(@"'''(?:[^""\\]|\\(.|\n))*'''"))) {
this._spans.Add(new _HighlightSpan(
_HighlightType._string,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// "String"
if (this._scanner.scan(new Regex(@"""(?:[^""\\]|\\.)*"""))) {
this._spans.Add(new _HighlightSpan(
_HighlightType._string,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// "String"
if (this._scanner.scan(new Regex(@"""(?:[^""\\]|\\.)*"""))) {
this._spans.Add(new _HighlightSpan(
_HighlightType._string,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Double
if (this._scanner.scan(new Regex(@"\d+\.\d+"))) {
this._spans.Add(new _HighlightSpan(
_HighlightType.number,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Integer
if (this._scanner.scan(new Regex(@"\d+"))) {
this._spans.Add(new _HighlightSpan(
_HighlightType.number,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length)
);
continue;
}
// Punctuation
if (this._scanner.scan(new Regex(@"[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]"))) {
this._spans.Add(new _HighlightSpan(
_HighlightType.punctuation,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Meta data
if (this._scanner.scan(new Regex(@"@\w+"))) {
this._spans.Add(new _HighlightSpan(
_HighlightType.keyword,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
continue;
}
// Words
if (this._scanner.scan(new Regex(@"\w+"))) {
_HighlightType? type = null;
string word = this._scanner.lastMatch.Groups[0].Value;
if (word.StartsWith("_")) {
word = word.Substring(1);
}
if (this._keywords.Contains(word)) {
type = _HighlightType.keyword;
}
else if (this._builtInTypes.Contains(word)) {
type = _HighlightType.keyword;
}
else if (this._firstLetterIsUpperCase(word)) {
type = _HighlightType.klass;
}
else if (word.Length >= 2 && word.StartsWith("k") &&
this._firstLetterIsUpperCase(word.Substring(1))) {
type = _HighlightType.constant;
}
if (type != null) {
this._spans.Add(new _HighlightSpan(
type,
this._scanner.lastMatch.Index,
this._scanner.lastMatch.Index + this._scanner.lastMatch.Length
));
}
}
// Check if this loop did anything
if (lastLoopPosition == this._scanner.position) {
// Failed to parse this file, abort gracefully
return false;
}
lastLoopPosition = this._scanner.position;
}
this._simplify();
return true;
}
void _simplify() {
for (int i = this._spans.Count - 2; i >= 0; i -= 1) {
if (this._spans[i].type == this._spans[i + 1].type && this._spans[i].end == this._spans[i + 1].start) {
this._spans[i] = new _HighlightSpan(
this._spans[i].type,
this._spans[i].start,
this._spans[i + 1].end
);
this._spans.RemoveAt(i + 1);
}
}
}
bool _firstLetterIsUpperCase(string str) {
if (str.isNotEmpty()) {
string first = str.Substring(0, 1);
return first == first.ToUpper();
}
return false;
}
}
enum _HighlightType {
number,
comment,
keyword,
_string,
punctuation,
klass,
constant
}
class _HighlightSpan {
public _HighlightSpan(_HighlightType? type, int start, int end) {
this.type = type;
this.start = start;
this.end = end;
}
public readonly _HighlightType? type;
public readonly int start;
public readonly int end;
public string textForSpan(string src) {
return src.Substring(this.start, this.end);
}
public TextStyle textStyle(SyntaxHighlighterStyle style) {
if (this.type == _HighlightType.number) {
return style.numberStyle;
}
else if (this.type == _HighlightType.comment) {
return style.commentStyle;
}
else if (this.type == _HighlightType.keyword) {
return style.keywordStyle;
}
else if (this.type == _HighlightType._string) {
return style.stringStyle;
}
else if (this.type == _HighlightType.punctuation) {
return style.punctuationStyle;
}
else if (this.type == _HighlightType.klass) {
return style.classStyle;
}
else if (this.type == _HighlightType.constant) {
return style.constantStyle;
}
else {
return style.baseStyle;
}
}
}
public class StringScanner {
string _source { get; set; }
public int position { get; set; }
public Match lastMatch {
get { return this._lastMatch; }
}
Match _lastMatch;
public StringScanner(string source) {
this._source = source;
this.position = 0;
}
public override string ToString() {
return this.isDone ? "" : this._source.Substring(this.position);
}
public bool isDone {
get { return this.position >= this._source.Length; }
}
public bool scan(Regex regex) {
var match = regex.Match(this.ToString());
if (match.Success) {
this.position += match.Length;
this._lastMatch = match;
return true;
}
else {
return false;
}
}
}
}

3
Samples/UIWidgetsGallery/gallery/syntax_highlighter.cs.meta


fileFormatVersion: 2
guid: 205d7446dc624493a18d7118ffeec352
timeCreated: 1552469338

14
Tests/Resources/GalleryIcons.ttf


 �0OS/2E�`cmapVҮTgasppglyf(�69x�head�]p6hhea���$hmtx�j��locac�_|Zmaxp7�� name��(D��post� ��������3 @�'���@�@ 8
 �'���� ���������797979U�k !/!!7!!7!U��++���V��9rr9�&@@&V�U��U@�@7!!3#37!3UV���**�k�`0 /`��ef�U��U����U����U�k !!!5!5!UVV�V���Uk��V��V�U���)!.#"3267!2654&!>54&'!2+��X4,''::'',4XW5KK5��/@'.:'',,'':.'K55K�   U@�@ !"3!2654&#532+��5KK5V5KK5��@K55KK55K�VU�k ! '#%!!'35#'!!��V���뇇��<�9'���a@k��o��|����@��Q�U�k 3OV4&#"326%4&#"326"327>7654'.'&"'.'&547>76323267�%&&%��&%%&UYMNt!""!tNMYXNNt!""!tNNXG>>]]>>GG>>]]>>��sIIs+&&%%&&%%["!tNNXXNNt!""!tNNXXNNt!"�]>>GG>>]]>>GG>>]K``K�kU4.#"327>767##"'.'&547>7632!�.|GG>>\\>>G<56WY ?&&*5/.FF./55\#�*�.6]>>GG>>]E/.8&. F./55/.F)#�*U�k5%"'.'&547>7632#"327>7654632XNNs""""sNNXG>>]]>>GG>>]""sNN""sNNXXNNs""]>>GG>>]]>>GXNNs""����!"3!2654&"&546327!!���,??,U,??�%%&&�����>,�*,>>,�,>��&%%&�UUk� %1>JV2#"&54635"32654&2#"&54635"32654&2#"&54635"32654&3"32654&�   $22$#22�   #22##21�   #22##22�#22#$22�  82##22##28  82##22##28  82##22##22##22##2�kU #2654&#""32654&"32654&#22##22##22##22##22##22k2##22##2V2##22##2�2##22##2���� 7!5!5!5!5!5����U�V�UU�@�@#'+!%!"3!2654&!!!!!!3#3#3#+����L� �o����UUUUUU���VU�L  ��UUVUU�UUVUU
U�k#'+/3!"3!2654&#535#535#53#535#535#53#535#535#53U�V$22$�$22�ܪ�����������������k2$�V$22$�$2��V�V��V�V�V��V�V�V�k 7 7' '�<��<��<</<�<����<�<�@��#3!5##"3!2654&+5!!���*��U+#22#V#22#++��V���UUU2#��#22#V#2U��Uk�#'##'##'#"3!265U�UUU�UVV�V*$12$�$2������2#�#22#UU�k !%!!!!U�V��V����V�V�V����VU�k !!5!5!5!5!5!3#3#3#UVV�V��V��V���VVVVVVk��V��V�V�*V�VVVVV�k
37337%!!5!!'?/��R(�)Q�zVV�U���V�((XX((X��ll�������+�V��+XXX((XX(j@�k! 326764'7032654&��VCq�
 
�����]6'&7]��Dq�;��
;2��Nu.&77&.uU�k!!!"&5463!2UV�����%%�%%k��V���V%%%%�@�@!"3!2654&'7+��#22#V#22�]�<�D<@2#��#22#V#2���<�D<U�k !%!!!!!!!!!!U�V��V�*��B������B���V�V�������V����U�k7C"327>7654'.'&"'.'&547>7632##33535#XNNt!""!tNNXXNNt!""!tNNXG>>]]>>GG>>]]>>V��V��k"!tNNXXNNt!""!tNNXXNNt!"�]>>GG>>]]>>GG>>]*�V��VU�k!!UV��k��V�UU��U�k %!%!5!!����V��VV��V�*�+�U�k0DXr�"327>767>767>7654'.'&#"'.'&546737"'.'&546737#"'.'&5467>3274'.'&#>32�+((E)B$* Q76>+((E)B$* Q76>�,'':Q76>A\,'':Q76>A�%,'':%,'':\Q76>A$,'':k *$B)E((+>67Q *$B)E((+>67Q�:'',$A>67Q�:'',$A>66Q�:'',%:'',%8>66Q:'',$A�@�@,3!2654&#!"#"&5463247>7632!�2#V#22#��#2K55KK55K��P,, ,,P����#22#V#22�5KK55KK�v " " +U�k%!!!����V�V���+�����&+D!!767>7676'.'&'3%!##>"'.'&'!#5��7. ""c>?DD<<ZP88D���:43O ���hz+''? +.%%3 B+*/�0�7D89PZ;<DD?>d"" �� O34:��оHg�'2#"*(
I+,//((:�@�@ #53#35#!5#''7'7'+VVVVU��V��<w;��<x<�<x;��<|<�����UVVVV<x;��<x<<w;.<|<�@�@ #%#35#!5#''7'7''333+VVU��V��<w;��<x<�<x;��<|<�wwLVL��UVVVV<x;��<x<<w;.<|<���3������ -;!"3!27>7654'.'&#4632#"&5#>54&'32���(&=
:'',V,''::'',�*J67II76J֫�6JJ�
=&(-''99''--''9�6JJ66JJ6�C##CJ66JU���!"3!2654&#U�V$22$�$22$�2#�#22##2U�k!!!463!2UV���V2##2k��V�#22#�U�k(!!!5332673%"&5463274&#"#!#UV���V�@&&@���%%%%zW>>W���k��V��##��%%%%@>WW>��+U�k !!!!!!UV���V��V��Vk��V�*���*���@�@ !!!!5!!5#3#35!!!���V����UUUU����V@U�UU�VV�UVVU�U����q[_<� ��L���L���������,UUUUUUU�U�U���U�UUUVjU�UUUUU�U���UUUU�
Bl��� ��Dx�":���"Jh��8b��0�>V�J��� " D |,�
� � E � $ i
�   � Q � / u
4�GalleryIconsGalleryIconsVersion 1.0Version 1.0GalleryIconsGalleryIconsGalleryIconsGalleryIconsRegularRegularGalleryIconsGalleryIconsFont generated by IcoMoon.Font generated by IcoMoon.

22
Tests/Resources/GalleryIcons.ttf.meta


fileFormatVersion: 2
guid: 3a6743c0a08ca4626a9b85050002f40c
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontName: GalleryIcons
fontNames:
- GalleryIcons
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

25
Tests/Resources/unity.png

之前 之后
宽度: 600  |  高度: 600  |  大小: 5.8 KiB

88
Tests/Resources/unity.png.meta


fileFormatVersion: 2
guid: e0f035e3c6f0247b9ba5aab8669a7f0a
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 9
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/material/animated_icons/animated_icons.cs.meta


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

3
Runtime/material/animated_icons/animated_icons_data.cs.meta


fileFormatVersion: 2
guid: 439a75e2cc39472ba806029b41996e9b
timeCreated: 1552892371

8
Runtime/material/animated_icons/data.meta


fileFormatVersion: 2
guid: 14a0ec7a1462b4e50861bac1c7cfc3bf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

11
Runtime/material/animated_icons/data/add_event.g.cs.meta


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

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

3
Runtime/material/animated_icons/data/arrow_menu.g.cs.meta


fileFormatVersion: 2
guid: f38795e53cc54f628c2125e5e50fea1c
timeCreated: 1552894502

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

3
Runtime/material/animated_icons/data/close_menu.g.cs.meta


fileFormatVersion: 2
guid: e3a716495016460c8599ef52f9bd690f
timeCreated: 1552894786

223
Runtime/material/animated_icons/animated_icons.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.material {
static class AnimatedIconUtils {
public static T _interpolate<T>(List<T> values, float progress, _Interpolator<T> interpolator) {
D.assert(progress <= 1.0f);
D.assert(progress >= 0.0f);
if (values.Count == 1) {
return values[0];
}
float targetIdx = MathUtils.lerpFloat(0, values.Count - 1, progress);
int lowIdx = targetIdx.floor();
int highIdx = targetIdx.ceil();
float t = targetIdx - lowIdx;
return interpolator(values[lowIdx], values[highIdx], t);
}
}
public class AnimatedIcon : StatelessWidget {
public AnimatedIcon(
Key key = null,
AnimatedIconData icon = null,
Animation<float> progress = null,
Color color = null,
float? size = null
) : base(key: key) {
D.assert(progress != null);
D.assert(icon != null);
this.progress = progress;
this.color = color;
this.size = size;
this.icon = icon;
}
public readonly Animation<float> progress;
public readonly Color color;
public readonly float? size;
public readonly AnimatedIconData icon;
public static readonly _UiPathFactory _pathFactory = () => new Path();
public override Widget build(BuildContext context) {
_AnimatedIconData iconData = (_AnimatedIconData) this.icon;
IconThemeData iconTheme = IconTheme.of(context);
float iconSize = this.size ?? iconTheme.size ?? 0.0f;
float? iconOpacity = iconTheme.opacity;
Color iconColor = this.color ?? iconTheme.color;
if (iconOpacity != 1.0f) {
iconColor = iconColor.withOpacity(iconColor.opacity * (iconOpacity ?? 1.0f));
}
return new CustomPaint(
size: new Size(iconSize, iconSize),
painter: new _AnimatedIconPainter(
paths: iconData.paths,
progress: this.progress,
color: iconColor,
scale: iconSize / iconData.size.width,
uiPathFactory: _pathFactory
)
);
}
}
public delegate Path _UiPathFactory();
class _AnimatedIconPainter : AbstractCustomPainter {
public _AnimatedIconPainter(
List<_PathFrames> paths = null,
Animation<float> progress = null,
Color color = null,
float? scale = null,
bool? shouldMirror = null,
_UiPathFactory uiPathFactory = null
) : base(repaint: progress) {
this.paths = paths;
this.progress = progress;
this.color = color;
this.scale = scale;
this.shouldMirror = shouldMirror;
this.uiPathFactory = uiPathFactory;
}
public readonly List<_PathFrames> paths;
public readonly Animation<float> progress;
public readonly Color color;
public readonly float? scale;
public readonly bool? shouldMirror;
public readonly _UiPathFactory uiPathFactory;
public override void paint(Canvas canvas, Size size) {
canvas.scale(this.scale ?? 1.0f, this.scale ?? 1.0f);
if (this.shouldMirror == true) {
canvas.rotate(Mathf.PI);
canvas.translate(-size.width, -size.height);
}
float clampedProgress = this.progress.value.clamp(0.0f, 1.0f);
foreach (_PathFrames path in this.paths) {
path.paint(canvas, this.color, this.uiPathFactory, clampedProgress);
}
}
public override bool shouldRepaint(CustomPainter _oldDelegate) {
_AnimatedIconPainter oldDelegate = _oldDelegate as _AnimatedIconPainter;
return oldDelegate.progress.value != this.progress.value
|| oldDelegate.color != this.color
|| oldDelegate.paths != this.paths
|| oldDelegate.scale != this.scale
|| oldDelegate.uiPathFactory != this.uiPathFactory;
}
public override bool? hitTest(Offset position) {
return null;
}
}
class _PathFrames {
public _PathFrames(
List<_PathCommand> commands,
List<float> opacities
) {
this.commands = commands;
this.opacities = opacities;
}
public readonly List<_PathCommand> commands;
public readonly List<float> opacities;
public void paint(Canvas canvas, Color color, _UiPathFactory uiPathFactory, float progress) {
float opacity = AnimatedIconUtils._interpolate<float>(this.opacities, progress, MathUtils.lerpFloat);
Paint paint = new Paint();
paint.style = PaintingStyle.fill;
paint.color = color.withOpacity(color.opacity * opacity);
Path path = uiPathFactory();
foreach (_PathCommand command in this.commands) {
command.apply(path, progress);
}
canvas.drawPath(path, paint);
}
}
abstract class _PathCommand {
public _PathCommand() {
}
public abstract void apply(Path path, float progress);
}
class _PathMoveTo : _PathCommand {
public _PathMoveTo(List<Offset> points) {
this.points = points;
}
public readonly List<Offset> points;
public override void apply(Path path, float progress) {
Offset offset = AnimatedIconUtils._interpolate<Offset>(this.points, progress, Offset.lerp);
path.moveTo(offset.dx, offset.dy);
}
}
class _PathCubicTo : _PathCommand {
public _PathCubicTo(List<Offset> controlPoints1, List<Offset> controlPoints2, List<Offset> targetPoints) {
this.controlPoints1 = controlPoints1;
this.controlPoints2 = controlPoints2;
this.targetPoints = targetPoints;
}
public readonly List<Offset> controlPoints2;
public readonly List<Offset> controlPoints1;
public readonly List<Offset> targetPoints;
public override void apply(Path path, float progress) {
Offset controlPoint1 = AnimatedIconUtils._interpolate<Offset>(this.controlPoints1, progress, Offset.lerp);
Offset controlPoint2 = AnimatedIconUtils._interpolate<Offset>(this.controlPoints2, progress, Offset.lerp);
Offset targetPoint = AnimatedIconUtils._interpolate<Offset>(this.targetPoints, progress, Offset.lerp);
// TODO: replace with cubicTo
path.bezierTo(
controlPoint1.dx, controlPoint1.dy,
controlPoint2.dx, controlPoint2.dy,
targetPoint.dx, targetPoint.dy
);
}
}
class _PathLineTo : _PathCommand {
public _PathLineTo(List<Offset> points) {
this.points = points;
}
List<Offset> points;
public override void apply(Path path, float progress) {
Offset point = AnimatedIconUtils._interpolate<Offset>(this.points, progress, Offset.lerp);
path.lineTo(point.dx, point.dy);
}
}
class _PathClose : _PathCommand {
public _PathClose() {
}
public override void apply(Path path, float progress) {
path.close();
}
}
public delegate T _Interpolator<T>(T a, T b, float progress);
}

54
Runtime/material/animated_icons/animated_icons_data.cs


using System.Collections.Generic;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.material {
public abstract class AnimatedIcons {
public static readonly AnimatedIconData add_event = AnimatedIconsData._add_event;
public static readonly AnimatedIconData arrow_menu = AnimatedIconsData._arrow_menu;
public static readonly AnimatedIconData close_menu = AnimatedIconsData._close_menu;
// public readonly AnimatedIconData ellipsis_search = AnimatedIconsData._ellipsis_search;
// public readonly AnimatedIconData event_add = AnimatedIconsData._event_add;
// public readonly AnimatedIconData home_menu = AnimatedIconsData._home_menu;
// public readonly AnimatedIconData list_view = AnimatedIconsData._list_view;
// public readonly AnimatedIconData menu_arrow = AnimatedIconsData._menu_arrow;
// public readonly AnimatedIconData menu_close = AnimatedIconsData._menu_close;
// public readonly AnimatedIconData menu_home = AnimatedIconsData._menu_home;
// public readonly AnimatedIconData pause_play = AnimatedIconsData._pause_play;
// public readonly AnimatedIconData play_pause = AnimatedIconsData._play_pause;
// public readonly AnimatedIconData search_ellipsis = AnimatedIconsData._search_ellipsis;
// public readonly AnimatedIconData view_list = AnimatedIconsData._view_list;
}
public abstract class AnimatedIconData {
public AnimatedIconData() {
}
public abstract bool matchTextDirection { get; }
}
class _AnimatedIconData : AnimatedIconData {
public _AnimatedIconData(Size size, List<_PathFrames> paths, bool matchTextDirection = false) {
this.size = size;
this.paths = paths;
this.matchTextDirection = matchTextDirection;
}
public readonly Size size;
public readonly List<_PathFrames> paths;
public override bool matchTextDirection { get; }
}
}

8
Samples/UIWidgetsGallery/demo/material.meta


fileFormatVersion: 2
guid: edc3bae86553f44c2b7e7fddbf6cb497
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

11
Samples/UIWidgetsGallery/demo/material/buttons_demo.cs.meta


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

382
Samples/UIWidgetsGallery/demo/material/buttons_demo.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.widgets;
namespace UIWidgetsGallery.gallery {
class ButtonsDemo : StatefulWidget {
public const string routeName = "/material/buttons";
public ButtonsDemo(Key key = null) : base(key: key) {
}
public override State createState() {
return new _ButtonsDemoState();
}
}
class _ButtonsDemoState : State<ButtonsDemo> {
const string _raisedText =
"Raised buttons add dimension to mostly flat layouts. They emphasize " +
"functions on busy or wide spaces.";
const string _raisedCode = "buttons_raised";
const string _flatText = "A flat button displays an ink splash on press " +
"but does not lift. Use flat buttons on toolbars, in dialogs and " +
"inline with padding";
const string _flatCode = "buttons_flat";
const string _outlineText =
"Outline buttons become opaque and elevate when pressed. They are often " +
"paired with raised buttons to indicate an alternative, secondary action.";
const string _outlineCode = "buttons_outline";
const string _dropdownText =
"A dropdown button displays a menu that's used to select a value from a " +
"small set of values. The button displays the current value and a down " +
"arrow.";
const string _dropdownCode = "buttons_dropdown";
const string _iconText =
"IconButtons are appropriate for toggle buttons that allow a single choice " +
"to be selected or deselected, such as adding or removing an item's star.";
const string _iconCode = "buttons_icon";
const string _actionText =
"Floating action buttons are used for a promoted action. They are " +
"distinguished by a circled icon floating above the UI and can have motion " +
"behaviors that include morphing, launching, and a transferring anchor " +
"point.";
const string _actionCode = "buttons_action";
ShapeBorder _buttonShape;
public _ButtonsDemoState() {
}
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context).copyWith(
shape: this._buttonShape
);
List<ComponentDemoTabData> demos = new List<ComponentDemoTabData> {
new ComponentDemoTabData(
tabName: "RAISED",
description: _raisedText,
demoWidget: ButtonTheme.fromButtonThemeData(
data: buttonTheme,
child: this.buildRaisedButton()
),
exampleCodeTag: _raisedCode,
documentationUrl: "https://docs.flutter.io/flutter/material/RaisedButton-class.html"
),
new ComponentDemoTabData(
tabName: "FLAT",
description: _flatText,
demoWidget: ButtonTheme.fromButtonThemeData(
data: buttonTheme,
child: this.buildFlatButton()
),
exampleCodeTag: _flatCode,
documentationUrl: "https://docs.flutter.io/flutter/material/FlatButton-class.html"
),
new ComponentDemoTabData(
tabName: "OUTLINE",
description: _outlineText,
demoWidget: ButtonTheme.fromButtonThemeData(
data: buttonTheme,
child: this.buildOutlineButton()
),
exampleCodeTag: _outlineCode,
documentationUrl: "https://docs.flutter.io/flutter/material/OutlineButton-class.html"
),
new ComponentDemoTabData(
tabName: "DROPDOWN",
description: _dropdownText,
demoWidget: this.buildDropdownButton(),
exampleCodeTag: _dropdownCode,
documentationUrl: "https://docs.flutter.io/flutter/material/DropdownButton-class.html"
),
new ComponentDemoTabData(
tabName: "ICON",
description: _iconText,
demoWidget: this.buildIconButton(),
exampleCodeTag: _iconCode,
documentationUrl: "https://docs.flutter.io/flutter/material/IconButton-class.html"
),
new ComponentDemoTabData(
tabName: "ACTION",
description: _actionText,
demoWidget: this.buildActionButton(),
exampleCodeTag: _actionCode,
documentationUrl: "https://docs.flutter.io/flutter/material/FloatingActionButton-class.html"
)
};
return new TabbedComponentDemoScaffold(
title: "Buttons",
demos: demos,
actions: new List<Widget> {
new IconButton(
icon: new Icon(Icons.sentiment_very_satisfied),
onPressed: () => {
this.setState(() => {
this._buttonShape = this._buttonShape == null ? new StadiumBorder() : null;
});
}
)
}
);
}
public Widget buildRaisedButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new RaisedButton(
child: new Text("RAISED BUTTON"),
onPressed: () => {
// Perform some action
}
),
new RaisedButton(
child: new Text("DISABLED"),
onPressed: null
)
}
),
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
RaisedButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("RAISED BUTTON"),
onPressed: () => {
// Perform some action
}
),
RaisedButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("DISABLED"),
onPressed: null
)
}
)
}
)
);
}
public Widget buildFlatButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new FlatButton(
child: new Text("FLAT BUTTON"),
onPressed: () => {
// Perform some action
}
),
new FlatButton(
child: new Text("DISABLED"),
onPressed: null
)
}
),
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
FlatButton.icon(
icon: new Icon(Icons.add_circle_outline, size: 18.0f),
label: new Text("FLAT BUTTON"),
onPressed: () => {
// Perform some action
}
),
FlatButton.icon(
icon: new Icon(Icons.add_circle_outline, size: 18.0f),
label: new Text("DISABLED"),
onPressed: null
),
}
)
}
)
);
}
Widget buildOutlineButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new OutlineButton(
child: new Text("OUTLINE BUTTON"),
onPressed: () => {
// Perform some action
}
),
new OutlineButton(
child: new Text("DISABLED"),
onPressed: null
)
}
),
new ButtonBar(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
OutlineButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("OUTLINE BUTTON"),
onPressed: () => {
// Perform some action
}
),
OutlineButton.icon(
icon: new Icon(Icons.add, size: 18.0f),
label: new Text("DISABLED"),
onPressed: null
)
}
)
}
)
);
}
// https://en.wikipedia.org/wiki/Free_Four
string dropdown1Value = "Free";
string dropdown2Value;
string dropdown3Value = "Four";
public Widget buildDropdownButton() {
return new Padding(
padding: EdgeInsets.all(24.0f),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: new List<Widget> {
new ListTile(
title: new Text("Simple dropdown:"),
trailing: new DropdownButton<string>(
value: this.dropdown1Value,
onChanged: (string newValue) => {
this.setState(() => { this.dropdown1Value = newValue; });
},
items: new List<string> {"One", "Two", "Free", "Four"}.Select((string value) => {
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).ToList()
)
),
new SizedBox(
height: 24.0f
),
new ListTile(
title: new Text("Dropdown with a hint:"),
trailing: new DropdownButton<string>(
value: this.dropdown2Value,
hint: new Text("Choose"),
onChanged: (string newValue) => {
this.setState(() => { this.dropdown2Value = newValue; });
},
items: new List<string> {"One", "Two", "Free", "Four"}.Select((string value) => {
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).ToList()
)
),
new SizedBox(
height: 24.0f
),
new ListTile(
title: new Text("Scrollable dropdown:"),
trailing: new DropdownButton<string>(
value: this.dropdown3Value,
onChanged: (string newValue) => {
this.setState(() => { this.dropdown3Value = newValue; });
},
items: new List<string> {
"One", "Two", "Free", "Four", "Can", "I", "Have", "A", "Little",
"Bit", "More", "Five", "Six", "Seven", "Eight", "Nine", "Ten"
}.Select<string, DropdownMenuItem<string>>(value => {
return new DropdownMenuItem<string>(
value: value,
child: new Text(value)
);
}).ToList()
)
)
}
)
);
}
bool iconButtonToggle = false;
public Widget buildIconButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
new IconButton(
icon: new Icon(
Icons.thumb_up
),
onPressed: () => { this.setState(() => this.iconButtonToggle = !this.iconButtonToggle); },
color: this.iconButtonToggle ? Theme.of(this.context).primaryColor : null
),
new IconButton(
icon: new Icon(
Icons.thumb_up
),
onPressed: null
)
}.Select<Widget, Widget>(
(Widget button) => new SizedBox(width: 64.0f, height: 64.0f, child: button)).ToList()
)
);
}
public Widget buildActionButton() {
return new Align(
alignment: new Alignment(0.0f, -0.2f),
child: new FloatingActionButton(
child: new Icon(Icons.add),
onPressed: () => {
// Perform some action
},
tooltip: "floating action button"
)
);
}
}
}

172
Samples/UIWidgetsGallery/demo/colors_demo.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsGallery.gallery {
class ColorDemoConstants {
public const float kColorItemHeight = 48.0f;
public static readonly List<Palette> allPalettes = new List<Palette> {
new Palette(name: "RED", primary: Colors.red, accent: Colors.redAccent, threshold: 300),
new Palette(name: "PINK", primary: Colors.pink, accent: Colors.pinkAccent, threshold: 200),
new Palette(name: "PURPLE", primary: Colors.purple, accent: Colors.purpleAccent, threshold: 200),
new Palette(name: "DEEP PURPLE", primary: Colors.deepPurple, accent: Colors.deepPurpleAccent,
threshold: 200),
new Palette(name: "INDIGO", primary: Colors.indigo, accent: Colors.indigoAccent, threshold: 200),
new Palette(name: "BLUE", primary: Colors.blue, accent: Colors.blueAccent, threshold: 400),
new Palette(name: "LIGHT BLUE", primary: Colors.lightBlue, accent: Colors.lightBlueAccent, threshold: 500),
new Palette(name: "CYAN", primary: Colors.cyan, accent: Colors.cyanAccent, threshold: 600),
new Palette(name: "TEAL", primary: Colors.teal, accent: Colors.tealAccent, threshold: 400),
new Palette(name: "GREEN", primary: Colors.green, accent: Colors.greenAccent, threshold: 500),
new Palette(name: "LIGHT GREEN", primary: Colors.lightGreen, accent: Colors.lightGreenAccent,
threshold: 600),
new Palette(name: "LIME", primary: Colors.lime, accent: Colors.limeAccent, threshold: 800),
new Palette(name: "YELLOW", primary: Colors.yellow, accent: Colors.yellowAccent),
new Palette(name: "AMBER", primary: Colors.amber, accent: Colors.amberAccent),
new Palette(name: "ORANGE", primary: Colors.orange, accent: Colors.orangeAccent, threshold: 700),
new Palette(name: "DEEP ORANGE", primary: Colors.deepOrange, accent: Colors.deepOrangeAccent,
threshold: 400),
new Palette(name: "BROWN", primary: Colors.brown, threshold: 200),
new Palette(name: "GREY", primary: Colors.grey, threshold: 500),
new Palette(name: "BLUE GREY", primary: Colors.blueGrey, threshold: 500),
};
}
public class Palette {
public Palette(string name = null, MaterialColor primary = null, MaterialAccentColor accent = null,
int threshold = 900) {
this.name = name;
this.primary = primary;
this.accent = accent;
this.threshold = threshold;
}
public readonly string name;
public readonly MaterialColor primary;
public readonly MaterialAccentColor accent;
public readonly int threshold;
public bool isValid {
get { return this.name != null && this.primary != null && this.threshold != null; }
}
}
public class ColorItem : StatelessWidget {
public ColorItem(
Key key = null,
int? index = null,
Color color = null,
string prefix = ""
) : base(key: key) {
D.assert(index != null);
D.assert(color != null);
D.assert(prefix != null);
this.index = index;
this.color = color;
this.prefix = prefix;
}
public readonly int? index;
public readonly Color color;
public readonly string prefix;
string colorString() {
return $"#{this.color.value.ToString("X8").ToUpper()}";
}
public override Widget build(BuildContext context) {
return new Container(
height: ColorDemoConstants.kColorItemHeight,
padding: EdgeInsets.symmetric(horizontal: 16.0f),
color: this.color,
child: new SafeArea(
top: false,
bottom: false,
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget> {
new Text($"{this.prefix}{this.index}"),
new Text(this.colorString())
}
)
)
);
}
}
public class PaletteTabView : StatelessWidget {
public PaletteTabView(
Key key = null,
Palette colors = null
) : base(key: key) {
D.assert(colors != null && colors.isValid);
this.colors = colors;
}
public readonly Palette colors;
public readonly static List<int> primaryKeys = new List<int> {50, 100, 200, 300, 400, 500, 600, 700, 800, 900};
public readonly static List<int> accentKeys = new List<int> {100, 200, 400, 700};
public override Widget build(BuildContext context) {
TextTheme textTheme = Theme.of(context).textTheme;
TextStyle whiteTextStyle = textTheme.body1.copyWith(color: Colors.white);
TextStyle blackTextStyle = textTheme.body1.copyWith(color: Colors.black);
List<Widget> colorItems = primaryKeys.Select<int, Widget>((int index) => {
return new DefaultTextStyle(
style: index > this.colors.threshold ? whiteTextStyle : blackTextStyle,
child: new ColorItem(index: index, color: this.colors.primary[index])
);
}).ToList();
if (this.colors.accent != null) {
colorItems.AddRange(accentKeys.Select<int, Widget>((int index) => {
return new DefaultTextStyle(
style: index > this.colors.threshold ? whiteTextStyle : blackTextStyle,
child: new ColorItem(index: index, color: this.colors.accent[index], prefix: "A")
);
}).ToList());
}
return new ListView(
itemExtent: ColorDemoConstants.kColorItemHeight,
children: colorItems
);
}
}
public class ColorsDemo : StatelessWidget {
public const string routeName = "/colors";
public override Widget build(BuildContext context) {
return new DefaultTabController(
length: ColorDemoConstants.allPalettes.Count,
child: new Scaffold(
appBar: new AppBar(
elevation: 0.0f,
title: new Text("Colors"),
bottom: new TabBar(
isScrollable: true,
tabs: ColorDemoConstants.allPalettes
.Select<Palette, Widget>((Palette swatch) => new Tab(text: swatch.name)).ToList()
)
),
body: new TabBarView(
children: ColorDemoConstants.allPalettes.Select<Palette, Widget>((Palette colors) => {
return new PaletteTabView(colors: colors);
}).ToList()
)
)
);
}
}
}

11
Samples/UIWidgetsGallery/demo/colors_demo.cs.meta


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

7
Samples/UIWidgetsGallery/main.cs


using Unity.UIWidgets.engine;
namespace UIWidgetsGallery {
public class GalleryMain : UIWidgetsPanel {
}
}

/Samples/UIWidgetsGallery/main.cs.meta → /Samples/UIWidgetsGallery/GalleryMain.cs.meta

正在加载...
取消
保存