浏览代码
Merge branch 'kgdev' into 'master'
Merge branch 'kgdev' into 'master'
more materials. See merge request upm-packages/ui-widgets/com.unity.uiwidgets!102/main
Xingwei Zhu
6 年前
当前提交
2d79eef4
共有 33 个文件被更改,包括 3033 次插入 和 59 次删除
-
10Runtime/material/constants.cs
-
53Runtime/material/debug.cs
-
5Runtime/material/dialog.cs
-
2Runtime/material/drawer_header.cs
-
2Runtime/material/expand_icon.cs
-
2Runtime/material/icon_button.cs
-
2Runtime/material/ink_decoration.cs
-
2Runtime/material/ink_well.cs
-
2Runtime/material/list_tile.cs
-
4Runtime/material/page.cs
-
20Runtime/material/theme_data.cs
-
1Runtime/painting/image_resolution.cs
-
4Runtime/ui/geometry.cs
-
67Runtime/widgets/basic.cs
-
30Runtime/widgets/debug.cs
-
4Runtime/widgets/pages.cs
-
11Runtime/widgets/routes.cs
-
1Samples/UIWidgetSample/NavigationSample.cs
-
21Samples/UIWidgetsGallery/gallery/app.cs
-
17Samples/UIWidgetsGallery/gallery/demos.cs
-
365Samples/UIWidgetsGallery/gallery/options.cs
-
390Runtime/material/material_localizations.cs
-
11Runtime/material/material_localizations.cs.meta
-
608Runtime/material/popup_menu.cs
-
11Runtime/material/popup_menu.cs.meta
-
527Runtime/material/switch.cs
-
11Runtime/material/switch.cs.meta
-
153Runtime/material/timer.cs
-
11Runtime/material/timer.cs.meta
-
323Runtime/widgets/localizations.cs
-
11Runtime/widgets/localizations.cs.meta
-
400Samples/UIWidgetsGallery/gallery/home.cs
-
11Samples/UIWidgetsGallery/gallery/home.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using RSG; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public abstract class MaterialLocalizations { |
|||
public abstract string openAppDrawerTooltip { get; } |
|||
public abstract string backButtonTooltip { get; } |
|||
public abstract string closeButtonTooltip { get; } |
|||
public abstract string deleteButtonTooltip { get; } |
|||
public abstract string nextMonthTooltip { get; } |
|||
public abstract string previousMonthTooltip { get; } |
|||
public abstract string nextPageTooltip { get; } |
|||
public abstract string previousPageTooltip { get; } |
|||
public abstract string showMenuTooltip { get; } |
|||
public abstract string aboutListTileTitle(string applicationName); |
|||
public abstract string licensesPageTitle { get; } |
|||
public abstract string pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate); |
|||
public abstract string rowsPerPageTitle { get; } |
|||
public abstract string tabLabel(int tabIndex, int tabCount); |
|||
public abstract string selectedRowCountTitle(int selectedRowCount); |
|||
public abstract string cancelButtonLabel { get; } |
|||
public abstract string closeButtonLabel { get; } |
|||
public abstract string continueButtonLabel { get; } |
|||
public abstract string copyButtonLabel { get; } |
|||
public abstract string cutButtonLabel { get; } |
|||
public abstract string okButtonLabel { get; } |
|||
public abstract string pasteButtonLabel { get; } |
|||
public abstract string selectAllButtonLabel { get; } |
|||
public abstract string viewLicensesButtonLabel { get; } |
|||
|
|||
public abstract string anteMeridiemAbbreviation { get; } |
|||
|
|||
public abstract string postMeridiemAbbreviation { get; } |
|||
|
|||
public abstract string searchFieldLabel { get; } |
|||
|
|||
public abstract TimeOfDayFormat timeOfDayFormat(bool alwaysUse24HourFormat = false); |
|||
|
|||
public abstract ScriptCategory scriptCategory { get; } |
|||
|
|||
public abstract string formatDecimal(int number); |
|||
|
|||
public abstract string formatHour(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false); |
|||
|
|||
public abstract string formatMinute(TimeOfDay timeOfDay); |
|||
|
|||
public abstract string formatTimeOfDay(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false); |
|||
|
|||
public abstract string formatYear(DateTime date); |
|||
|
|||
public abstract string formatMediumDate(DateTime date); |
|||
|
|||
public abstract string formatFullDate(DateTime date); |
|||
|
|||
public abstract string formatMonthYear(DateTime date); |
|||
|
|||
public abstract List<string> narrowWeekdays { get; } |
|||
|
|||
public abstract int firstDayOfWeekIndex { get; } |
|||
|
|||
public static MaterialLocalizations of(BuildContext context) { |
|||
return Localizations.of<MaterialLocalizations>(context, typeof(MaterialLocalizations)); |
|||
} |
|||
} |
|||
|
|||
class _MaterialLocalizationsDelegate : LocalizationsDelegate<MaterialLocalizations> { |
|||
public _MaterialLocalizationsDelegate() { |
|||
} |
|||
|
|||
public override bool isSupported(Locale locale) { |
|||
return locale.languageCode == "en"; |
|||
} |
|||
|
|||
public override IPromise<object> load(Locale locale) { |
|||
return DefaultMaterialLocalizations.load(locale); |
|||
} |
|||
|
|||
public override bool shouldReload(LocalizationsDelegate old) { |
|||
return false; |
|||
} |
|||
|
|||
public override string ToString() { |
|||
return "DefaultMaterialLocalizations.delegate(en_US)"; |
|||
} |
|||
} |
|||
|
|||
public class DefaultMaterialLocalizations : MaterialLocalizations { |
|||
public DefaultMaterialLocalizations() { |
|||
} |
|||
|
|||
static readonly List<string> _shortWeekdays = new List<string>() { |
|||
"Mon", |
|||
"Tue", |
|||
"Wed", |
|||
"Thu", |
|||
"Fri", |
|||
"Sat", |
|||
"Sun", |
|||
}; |
|||
|
|||
static readonly List<String> _weekdays = new List<string>() { |
|||
"Monday", |
|||
"Tuesday", |
|||
"Wednesday", |
|||
"Thursday", |
|||
"Friday", |
|||
"Saturday", |
|||
"Sunday", |
|||
}; |
|||
|
|||
static readonly List<String> _narrowWeekdays = new List<string>() { |
|||
"S", |
|||
"M", |
|||
"T", |
|||
"W", |
|||
"T", |
|||
"F", |
|||
"S", |
|||
}; |
|||
|
|||
static readonly List<String> _shortMonths = new List<string>() { |
|||
"Jan", |
|||
"Feb", |
|||
"Mar", |
|||
"Apr", |
|||
"May", |
|||
"Jun", |
|||
"Jul", |
|||
"Aug", |
|||
"Sep", |
|||
"Oct", |
|||
"Nov", |
|||
"Dec", |
|||
}; |
|||
|
|||
static readonly List<String> _months = new List<string>() { |
|||
"January", |
|||
"February", |
|||
"March", |
|||
"April", |
|||
"May", |
|||
"June", |
|||
"July", |
|||
"August", |
|||
"September", |
|||
"October", |
|||
"November", |
|||
"December", |
|||
}; |
|||
|
|||
public override string formatHour(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false) { |
|||
TimeOfDayFormat format = this.timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat); |
|||
switch (format) { |
|||
case TimeOfDayFormat.h_colon_mm_space_a: |
|||
return this.formatDecimal(timeOfDay.hourOfPeriod == 0 ? 12 : timeOfDay.hourOfPeriod); |
|||
case TimeOfDayFormat.HH_colon_mm: |
|||
return this._formatTwoDigitZeroPad(timeOfDay.hour); |
|||
default: |
|||
throw new AssertionError($"runtimeType does not support {format}."); |
|||
} |
|||
} |
|||
|
|||
string _formatTwoDigitZeroPad(int number) { |
|||
D.assert(0 <= number && number < 100); |
|||
|
|||
if (number < 10) { |
|||
return "0" + number; |
|||
} |
|||
|
|||
return number.ToString(); |
|||
} |
|||
|
|||
public override string formatMinute(TimeOfDay timeOfDay) { |
|||
int minute = timeOfDay.minute; |
|||
return minute < 10 ? "0" + minute : minute.ToString(); |
|||
} |
|||
|
|||
public override string formatYear(DateTime date) { |
|||
return date.Year.ToString(); |
|||
} |
|||
|
|||
public override string formatMediumDate(DateTime date) { |
|||
string day = _shortWeekdays[((int) date.DayOfWeek + 6) % 7]; |
|||
string month = _shortMonths[date.Month - 1]; |
|||
return $"{day}, {month} ${date.Day}"; |
|||
} |
|||
|
|||
public override string formatFullDate(DateTime date) { |
|||
string month = _months[date.Month - 1]; |
|||
return $"{_weekdays[((int) date.DayOfWeek + 6) % 7]}, {month} {date.Day}, {date.Year}"; |
|||
} |
|||
|
|||
public override string formatMonthYear(DateTime date) { |
|||
string year = this.formatYear(date); |
|||
string month = _months[date.Month - 1]; |
|||
return $"{month} {year}"; |
|||
} |
|||
|
|||
public override List<string> narrowWeekdays { |
|||
get { return _narrowWeekdays; } |
|||
} |
|||
|
|||
public override int firstDayOfWeekIndex { |
|||
get { return 0; } |
|||
} |
|||
|
|||
string _formatDayPeriod(TimeOfDay timeOfDay) { |
|||
switch (timeOfDay.period) { |
|||
case DayPeriod.am: |
|||
return this.anteMeridiemAbbreviation; |
|||
case DayPeriod.pm: |
|||
return this.postMeridiemAbbreviation; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public override string formatDecimal(int number) { |
|||
if (number > -1000 && number < 1000) { |
|||
return number.ToString(); |
|||
} |
|||
|
|||
string digits = number.abs().ToString(); |
|||
StringBuilder result = new StringBuilder(number < 0 ? "-" : ""); |
|||
int maxDigitIndex = digits.Length - 1; |
|||
for (int i = 0; i <= maxDigitIndex; i += 1) { |
|||
result.Append(digits[i]); |
|||
if (i < maxDigitIndex && (maxDigitIndex - i) % 3 == 0) { |
|||
result.Append(','); |
|||
} |
|||
} |
|||
return result.ToString(); |
|||
} |
|||
|
|||
public override string formatTimeOfDay(TimeOfDay timeOfDay, bool alwaysUse24HourFormat = false) { |
|||
StringBuilder buffer = new StringBuilder(); |
|||
|
|||
buffer.Append(this.formatHour(timeOfDay, alwaysUse24HourFormat: alwaysUse24HourFormat)); |
|||
buffer.Append(":"); |
|||
buffer.Append(this.formatMinute(timeOfDay)); |
|||
|
|||
if (alwaysUse24HourFormat) { |
|||
return buffer.ToString(); |
|||
} |
|||
|
|||
buffer.Append(" "); |
|||
buffer.Append(this._formatDayPeriod(timeOfDay)); |
|||
return buffer.ToString(); |
|||
} |
|||
|
|||
public override string openAppDrawerTooltip { |
|||
get { return "Open navigation menu"; } |
|||
} |
|||
|
|||
public override string backButtonTooltip { |
|||
get { return "Back"; } |
|||
} |
|||
|
|||
public override string closeButtonTooltip { |
|||
get { return "Close"; } |
|||
} |
|||
|
|||
public override string deleteButtonTooltip { |
|||
get { return "Delete"; } |
|||
} |
|||
|
|||
public override string nextMonthTooltip { |
|||
get { return "Next month"; } |
|||
} |
|||
|
|||
public override string previousMonthTooltip { |
|||
get { return "Previous month"; } |
|||
} |
|||
|
|||
public override string nextPageTooltip { |
|||
get { return "Next page"; } |
|||
} |
|||
|
|||
public override string previousPageTooltip { |
|||
get { return "Previous page"; } |
|||
} |
|||
|
|||
public override string showMenuTooltip { |
|||
get { return "Show menu"; } |
|||
} |
|||
|
|||
public override string searchFieldLabel { |
|||
get { return "Search"; } |
|||
} |
|||
|
|||
public override string aboutListTileTitle(string applicationName) { |
|||
return "About " + applicationName; |
|||
} |
|||
|
|||
public override string licensesPageTitle { |
|||
get { return "Licenses"; } |
|||
} |
|||
|
|||
public override string pageRowsInfoTitle(int firstRow, int lastRow, int rowCount, bool rowCountIsApproximate) { |
|||
return rowCountIsApproximate |
|||
? $"{firstRow}–{lastRow} of about {rowCount}" |
|||
: $"{firstRow}–{lastRow} of {rowCount}"; |
|||
} |
|||
|
|||
public override string rowsPerPageTitle { |
|||
get { return "Rows per page:"; } |
|||
} |
|||
|
|||
public override string tabLabel(int tabIndex, int tabCount) { |
|||
D.assert(tabIndex >= 1); |
|||
D.assert(tabCount >= 1); |
|||
return $"Tab {tabIndex} of {tabCount}"; |
|||
} |
|||
|
|||
public override string selectedRowCountTitle(int selectedRowCount) { |
|||
switch (selectedRowCount) { |
|||
case 0: |
|||
return "No items selected"; |
|||
case 1: |
|||
return "1 item selected"; |
|||
default: |
|||
return selectedRowCount + " items selected"; |
|||
} |
|||
} |
|||
|
|||
public override string cancelButtonLabel { |
|||
get { return "CANCEL"; } |
|||
} |
|||
|
|||
public override string closeButtonLabel { |
|||
get { return "CLOSE"; } |
|||
} |
|||
|
|||
public override string continueButtonLabel { |
|||
get { return "CONTINUE"; } |
|||
} |
|||
|
|||
public override string copyButtonLabel { |
|||
get { return "COPY"; } |
|||
} |
|||
|
|||
public override string cutButtonLabel { |
|||
get { return "CUT"; } |
|||
} |
|||
|
|||
public override string okButtonLabel { |
|||
get { return "OK"; } |
|||
} |
|||
|
|||
public override string pasteButtonLabel { |
|||
get { return "PASTE"; } |
|||
} |
|||
|
|||
public override string selectAllButtonLabel { |
|||
get { return "SELECT ALL"; } |
|||
} |
|||
|
|||
public override string viewLicensesButtonLabel { |
|||
get { return "VIEW LICENSES"; } |
|||
} |
|||
|
|||
public override string anteMeridiemAbbreviation { |
|||
get { return "AM"; } |
|||
} |
|||
|
|||
public override string postMeridiemAbbreviation { |
|||
get { return "PM"; } |
|||
} |
|||
|
|||
public override ScriptCategory scriptCategory { |
|||
get { return ScriptCategory.englishLike; } |
|||
} |
|||
|
|||
public override TimeOfDayFormat timeOfDayFormat(bool alwaysUse24HourFormat = false) { |
|||
return alwaysUse24HourFormat |
|||
? TimeOfDayFormat.HH_colon_mm |
|||
: TimeOfDayFormat.h_colon_mm_space_a; |
|||
} |
|||
|
|||
public static IPromise<object> load(Locale locale) { |
|||
return Promise<object>.Resolved(new DefaultMaterialLocalizations()); |
|||
} |
|||
|
|||
public static readonly LocalizationsDelegate<MaterialLocalizations> del = new _MaterialLocalizationsDelegate(); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d140c1ef287754af7adf006964153c07 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using RSG; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
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 Rect = Unity.UIWidgets.ui.Rect; |
|||
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; |
|||
internal const float _kMenuCloseIntervalEnd = 2.0f / 3.0f; |
|||
internal const float _kMenuHorizontalPadding = 16.0f; |
|||
internal const float _kMenuItemHeight = 48.0f; |
|||
internal const float _kMenuDividerHeight = 16.0f; |
|||
internal const float _kMenuMaxWidth = 5.0f * _kMenuWidthStep; |
|||
internal const float _kMenuMinWidth = 2.0f * _kMenuWidthStep; |
|||
internal const float _kMenuVerticalPadding = 8.0f; |
|||
internal const float _kMenuWidthStep = 56.0f; |
|||
internal const float _kMenuScreenPadding = 8.0f; |
|||
} |
|||
|
|||
public abstract class PopupMenuEntry<T> : StatefulWidget { |
|||
protected PopupMenuEntry(Key key = null) : base(key: key) { |
|||
} |
|||
|
|||
public abstract float height { get; } |
|||
|
|||
public abstract bool represents(T value); |
|||
} |
|||
|
|||
|
|||
public class PopupMenuDivider : PopupMenuEntry<object> { |
|||
public PopupMenuDivider(Key key = null, float height = PopupMenuUtils._kMenuDividerHeight) : base(key: key) { |
|||
this._height = height; |
|||
|
|||
} |
|||
|
|||
readonly float _height; |
|||
|
|||
public override float height { |
|||
get { return this._height; } |
|||
} |
|||
|
|||
public override bool represents(object value) { |
|||
return false; |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _PopupMenuDividerState(); |
|||
} |
|||
} |
|||
|
|||
class _PopupMenuDividerState : State<PopupMenuDivider> { |
|||
public override Widget build(BuildContext context) { |
|||
return new Divider(height: this.widget.height); |
|||
} |
|||
} |
|||
|
|||
public class PopupMenuItem<T> : PopupMenuEntry<T> { |
|||
public PopupMenuItem( |
|||
Key key = null, |
|||
T value = default, |
|||
bool enabled = true, |
|||
float height = PopupMenuUtils._kMenuItemHeight, |
|||
Widget child = null |
|||
) : base(key: key) { |
|||
this.value = value; |
|||
this.enabled = enabled; |
|||
this._height = height; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly T value; |
|||
|
|||
public readonly bool enabled; |
|||
|
|||
readonly float _height; |
|||
|
|||
public override float height { |
|||
get { return this._height; } |
|||
} |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public override bool represents(T value) { |
|||
return Equals(value, this.value); |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new PopupMenuItemState<T, PopupMenuItem<T>>(); |
|||
} |
|||
} |
|||
|
|||
public class PopupMenuItemState<T, W> : State<W> where W : PopupMenuItem<T> { |
|||
protected virtual Widget buildChild() { |
|||
return this.widget.child; |
|||
} |
|||
|
|||
protected virtual void handleTap() { |
|||
Navigator.pop(this.context, this.widget.value); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
ThemeData theme = Theme.of(context); |
|||
TextStyle style = theme.textTheme.subhead; |
|||
if (!this.widget.enabled) { |
|||
style = style.copyWith(color: theme.disabledColor); |
|||
} |
|||
|
|||
Widget item = new AnimatedDefaultTextStyle( |
|||
style: style, |
|||
duration: Constants.kThemeChangeDuration, |
|||
child: new Baseline( |
|||
baseline: this.widget.height - PopupMenuUtils._kBaselineOffsetFromBottom, |
|||
baselineType: style.textBaseline, |
|||
child: this.buildChild() |
|||
) |
|||
); |
|||
|
|||
if (!this.widget.enabled) { |
|||
bool isDark = theme.brightness == Brightness.dark; |
|||
item = IconTheme.merge( |
|||
data: new IconThemeData(opacity: isDark ? 0.5f : 0.38f), |
|||
child: item |
|||
); |
|||
} |
|||
|
|||
return new InkWell( |
|||
onTap: this.widget.enabled ? this.handleTap : (GestureTapCallback) null, |
|||
child: new Container( |
|||
height: this.widget.height, |
|||
padding: EdgeInsets.symmetric(horizontal: PopupMenuUtils._kMenuHorizontalPadding), |
|||
child: item |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class PopupMenuItemSingleTickerProviderState<T, W> : SingleTickerProviderStateMixin<W> |
|||
where W : PopupMenuItem<T> { |
|||
protected virtual Widget buildChild() { |
|||
return this.widget.child; |
|||
} |
|||
|
|||
protected virtual void handleTap() { |
|||
Navigator.pop(this.context, this.widget.value); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
ThemeData theme = Theme.of(context); |
|||
TextStyle style = theme.textTheme.subhead; |
|||
if (!this.widget.enabled) { |
|||
style = style.copyWith(color: theme.disabledColor); |
|||
} |
|||
|
|||
Widget item = new AnimatedDefaultTextStyle( |
|||
style: style, |
|||
duration: Constants.kThemeChangeDuration, |
|||
child: new Baseline( |
|||
baseline: this.widget.height - PopupMenuUtils._kBaselineOffsetFromBottom, |
|||
baselineType: style.textBaseline, |
|||
child: this.buildChild() |
|||
) |
|||
); |
|||
|
|||
if (!this.widget.enabled) { |
|||
bool isDark = theme.brightness == Brightness.dark; |
|||
item = IconTheme.merge( |
|||
data: new IconThemeData(opacity: isDark ? 0.5f : 0.38f), |
|||
child: item |
|||
); |
|||
} |
|||
|
|||
return new InkWell( |
|||
onTap: this.widget.enabled ? this.handleTap : (GestureTapCallback) null, |
|||
child: new Container( |
|||
height: this.widget.height, |
|||
padding: EdgeInsets.symmetric(horizontal: PopupMenuUtils._kMenuHorizontalPadding), |
|||
child: item |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class CheckedPopupMenuItem<T> : PopupMenuItem<T> { |
|||
public CheckedPopupMenuItem( |
|||
Key key = null, |
|||
T value = default, |
|||
bool isChecked = false, |
|||
bool enabled = true, |
|||
Widget child = null |
|||
) : base( |
|||
key: key, |
|||
value: value, |
|||
enabled: enabled, |
|||
child: child |
|||
) { |
|||
this.isChecked = isChecked; |
|||
} |
|||
|
|||
public readonly bool isChecked; |
|||
|
|||
public override State createState() { |
|||
return new _CheckedPopupMenuItemState<T>(); |
|||
} |
|||
} |
|||
|
|||
class _CheckedPopupMenuItemState<T> : PopupMenuItemSingleTickerProviderState<T, CheckedPopupMenuItem<T>> { |
|||
static readonly TimeSpan _fadeDuration = new TimeSpan(0, 0, 0, 0, 150); |
|||
|
|||
AnimationController _controller; |
|||
|
|||
Animation<float> _opacity { |
|||
get { return this._controller.view; } |
|||
} |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this._controller = new AnimationController(duration: _fadeDuration, vsync: this); |
|||
this._controller.setValue(this.widget.isChecked ? 1.0f : 0.0f); |
|||
this._controller.addListener(() => this.setState(() => { |
|||
/* animation changed */ |
|||
})); |
|||
} |
|||
|
|||
protected override void handleTap() { |
|||
if (this.widget.isChecked) { |
|||
this._controller.reverse(); |
|||
} else { |
|||
this._controller.forward(); |
|||
} |
|||
base.handleTap(); |
|||
} |
|||
|
|||
protected override Widget buildChild() { |
|||
return new ListTile( |
|||
enabled: this.widget.enabled, |
|||
leading: new FadeTransition( |
|||
opacity: this._opacity, |
|||
child: new Icon(this._controller.isDismissed ? null : Icons.done) |
|||
), |
|||
title: this.widget.child |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _PopupMenu<T> : StatelessWidget { |
|||
public _PopupMenu( |
|||
Key key = null, |
|||
_PopupMenuRoute<T> route = null |
|||
) : base(key: key) { |
|||
this.route = route; |
|||
} |
|||
|
|||
public readonly _PopupMenuRoute<T> route; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
float unit = 1.0f / (this.route.items.Count + 1.5f); |
|||
List<Widget> children = new List<Widget>(); |
|||
|
|||
for (int i = 0; i < this.route.items.Count; i += 1) { |
|||
float start = (i + 1) * unit; |
|||
float end = (start + 1.5f * unit).clamp(0.0f, 1.0f); |
|||
Widget item = this.route.items[i]; |
|||
if (this.route.initialValue != null && this.route.items[i].represents((T) this.route.initialValue)) { |
|||
item = new Container( |
|||
color: Theme.of(context).highlightColor, |
|||
child: item |
|||
); |
|||
} |
|||
children.Add(new FadeTransition( |
|||
opacity: new CurvedAnimation( |
|||
parent: this.route.animation, |
|||
curve: new Interval(start, end) |
|||
), |
|||
child: item |
|||
)); |
|||
} |
|||
|
|||
CurveTween opacity = new CurveTween(curve: new Interval(0.0f, 1.0f / 3.0f)); |
|||
CurveTween width = new CurveTween(curve: new Interval(0.0f, unit)); |
|||
CurveTween height = new CurveTween(curve: new Interval(0.0f, unit * this.route.items.Count)); |
|||
|
|||
Widget child = new ConstrainedBox( |
|||
constraints: new BoxConstraints( |
|||
minWidth: PopupMenuUtils._kMenuMinWidth, |
|||
maxWidth: PopupMenuUtils._kMenuMaxWidth |
|||
), |
|||
child: new IntrinsicWidth( |
|||
stepWidth: PopupMenuUtils._kMenuWidthStep, |
|||
child: new SingleChildScrollView( |
|||
padding: EdgeInsets.symmetric( |
|||
vertical: PopupMenuUtils._kMenuVerticalPadding |
|||
), |
|||
child: new ListBody(children: children) |
|||
) |
|||
) |
|||
); |
|||
|
|||
return new AnimatedBuilder( |
|||
animation: this.route.animation, |
|||
builder: (_, builderChild) => { |
|||
return new Opacity( |
|||
opacity: opacity.evaluate(this.route.animation), |
|||
child: new Material( |
|||
type: MaterialType.card, |
|||
elevation: this.route.elevation, |
|||
child: new Align( |
|||
alignment: Alignment.topRight, |
|||
widthFactor: width.evaluate(this.route.animation), |
|||
heightFactor: height.evaluate(this.route.animation), |
|||
child: builderChild |
|||
) |
|||
) |
|||
); |
|||
}, |
|||
child: child |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _PopupMenuRouteLayout : SingleChildLayoutDelegate { |
|||
public _PopupMenuRouteLayout(RelativeRect position, float? selectedItemOffset) { |
|||
this.position = position; |
|||
this.selectedItemOffset = selectedItemOffset; |
|||
} |
|||
|
|||
public readonly RelativeRect position; |
|||
|
|||
public readonly float? selectedItemOffset; |
|||
|
|||
public override BoxConstraints getConstraintsForChild(BoxConstraints constraints) { |
|||
return BoxConstraints.loose(constraints.biggest - |
|||
new Offset( |
|||
PopupMenuUtils._kMenuScreenPadding * 2.0f, |
|||
PopupMenuUtils._kMenuScreenPadding * 2.0f)); |
|||
} |
|||
|
|||
public override Offset getPositionForChild(Size size, Size childSize) { |
|||
float y; |
|||
if (this.selectedItemOffset == null) { |
|||
y = this.position.top; |
|||
} else { |
|||
y = this.position.top + (size.height - this.position.top - this.position.bottom) / 2.0f - |
|||
this.selectedItemOffset.Value; |
|||
} |
|||
|
|||
float x; |
|||
if (this.position.left > this.position.right) { |
|||
x = size.width - this.position.right - childSize.width; |
|||
} else if (this.position.left < this.position.right) { |
|||
x = this.position.left; |
|||
} else { |
|||
x = this.position.left; |
|||
} |
|||
|
|||
if (x < PopupMenuUtils._kMenuScreenPadding) { |
|||
x = PopupMenuUtils._kMenuScreenPadding; |
|||
} else if (x + childSize.width > size.width - PopupMenuUtils._kMenuScreenPadding) { |
|||
x = size.width - childSize.width - PopupMenuUtils._kMenuScreenPadding; |
|||
} |
|||
|
|||
if (y < PopupMenuUtils._kMenuScreenPadding) { |
|||
y = PopupMenuUtils._kMenuScreenPadding; |
|||
} else if (y + childSize.height > size.height - PopupMenuUtils._kMenuScreenPadding) { |
|||
y = size.height - childSize.height - PopupMenuUtils._kMenuScreenPadding; |
|||
} |
|||
|
|||
return new Offset(x, y); |
|||
} |
|||
|
|||
public override bool shouldRelayout(SingleChildLayoutDelegate oldDelegate) { |
|||
return this.position != ((_PopupMenuRouteLayout) oldDelegate).position; |
|||
} |
|||
} |
|||
|
|||
class _PopupMenuRoute<T> : PopupRoute { |
|||
public _PopupMenuRoute( |
|||
RelativeRect position = null, |
|||
List<PopupMenuEntry<T>> items = null, |
|||
object initialValue = null, |
|||
float elevation = 8.0f, |
|||
ThemeData theme = null |
|||
) { |
|||
this.position = position; |
|||
this.items = items; |
|||
this.initialValue = initialValue; |
|||
this.elevation = elevation; |
|||
this.theme = theme; |
|||
} |
|||
|
|||
public readonly RelativeRect position; |
|||
public readonly List<PopupMenuEntry<T>> items; |
|||
public readonly object initialValue; |
|||
public readonly float elevation; |
|||
public readonly ThemeData theme; |
|||
|
|||
public override Animation<float> createAnimation() { |
|||
return new CurvedAnimation( |
|||
parent: base.createAnimation(), |
|||
curve: Curves.linear, |
|||
reverseCurve: new Interval(0.0f, PopupMenuUtils._kMenuCloseIntervalEnd) |
|||
); |
|||
} |
|||
|
|||
public override TimeSpan transitionDuration { |
|||
get { return PopupMenuUtils._kMenuDuration; } |
|||
} |
|||
|
|||
public override bool barrierDismissible { |
|||
get { return true; } |
|||
} |
|||
|
|||
public override Color barrierColor { |
|||
get { return null; } |
|||
} |
|||
|
|||
public override Widget buildPage(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) { |
|||
float? selectedItemOffset = null; |
|||
if (this.initialValue != null) { |
|||
float y = PopupMenuUtils._kMenuVerticalPadding; |
|||
foreach (PopupMenuEntry<T> entry in this.items) { |
|||
if (entry.represents((T) this.initialValue)) { |
|||
selectedItemOffset = y + entry.height / 2.0f; |
|||
break; |
|||
} |
|||
y += entry.height; |
|||
} |
|||
} |
|||
|
|||
Widget menu = new _PopupMenu<T>(route: this); |
|||
if (this.theme != null) { |
|||
menu = new Theme(data: this.theme, child: menu); |
|||
} |
|||
|
|||
return MediaQuery.removePadding( |
|||
context: context, |
|||
removeTop: true, |
|||
removeBottom: true, |
|||
removeLeft: true, |
|||
removeRight: true, |
|||
child: new Builder( |
|||
builder: _ => new CustomSingleChildLayout( |
|||
layoutDelegate: new _PopupMenuRouteLayout( |
|||
this.position, |
|||
selectedItemOffset |
|||
), |
|||
child: menu |
|||
)) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public static partial class PopupMenuUtils { |
|||
public static IPromise<T> showMenu<T>( |
|||
BuildContext context, |
|||
RelativeRect position, |
|||
List<PopupMenuEntry<T>> items, |
|||
T initialValue, |
|||
float elevation = 8.0f |
|||
) { |
|||
D.assert(context != null); |
|||
D.assert(items != null && items.isNotEmpty()); |
|||
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context)); |
|||
|
|||
return Navigator.push(context, new _PopupMenuRoute<T>( |
|||
position: position, |
|||
items: items, |
|||
initialValue: initialValue, |
|||
elevation: elevation, |
|||
theme: Theme.of(context, shadowThemeOnly: true) |
|||
)).Then(result => (T) result); |
|||
} |
|||
} |
|||
|
|||
public delegate void PopupMenuItemSelected<T>(T value); |
|||
|
|||
public delegate void PopupMenuCanceled(); |
|||
|
|||
public delegate List<PopupMenuEntry<T>> PopupMenuItemBuilder<T>(BuildContext context); |
|||
|
|||
public class PopupMenuButton<T> : StatefulWidget { |
|||
public PopupMenuButton( |
|||
Key key = null, |
|||
PopupMenuItemBuilder<T> itemBuilder = null, |
|||
T initialValue = default, |
|||
PopupMenuItemSelected<T> onSelected = null, |
|||
PopupMenuCanceled onCanceled = null, |
|||
string tooltip = null, |
|||
float elevation = 8.0f, |
|||
EdgeInsets padding = null, |
|||
Widget child = null, |
|||
Icon icon = null, |
|||
Offset offset = null |
|||
) : base(key: key) { |
|||
D.assert(itemBuilder != null); |
|||
D.assert(offset != null); |
|||
D.assert(!(child != null && icon != null)); |
|||
|
|||
this.itemBuilder = itemBuilder; |
|||
this.initialValue = initialValue; |
|||
this.onSelected = onSelected; |
|||
this.onCanceled = onCanceled; |
|||
this.tooltip = tooltip; |
|||
this.elevation = elevation; |
|||
this.padding = padding ?? EdgeInsets.all(8.0f); |
|||
this.child = child; |
|||
this.icon = icon; |
|||
this.offset = offset ?? Offset.zero; |
|||
} |
|||
|
|||
|
|||
public readonly PopupMenuItemBuilder<T> itemBuilder; |
|||
|
|||
public readonly T initialValue; |
|||
|
|||
public readonly PopupMenuItemSelected<T> onSelected; |
|||
|
|||
public readonly PopupMenuCanceled onCanceled; |
|||
|
|||
public readonly string tooltip; |
|||
|
|||
public readonly float elevation; |
|||
|
|||
public readonly EdgeInsets padding; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public readonly Icon icon; |
|||
|
|||
public readonly Offset offset; |
|||
|
|||
public override State createState() { |
|||
return new _PopupMenuButtonState<T>(); |
|||
} |
|||
} |
|||
|
|||
class _PopupMenuButtonState<T> : State<PopupMenuButton<T>> { |
|||
void showButtonMenu() { |
|||
RenderBox button = (RenderBox) this.context.findRenderObject(); |
|||
RenderBox overlay = (RenderBox) Overlay.of(this.context).context.findRenderObject(); |
|||
RelativeRect position = RelativeRect.fromRect( |
|||
Rect.fromPoints( |
|||
button.localToGlobal(this.widget.offset, ancestor: overlay), |
|||
button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay) |
|||
), |
|||
Offset.zero & overlay.size |
|||
); |
|||
PopupMenuUtils.showMenu<T>( |
|||
context: this.context, |
|||
elevation: this.widget.elevation, |
|||
items: this.widget.itemBuilder(this.context), |
|||
initialValue: this.widget.initialValue, |
|||
position: position |
|||
) |
|||
.Then(newValue => { |
|||
if (!this.mounted) { |
|||
return; |
|||
} |
|||
if (newValue == null) { |
|||
if (this.widget.onCanceled != null) { |
|||
this.widget.onCanceled(); |
|||
} |
|||
return; |
|||
} |
|||
if (this.widget.onSelected != null) { |
|||
this.widget.onSelected(newValue); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
Icon _getIcon(RuntimePlatform platform) { |
|||
switch (platform) { |
|||
case RuntimePlatform.IPhonePlayer: |
|||
return new Icon(Icons.more_horiz); |
|||
default: |
|||
return new Icon(Icons.more_vert); |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context)); |
|||
return this.widget.child != null |
|||
? (Widget) new InkWell( |
|||
onTap: this.showButtonMenu, |
|||
child: this.widget.child |
|||
) |
|||
: new IconButton( |
|||
icon: this.widget.icon ?? this._getIcon(Theme.of(context).platform), |
|||
padding: this.widget.padding, |
|||
tooltip: this.widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip, |
|||
onPressed: this.showButtonMenu |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ce8e103e04e044eeaa81c9c2ade4369b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.scheduler; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ImageUtils = Unity.UIWidgets.widgets.ImageUtils; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
enum _SwitchType { |
|||
material, |
|||
adaptive |
|||
} |
|||
|
|||
public class Switch : StatefulWidget { |
|||
internal const float _kTrackHeight = 14.0f; |
|||
internal const float _kTrackWidth = 33.0f; |
|||
internal const float _kTrackRadius = _kTrackHeight / 2.0f; |
|||
internal const float _kThumbRadius = 10.0f; |
|||
internal const float _kSwitchWidth = _kTrackWidth - 2 * _kTrackRadius + 2 * Constants.kRadialReactionRadius; |
|||
internal const float _kSwitchHeight = 2 * Constants.kRadialReactionRadius + 8.0f; |
|||
internal const float _kSwitchHeightCollapsed = 2 * Constants.kRadialReactionRadius; |
|||
|
|||
public Switch( |
|||
Key key = null, |
|||
bool? value = null, |
|||
ValueChanged<bool?> onChanged = null, |
|||
Color activeColor = null, |
|||
Color activeTrackColor = null, |
|||
Color inactiveThumbColor = null, |
|||
Color inactiveTrackColor = null, |
|||
ImageProvider activeThumbImage = null, |
|||
ImageProvider inactiveThumbImage = null, |
|||
MaterialTapTargetSize? materialTapTargetSize = null |
|||
) : this( |
|||
key: key, |
|||
value: value, |
|||
onChanged: onChanged, |
|||
activeColor: activeColor, |
|||
activeTrackColor: activeTrackColor, |
|||
inactiveThumbColor: inactiveThumbColor, |
|||
inactiveTrackColor: inactiveTrackColor, |
|||
activeThumbImage: activeThumbImage, |
|||
inactiveThumbImage: inactiveThumbImage, |
|||
materialTapTargetSize: materialTapTargetSize, |
|||
switchType: _SwitchType.material |
|||
) { |
|||
} |
|||
|
|||
Switch( |
|||
Key key = null, |
|||
bool? value = null, |
|||
ValueChanged<bool?> onChanged = null, |
|||
Color activeColor = null, |
|||
Color activeTrackColor = null, |
|||
Color inactiveThumbColor = null, |
|||
Color inactiveTrackColor = null, |
|||
ImageProvider activeThumbImage = null, |
|||
ImageProvider inactiveThumbImage = null, |
|||
MaterialTapTargetSize? materialTapTargetSize = null, |
|||
_SwitchType switchType = _SwitchType.material |
|||
) : base(key: key) { |
|||
D.assert(value != null); |
|||
this.value = value.Value; |
|||
D.assert(onChanged != null); |
|||
this.onChanged = onChanged; |
|||
this.activeColor = activeColor; |
|||
this.activeTrackColor = activeTrackColor; |
|||
this.inactiveThumbColor = inactiveThumbColor; |
|||
this.inactiveTrackColor = inactiveTrackColor; |
|||
this.activeThumbImage = activeThumbImage; |
|||
this.inactiveThumbImage = inactiveThumbImage; |
|||
this.materialTapTargetSize = materialTapTargetSize; |
|||
this._switchType = switchType; |
|||
} |
|||
|
|||
public static Switch adaptive( |
|||
Key key = null, |
|||
bool? value = null, |
|||
ValueChanged<bool?> onChanged = null, |
|||
Color activeColor = null, |
|||
Color activeTrackColor = null, |
|||
Color inactiveThumbColor = null, |
|||
Color inactiveTrackColor = null, |
|||
ImageProvider activeThumbImage = null, |
|||
ImageProvider inactiveThumbImage = null, |
|||
MaterialTapTargetSize? materialTapTargetSize = null |
|||
) { |
|||
return new Switch(key: key, |
|||
value: value, |
|||
onChanged: onChanged, |
|||
activeColor: activeColor, |
|||
activeTrackColor: activeTrackColor, |
|||
inactiveThumbColor: inactiveThumbColor, |
|||
inactiveTrackColor: inactiveTrackColor, |
|||
activeThumbImage: activeThumbImage, |
|||
inactiveThumbImage: inactiveThumbImage, |
|||
materialTapTargetSize: materialTapTargetSize, |
|||
switchType: _SwitchType.adaptive |
|||
); |
|||
} |
|||
|
|||
public readonly bool value; |
|||
|
|||
public readonly ValueChanged<bool?> onChanged; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public readonly Color activeTrackColor; |
|||
|
|||
public readonly Color inactiveThumbColor; |
|||
|
|||
public readonly Color inactiveTrackColor; |
|||
|
|||
public readonly ImageProvider activeThumbImage; |
|||
|
|||
public readonly ImageProvider inactiveThumbImage; |
|||
|
|||
public readonly MaterialTapTargetSize? materialTapTargetSize; |
|||
|
|||
internal readonly _SwitchType _switchType; |
|||
|
|||
public override State createState() { |
|||
return new _SwitchState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FlagProperty("value", value: this.value, ifTrue: "on", ifFalse: "off", showName: true)); |
|||
properties.add(new ObjectFlagProperty<ValueChanged<bool>>("onChanged", this.onChanged, ifNull: "disabled")); |
|||
} |
|||
} |
|||
|
|||
class _SwitchState : TickerProviderStateMixin<Switch> { |
|||
Size getSwitchSize(ThemeData theme) { |
|||
switch (this.widget.materialTapTargetSize ?? theme.materialTapTargetSize) { |
|||
case MaterialTapTargetSize.padded: |
|||
return new Size(Switch._kSwitchWidth, Switch._kSwitchHeight); |
|||
break; |
|||
case MaterialTapTargetSize.shrinkWrap: |
|||
return new Size(Switch._kSwitchWidth, Switch._kSwitchHeightCollapsed); |
|||
break; |
|||
} |
|||
D.assert(false); |
|||
return null; |
|||
} |
|||
|
|||
Widget buildMaterialSwitch(BuildContext context) { |
|||
D.assert(MaterialD.debugCheckHasMaterial(context)); |
|||
ThemeData theme = Theme.of(context); |
|||
bool isDark = theme.brightness == Brightness.dark; |
|||
|
|||
Color activeThumbColor = this.widget.activeColor ?? theme.toggleableActiveColor; |
|||
Color activeTrackColor = this.widget.activeTrackColor ?? activeThumbColor.withAlpha(0x80); |
|||
|
|||
Color inactiveThumbColor; |
|||
Color inactiveTrackColor; |
|||
if (this.widget.onChanged != null) { |
|||
Color black32 = new Color(0x52000000); // Black with 32% opacity
|
|||
inactiveThumbColor = this.widget.inactiveThumbColor ?? |
|||
(isDark ? Colors.grey.shade400 : Colors.grey.shade50); |
|||
inactiveTrackColor = this.widget.inactiveTrackColor ?? (isDark ? Colors.white30 : black32); |
|||
} else { |
|||
inactiveThumbColor = this.widget.inactiveThumbColor ?? |
|||
(isDark ? Colors.grey.shade800 : Colors.grey.shade400); |
|||
inactiveTrackColor = this.widget.inactiveTrackColor ?? (isDark ? Colors.white10 : Colors.black12); |
|||
} |
|||
|
|||
return new _SwitchRenderObjectWidget( |
|||
value: this.widget.value, |
|||
activeColor: activeThumbColor, |
|||
inactiveColor: inactiveThumbColor, |
|||
activeThumbImage: this.widget.activeThumbImage, |
|||
inactiveThumbImage: this.widget.inactiveThumbImage, |
|||
activeTrackColor: activeTrackColor, |
|||
inactiveTrackColor: inactiveTrackColor, |
|||
configuration: ImageUtils.createLocalImageConfiguration(context), |
|||
onChanged: this.widget.onChanged, |
|||
additionalConstraints: BoxConstraints.tight(this.getSwitchSize(theme)), |
|||
vsync: this |
|||
); |
|||
} |
|||
|
|||
// Widget buildCupertinoSwitch(BuildContext context) {
|
|||
// Size size = this.getSwitchSize(Theme.of(context));
|
|||
// return new Container(
|
|||
// width: size.width, // Same size as the Material switch.
|
|||
// height: size.height,
|
|||
// alignment: Alignment.center,
|
|||
// child: CupertinoSwitch(
|
|||
// value: this.widget.value,
|
|||
// onChanged: this.widget.onChanged,
|
|||
// activeColor: this.widget.activeColor
|
|||
// )
|
|||
// );
|
|||
// }
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
switch (this.widget._switchType) { |
|||
case _SwitchType.material: |
|||
return this.buildMaterialSwitch(context); |
|||
|
|||
case _SwitchType.adaptive: { |
|||
return this.buildMaterialSwitch(context); |
|||
// ThemeData theme = Theme.of(context);
|
|||
// D.assert(theme.platform != null);
|
|||
// switch (theme.platform) {
|
|||
// case TargetPlatform.android:
|
|||
// return buildMaterialSwitch(context);
|
|||
// case TargetPlatform.iOS:
|
|||
// return buildCupertinoSwitch(context);
|
|||
// }
|
|||
// break;
|
|||
} |
|||
} |
|||
|
|||
D.assert(false); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
class _SwitchRenderObjectWidget : LeafRenderObjectWidget { |
|||
public _SwitchRenderObjectWidget( |
|||
Key key = null, |
|||
bool? value = null, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
ImageProvider activeThumbImage = null, |
|||
ImageProvider inactiveThumbImage = null, |
|||
Color activeTrackColor = null, |
|||
Color inactiveTrackColor = null, |
|||
ImageConfiguration configuration = null, |
|||
ValueChanged<bool?> onChanged = null, |
|||
TickerProvider vsync = null, |
|||
BoxConstraints additionalConstraints = null |
|||
) : base(key: key) { |
|||
D.assert(value != null); |
|||
this.value = value.Value; |
|||
this.activeColor = activeColor; |
|||
this.inactiveColor = inactiveColor; |
|||
this.activeThumbImage = activeThumbImage; |
|||
this.inactiveThumbImage = inactiveThumbImage; |
|||
this.activeTrackColor = activeTrackColor; |
|||
this.inactiveTrackColor = inactiveTrackColor; |
|||
this.configuration = configuration; |
|||
this.onChanged = onChanged; |
|||
this.vsync = vsync; |
|||
this.additionalConstraints = additionalConstraints; |
|||
} |
|||
|
|||
public readonly bool value; |
|||
public readonly Color activeColor; |
|||
public readonly Color inactiveColor; |
|||
public readonly ImageProvider activeThumbImage; |
|||
public readonly ImageProvider inactiveThumbImage; |
|||
public readonly Color activeTrackColor; |
|||
public readonly Color inactiveTrackColor; |
|||
public readonly ImageConfiguration configuration; |
|||
public readonly ValueChanged<bool?> onChanged; |
|||
public readonly TickerProvider vsync; |
|||
public readonly BoxConstraints additionalConstraints; |
|||
|
|||
public override RenderObject createRenderObject(BuildContext context) { |
|||
return new _RenderSwitch( |
|||
value: this.value, |
|||
activeColor: this.activeColor, |
|||
inactiveColor: this.inactiveColor, |
|||
activeThumbImage: this.activeThumbImage, |
|||
inactiveThumbImage: this.inactiveThumbImage, |
|||
activeTrackColor: this.activeTrackColor, |
|||
inactiveTrackColor: this.inactiveTrackColor, |
|||
configuration: this.configuration, |
|||
onChanged: this.onChanged, |
|||
additionalConstraints: this.additionalConstraints, |
|||
vsync: this.vsync |
|||
); |
|||
} |
|||
|
|||
public override void updateRenderObject(BuildContext context, RenderObject renderObjectRaw) { |
|||
_RenderSwitch renderObject = (_RenderSwitch) renderObjectRaw; |
|||
|
|||
renderObject.value = this.value; |
|||
renderObject.activeColor = this.activeColor; |
|||
renderObject.inactiveColor = this.inactiveColor; |
|||
renderObject.activeThumbImage = this.activeThumbImage; |
|||
renderObject.inactiveThumbImage = this.inactiveThumbImage; |
|||
renderObject.activeTrackColor = this.activeTrackColor; |
|||
renderObject.inactiveTrackColor = this.inactiveTrackColor; |
|||
renderObject.configuration = this.configuration; |
|||
renderObject.onChanged = this.onChanged; |
|||
renderObject.additionalConstraints = this.additionalConstraints; |
|||
renderObject.vsync = this.vsync; |
|||
} |
|||
} |
|||
|
|||
class _RenderSwitch : RenderToggleable { |
|||
public _RenderSwitch( |
|||
bool? value = null, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
ImageProvider activeThumbImage = null, |
|||
ImageProvider inactiveThumbImage = null, |
|||
Color activeTrackColor = null, |
|||
Color inactiveTrackColor = null, |
|||
ImageConfiguration configuration = null, |
|||
BoxConstraints additionalConstraints = null, |
|||
ValueChanged<bool?> onChanged = null, |
|||
TickerProvider vsync = null |
|||
) : base( |
|||
value: value, |
|||
tristate: false, |
|||
activeColor: activeColor, |
|||
inactiveColor: inactiveColor, |
|||
onChanged: onChanged, |
|||
additionalConstraints: additionalConstraints, |
|||
vsync: vsync |
|||
) { |
|||
this._activeThumbImage = activeThumbImage; |
|||
this._inactiveThumbImage = inactiveThumbImage; |
|||
this._activeTrackColor = activeTrackColor; |
|||
this._inactiveTrackColor = inactiveTrackColor; |
|||
this._configuration = configuration; |
|||
this._drag = new HorizontalDragGestureRecognizer { |
|||
onStart = this._handleDragStart, |
|||
onUpdate = this._handleDragUpdate, |
|||
onEnd = this._handleDragEnd, |
|||
}; |
|||
} |
|||
|
|||
public ImageProvider activeThumbImage { |
|||
get { return this._activeThumbImage; } |
|||
set { |
|||
if (value == this._activeThumbImage) { |
|||
return; |
|||
} |
|||
this._activeThumbImage = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
ImageProvider _activeThumbImage; |
|||
|
|||
public ImageProvider inactiveThumbImage { |
|||
get { return this._inactiveThumbImage; } |
|||
set { |
|||
if (value == this._inactiveThumbImage) { |
|||
return; |
|||
} |
|||
this._inactiveThumbImage = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
ImageProvider _inactiveThumbImage; |
|||
|
|||
public Color activeTrackColor { |
|||
get { return this._activeTrackColor; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._activeTrackColor) { |
|||
return; |
|||
} |
|||
this._activeTrackColor = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _activeTrackColor; |
|||
|
|||
public Color inactiveTrackColor { |
|||
get { return this._inactiveTrackColor; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._inactiveTrackColor) { |
|||
return; |
|||
} |
|||
this._inactiveTrackColor = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _inactiveTrackColor; |
|||
|
|||
public ImageConfiguration configuration { |
|||
get { return this._configuration; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._configuration) { |
|||
return; |
|||
} |
|||
this._configuration = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
ImageConfiguration _configuration; |
|||
|
|||
public override void detach() { |
|||
this._cachedThumbPainter?.Dispose(); |
|||
this._cachedThumbPainter = null; |
|||
base.detach(); |
|||
} |
|||
|
|||
float _trackInnerLength { |
|||
get { return this.size.width - 2.0f * Constants.kRadialReactionRadius; } |
|||
} |
|||
|
|||
HorizontalDragGestureRecognizer _drag; |
|||
|
|||
void _handleDragStart(DragStartDetails details) { |
|||
if (this.isInteractive) { |
|||
this.reactionController.forward(); |
|||
} |
|||
} |
|||
|
|||
void _handleDragUpdate(DragUpdateDetails details) { |
|||
if (this.isInteractive) { |
|||
this.position.curve = null; |
|||
this.position.reverseCurve = null; |
|||
float delta = details.primaryDelta.Value / this._trackInnerLength; |
|||
this.positionController.setValue(this.positionController.value + delta); |
|||
} |
|||
} |
|||
|
|||
void _handleDragEnd(DragEndDetails details) { |
|||
if (this.position.value >= 0.5) { |
|||
this.positionController.forward(); |
|||
} else { |
|||
this.positionController.reverse(); |
|||
} |
|||
this.reactionController.reverse(); |
|||
} |
|||
|
|||
public override void handleEvent(PointerEvent evt, HitTestEntry entry) { |
|||
D.assert(this.debugHandleEvent(evt, entry)); |
|||
if (evt is PointerDownEvent && this.onChanged != null) { |
|||
this._drag.addPointer((PointerDownEvent) evt); |
|||
} |
|||
base.handleEvent(evt, entry); |
|||
} |
|||
|
|||
Color _cachedThumbColor; |
|||
ImageProvider _cachedThumbImage; |
|||
BoxPainter _cachedThumbPainter; |
|||
|
|||
BoxDecoration _createDefaultThumbDecoration(Color color, ImageProvider image) { |
|||
return new BoxDecoration( |
|||
color: color, |
|||
image: image == null ? null : new DecorationImage(image: image), |
|||
shape: BoxShape.circle, |
|||
boxShadow: ShadowConstants.kElevationToShadow[1] |
|||
); |
|||
} |
|||
|
|||
bool _isPainting = false; |
|||
|
|||
void _handleDecorationChanged() { |
|||
if (!this._isPainting) { |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
public override void paint(PaintingContext context, Offset offset) { |
|||
Canvas canvas = context.canvas; |
|||
|
|||
bool isActive = this.onChanged != null; |
|||
float currentValue = this.position.value; |
|||
|
|||
float visualPosition = currentValue; |
|||
|
|||
Color trackColor = isActive |
|||
? Color.lerp(this.inactiveTrackColor, this.activeTrackColor, currentValue) |
|||
: this.inactiveTrackColor; |
|||
|
|||
// Paint the track
|
|||
Paint paint = new Paint {color = trackColor}; |
|||
float trackHorizontalPadding = Constants.kRadialReactionRadius - Switch._kTrackRadius; |
|||
Rect trackRect = Rect.fromLTWH( |
|||
offset.dx + trackHorizontalPadding, |
|||
offset.dy + (this.size.height - Switch._kTrackHeight) / 2.0f, |
|||
this.size.width - 2.0f * trackHorizontalPadding, |
|||
Switch._kTrackHeight |
|||
); |
|||
RRect trackRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(Switch._kTrackRadius)); |
|||
canvas.drawRRect(trackRRect, paint); |
|||
|
|||
Offset thumbPosition = new Offset( |
|||
Constants.kRadialReactionRadius + visualPosition * this._trackInnerLength, |
|||
this.size.height / 2.0f |
|||
); |
|||
|
|||
this.paintRadialReaction(canvas, offset, thumbPosition); |
|||
|
|||
try { |
|||
this._isPainting = true; |
|||
BoxPainter thumbPainter; |
|||
Color thumbColor = isActive |
|||
? Color.lerp(this.inactiveColor, this.activeColor, currentValue) |
|||
: this.inactiveColor; |
|||
ImageProvider thumbImage = isActive |
|||
? (currentValue < 0.5 ? this.inactiveThumbImage : this.activeThumbImage) |
|||
: this.inactiveThumbImage; |
|||
if (this._cachedThumbPainter == null || thumbColor != this._cachedThumbColor || |
|||
thumbImage != this._cachedThumbImage) { |
|||
this._cachedThumbColor = thumbColor; |
|||
this._cachedThumbImage = thumbImage; |
|||
this._cachedThumbPainter = this._createDefaultThumbDecoration(thumbColor, thumbImage) |
|||
.createBoxPainter(this._handleDecorationChanged); |
|||
} |
|||
thumbPainter = this._cachedThumbPainter; |
|||
|
|||
float inset = 1.0f - (currentValue - 0.5f).abs() * 2.0f; |
|||
float radius = Switch._kThumbRadius - inset; |
|||
thumbPainter.paint( |
|||
canvas, |
|||
thumbPosition + offset - new Offset(radius, radius), |
|||
this.configuration.copyWith(size: Size.fromRadius(radius)) |
|||
); |
|||
} finally { |
|||
this._isPainting = false; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4d9cbabd047e4459c890af24af812425 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
|
|||
public enum DayPeriod { |
|||
am, |
|||
pm, |
|||
} |
|||
|
|||
public class TimeOfDay : IEquatable<TimeOfDay> { |
|||
public TimeOfDay(int hour, int minute) { |
|||
this.hour = hour; |
|||
this.minute = minute; |
|||
} |
|||
|
|||
public static TimeOfDay fromDateTime(DateTime time) { |
|||
return new TimeOfDay( |
|||
hour: time.Hour, |
|||
minute: time.Minute |
|||
); |
|||
} |
|||
|
|||
public static TimeOfDay now() { |
|||
return TimeOfDay.fromDateTime(DateTime.Now); |
|||
} |
|||
|
|||
public static readonly int hoursPerDay = 24; |
|||
|
|||
public static readonly int hoursPerPeriod = 12; |
|||
|
|||
public static readonly int minutesPerHour = 60; |
|||
|
|||
public TimeOfDay replacing(int? hour = null, int? minute = null) { |
|||
D.assert(hour == null || (hour >= 0 && hour < hoursPerDay)); |
|||
D.assert(minute == null || (minute >= 0 && minute < minutesPerHour)); |
|||
|
|||
return new TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute); |
|||
} |
|||
|
|||
public readonly int hour; |
|||
|
|||
public readonly int minute; |
|||
|
|||
public DayPeriod period { |
|||
get { return this.hour < hoursPerPeriod ? DayPeriod.am : DayPeriod.pm; } |
|||
} |
|||
|
|||
public int hourOfPeriod { |
|||
get { return this.hour - this.periodOffset; } |
|||
} |
|||
|
|||
public int periodOffset { |
|||
get { return this.period == DayPeriod.am ? 0 : hoursPerPeriod; } |
|||
} |
|||
|
|||
public string format(BuildContext context) { |
|||
D.assert(WidgetsD.debugCheckHasMediaQuery(context)); |
|||
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context)); |
|||
MaterialLocalizations localizations = MaterialLocalizations.of(context); |
|||
return localizations.formatTimeOfDay( |
|||
this, |
|||
alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat |
|||
); |
|||
} |
|||
|
|||
static string _addLeadingZeroIfNeeded(int value) { |
|||
if (value < 10) { |
|||
return "0" + value; |
|||
} |
|||
return value.ToString(); |
|||
} |
|||
|
|||
public bool Equals(TimeOfDay other) { |
|||
if (ReferenceEquals(null, other)) { |
|||
return false; |
|||
} |
|||
if (ReferenceEquals(this, other)) { |
|||
return true; |
|||
} |
|||
return this.hour == other.hour && this.minute == other.minute; |
|||
} |
|||
|
|||
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((TimeOfDay) obj); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
return (this.hour * 397) ^ this.minute; |
|||
} |
|||
} |
|||
|
|||
public static bool operator ==(TimeOfDay left, TimeOfDay right) { |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(TimeOfDay left, TimeOfDay right) { |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override string ToString() { |
|||
string hourLabel = _addLeadingZeroIfNeeded(this.hour); |
|||
string minuteLabel = _addLeadingZeroIfNeeded(this.minute); |
|||
|
|||
return $"TimeOfDay({hourLabel}:{minuteLabel})"; |
|||
} |
|||
} |
|||
|
|||
public enum TimeOfDayFormat { |
|||
HH_colon_mm, |
|||
HH_dot_mm, |
|||
|
|||
frenchCanadian, |
|||
H_colon_mm, |
|||
h_colon_mm_space_a, |
|||
a_space_h_colon_mm, |
|||
} |
|||
|
|||
public enum HourFormat { |
|||
HH, |
|||
H, |
|||
h, |
|||
} |
|||
|
|||
public static class HourFormatUtils { |
|||
public static HourFormat hourFormat(TimeOfDayFormat of) { |
|||
switch (of) { |
|||
case TimeOfDayFormat.h_colon_mm_space_a: |
|||
case TimeOfDayFormat.a_space_h_colon_mm: |
|||
return HourFormat.h; |
|||
case TimeOfDayFormat.H_colon_mm: |
|||
return HourFormat.H; |
|||
case TimeOfDayFormat.HH_dot_mm: |
|||
case TimeOfDayFormat.HH_colon_mm: |
|||
case TimeOfDayFormat.frenchCanadian: |
|||
return HourFormat.HH; |
|||
} |
|||
|
|||
throw new Exception("unknown format: " + of); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: eeb5dc81b18e644e69b2b89cf48b8f3b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using RSG; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.widgets { |
|||
class _Pending { |
|||
public _Pending(LocalizationsDelegate del, IPromise<object> futureValue) { |
|||
this.del = del; |
|||
this.futureValue = futureValue; |
|||
} |
|||
|
|||
public readonly LocalizationsDelegate del; |
|||
public readonly IPromise<object> futureValue; |
|||
|
|||
internal static IPromise<Dictionary<Type, object>> _loadAll(Locale locale, |
|||
IEnumerable<LocalizationsDelegate> allDelegates) { |
|||
Dictionary<Type, object> output = new Dictionary<Type, object>(); |
|||
List<_Pending> pendingList = null; |
|||
|
|||
HashSet<Type> types = new HashSet<Type>(); |
|||
List<LocalizationsDelegate> delegates = new List<LocalizationsDelegate>(); |
|||
foreach (LocalizationsDelegate del in allDelegates) { |
|||
if (!types.Contains(del.type) && del.isSupported(locale)) { |
|||
types.Add(del.type); |
|||
delegates.Add(del); |
|||
} |
|||
} |
|||
|
|||
foreach (LocalizationsDelegate del in delegates) { |
|||
IPromise<object> inputValue = del.load(locale); |
|||
object completedValue = null; |
|||
IPromise<object> futureValue = inputValue.Then(value => { return completedValue = value; }); |
|||
if (completedValue != null) { |
|||
Type type = del.type; |
|||
D.assert(!output.ContainsKey(type)); |
|||
output[type] = completedValue; |
|||
} else { |
|||
pendingList = pendingList ?? new List<_Pending>(); |
|||
pendingList.Add(new _Pending(del, futureValue)); |
|||
} |
|||
} |
|||
|
|||
if (pendingList == null) { |
|||
return Promise<Dictionary<Type, object>>.Resolved(output); |
|||
} |
|||
|
|||
return Promise<object>.All(pendingList.Select(p => p.futureValue)) |
|||
.Then(values => { |
|||
var list = values.ToList(); |
|||
D.assert(list.Count == pendingList.Count); |
|||
for (int i = 0; i < list.Count; i += 1) { |
|||
Type type = pendingList[i].del.type; |
|||
D.assert(!output.ContainsKey(type)); |
|||
output[type] = list[i]; |
|||
} |
|||
return output; |
|||
}); |
|||
} |
|||
} |
|||
|
|||
public abstract class LocalizationsDelegate { |
|||
protected LocalizationsDelegate() { |
|||
} |
|||
|
|||
public abstract bool isSupported(Locale locale); |
|||
|
|||
public abstract IPromise<object> load(Locale locale); |
|||
|
|||
public abstract bool shouldReload(LocalizationsDelegate old); |
|||
|
|||
public abstract Type type { get; } |
|||
|
|||
public override string ToString() { |
|||
return $"{this.GetType()}[{this.type}]"; |
|||
} |
|||
} |
|||
|
|||
public abstract class LocalizationsDelegate<T> : LocalizationsDelegate { |
|||
public override Type type { |
|||
get { return typeof(T); } |
|||
} |
|||
} |
|||
|
|||
public abstract class WidgetsLocalizations { |
|||
static WidgetsLocalizations of(BuildContext context) { |
|||
return Localizations.of<WidgetsLocalizations>(context, typeof(WidgetsLocalizations)); |
|||
} |
|||
} |
|||
|
|||
class _WidgetsLocalizationsDelegate : LocalizationsDelegate<WidgetsLocalizations> { |
|||
public _WidgetsLocalizationsDelegate() { |
|||
} |
|||
|
|||
public override bool isSupported(Locale locale) { |
|||
return true; |
|||
} |
|||
|
|||
public override IPromise<object> load(Locale locale) { |
|||
return DefaultWidgetsLocalizations.load(locale); |
|||
} |
|||
|
|||
public override bool shouldReload(LocalizationsDelegate old) { |
|||
return false; |
|||
} |
|||
|
|||
public override string ToString() { |
|||
return "DefaultWidgetsLocalizations.delegate(en_US)"; |
|||
} |
|||
} |
|||
|
|||
public class DefaultWidgetsLocalizations : WidgetsLocalizations { |
|||
public DefaultWidgetsLocalizations() { |
|||
} |
|||
|
|||
public static IPromise<object> load(Locale locale) { |
|||
return Promise<object>.Resolved(new DefaultWidgetsLocalizations()); |
|||
} |
|||
|
|||
public static readonly LocalizationsDelegate<WidgetsLocalizations> del = new _WidgetsLocalizationsDelegate(); |
|||
} |
|||
|
|||
class _LocalizationsScope : InheritedWidget { |
|||
public _LocalizationsScope( |
|||
Key key, |
|||
Locale locale, |
|||
_LocalizationsState localizationsState, |
|||
Dictionary<Type, object> typeToResources, |
|||
Widget child |
|||
) : base(key: key, child: child) { |
|||
D.assert(locale != null); |
|||
D.assert(localizationsState != null); |
|||
D.assert(typeToResources != null); |
|||
this.locale = locale; |
|||
this.localizationsState = localizationsState; |
|||
this.typeToResources = typeToResources; |
|||
} |
|||
|
|||
public readonly Locale locale; |
|||
|
|||
public readonly _LocalizationsState localizationsState; |
|||
|
|||
public readonly Dictionary<Type, object> typeToResources; |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget old) { |
|||
return this.typeToResources != ((_LocalizationsScope) old).typeToResources; |
|||
} |
|||
} |
|||
|
|||
public class Localizations : StatefulWidget { |
|||
public Localizations( |
|||
Key key = null, |
|||
Locale locale = null, |
|||
List<LocalizationsDelegate> delegates = null, |
|||
Widget child = null |
|||
) : base(key: key) { |
|||
D.assert(locale != null); |
|||
D.assert(delegates != null); |
|||
D.assert(delegates.Any(del => del is LocalizationsDelegate<WidgetsLocalizations>)); |
|||
} |
|||
|
|||
public static Localizations overrides( |
|||
Key key = null, |
|||
BuildContext context = null, |
|||
Locale locale = null, |
|||
List<LocalizationsDelegate> delegates = null, |
|||
Widget child = null |
|||
) { |
|||
List<LocalizationsDelegate> mergedDelegates = _delegatesOf(context); |
|||
if (delegates != null) { |
|||
mergedDelegates.InsertRange(0, delegates); |
|||
} |
|||
return new Localizations( |
|||
key: key, |
|||
locale: locale ?? Localizations.localeOf(context), |
|||
delegates: mergedDelegates, |
|||
child: child |
|||
); |
|||
} |
|||
|
|||
public readonly Locale locale; |
|||
|
|||
public readonly List<LocalizationsDelegate> delegates; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public static Locale localeOf(BuildContext context, bool nullOk = false) { |
|||
D.assert(context != null); |
|||
_LocalizationsScope scope = |
|||
(_LocalizationsScope) context.inheritFromWidgetOfExactType(typeof(_LocalizationsScope)); |
|||
if (nullOk && scope == null) { |
|||
return null; |
|||
} |
|||
D.assert((bool) (scope != null), "a Localizations ancestor was not found"); |
|||
return scope.localizationsState.locale; |
|||
} |
|||
|
|||
public static List<LocalizationsDelegate> _delegatesOf(BuildContext context) { |
|||
D.assert(context != null); |
|||
_LocalizationsScope scope = |
|||
(_LocalizationsScope) context.inheritFromWidgetOfExactType(typeof(_LocalizationsScope)); |
|||
D.assert(scope != null, "a Localizations ancestor was not found"); |
|||
return new List<LocalizationsDelegate>(scope.localizationsState.widget.delegates); |
|||
} |
|||
|
|||
public static T of<T>(BuildContext context, Type type) { |
|||
D.assert(context != null); |
|||
D.assert(type != null); |
|||
_LocalizationsScope scope = |
|||
(_LocalizationsScope) context.inheritFromWidgetOfExactType(typeof(_LocalizationsScope)); |
|||
if (scope != null && scope.localizationsState != null) { |
|||
return scope.localizationsState.resourcesFor<T>(type); |
|||
} |
|||
|
|||
return default; |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _LocalizationsState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new DiagnosticsProperty<Locale>("locale", this.locale)); |
|||
properties.add(new EnumerableProperty<LocalizationsDelegate>("delegates", this.delegates)); |
|||
} |
|||
} |
|||
|
|||
|
|||
class _LocalizationsState : State<Localizations> { |
|||
readonly GlobalKey _localizedResourcesScopeKey = GlobalKey.key(); |
|||
Dictionary<Type, object> _typeToResources = new Dictionary<Type, object>(); |
|||
|
|||
public Locale locale { |
|||
get { return this._locale; } |
|||
} |
|||
|
|||
Locale _locale; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this.load(this.widget.locale); |
|||
} |
|||
|
|||
bool _anyDelegatesShouldReload(Localizations old) { |
|||
if (this.widget.delegates.Count != old.delegates.Count) { |
|||
return true; |
|||
} |
|||
|
|||
List<LocalizationsDelegate> delegates = this.widget.delegates.ToList(); |
|||
List<LocalizationsDelegate> oldDelegates = old.delegates.ToList(); |
|||
for (int i = 0; i < delegates.Count; i += 1) { |
|||
LocalizationsDelegate del = delegates[i]; |
|||
LocalizationsDelegate oldDelegate = oldDelegates[i]; |
|||
if (del.GetType() != oldDelegate.GetType() || del.shouldReload(oldDelegate)) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
Localizations old = (Localizations) oldWidget; |
|||
base.didUpdateWidget(old); |
|||
if (this.widget.locale != old.locale |
|||
|| (this.widget.delegates == null && old.delegates != null) |
|||
|| (this.widget.delegates != null && old.delegates == null) |
|||
|| (this.widget.delegates != null && this._anyDelegatesShouldReload(old))) { |
|||
this.load(this.widget.locale); |
|||
} |
|||
} |
|||
|
|||
void load(Locale locale) { |
|||
var delegates = this.widget.delegates; |
|||
if (delegates == null || delegates.isEmpty()) { |
|||
this._locale = locale; |
|||
return; |
|||
} |
|||
|
|||
Dictionary<Type, object> typeToResources = null; |
|||
IPromise<Dictionary<Type, object>> typeToResourcesFuture = _Pending._loadAll(locale, delegates) |
|||
.Then(value => { return typeToResources = value; }); |
|||
|
|||
if (typeToResources != null) { |
|||
this._typeToResources = typeToResources; |
|||
this._locale = locale; |
|||
} else { |
|||
// WidgetsBinding.instance.deferFirstFrameReport();
|
|||
typeToResourcesFuture.Then(value => { |
|||
// WidgetsBinding.instance.allowFirstFrameReport();
|
|||
if (!this.mounted) { |
|||
return; |
|||
} |
|||
this.setState(() => { |
|||
this._typeToResources = value; |
|||
this._locale = locale; |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
public T resourcesFor<T>(Type type) { |
|||
D.assert(type != null); |
|||
T resources = (T) this._typeToResources[type]; |
|||
return resources; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
if (this._locale == null) { |
|||
return new Container(); |
|||
} |
|||
return new _LocalizationsScope( |
|||
key: this._localizedResourcesScopeKey, |
|||
locale: this._locale, |
|||
localizationsState: this, |
|||
typeToResources: this._typeToResources, |
|||
child: this.widget.child |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 40b3aee9af16a4b40b16b463e6999452 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using RSG; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
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; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
public static class HomeUtils { |
|||
internal static readonly Color _kUIWidgetsBlue = new Color(0xFF003D75); |
|||
internal const float _kDemoItemHeight = 64.0f; |
|||
internal static TimeSpan _kFrontLayerSwitchDuration = new TimeSpan(0, 0, 0, 0, 300); |
|||
} |
|||
|
|||
class _UIWidgetsLogo : StatelessWidget { |
|||
public _UIWidgetsLogo(Key key = null) : base(key: key) { |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Center( |
|||
child: new Container( |
|||
width: 34.0f, |
|||
height: 34.0f, |
|||
decoration: new BoxDecoration( |
|||
image: new DecorationImage( |
|||
image: new AssetImage( |
|||
"logos/unity.png") |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CategoryItem : StatelessWidget { |
|||
public _CategoryItem( |
|||
Key key = null, |
|||
GalleryDemoCategory category = null, |
|||
VoidCallback onTap = null |
|||
) : base(key: key) { |
|||
this.category = category; |
|||
this.onTap = onTap; |
|||
} |
|||
|
|||
public readonly GalleryDemoCategory category; |
|||
|
|||
public readonly VoidCallback onTap; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
ThemeData theme = Theme.of(context); |
|||
bool isDark = theme.brightness == Brightness.dark; |
|||
|
|||
return new RepaintBoundary( |
|||
child: new RawMaterialButton( |
|||
padding: EdgeInsets.zero, |
|||
splashColor: theme.primaryColor.withOpacity(0.12f), |
|||
highlightColor: Colors.transparent, |
|||
onPressed: this.onTap, |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.end, |
|||
crossAxisAlignment: CrossAxisAlignment.center, |
|||
children: new List<Widget> { |
|||
new Padding( |
|||
padding: EdgeInsets.all(6.0f), |
|||
child: new Icon( |
|||
this.category.icon, |
|||
size: 60.0f, |
|||
color: isDark ? Colors.white : HomeUtils._kUIWidgetsBlue |
|||
) |
|||
), |
|||
new SizedBox(height: 10.0f), |
|||
new Container( |
|||
height: 48.0f, |
|||
alignment: Alignment.center, |
|||
child: new Text( |
|||
this.category.name, |
|||
textAlign: TextAlign.center, |
|||
style: theme.textTheme.subhead.copyWith( |
|||
fontFamily: "GoogleSans", |
|||
color: isDark ? Colors.white : HomeUtils._kUIWidgetsBlue |
|||
) |
|||
) |
|||
) |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CategoriesPage : StatelessWidget { |
|||
public _CategoriesPage( |
|||
Key key = null, |
|||
IEnumerable<GalleryDemoCategory> categories = null, |
|||
ValueChanged<GalleryDemoCategory> onCategoryTap = null |
|||
) : base(key: key) { |
|||
this.categories = categories; |
|||
this.onCategoryTap = onCategoryTap; |
|||
} |
|||
|
|||
public readonly IEnumerable<GalleryDemoCategory> categories; |
|||
|
|||
public readonly ValueChanged<GalleryDemoCategory> onCategoryTap; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
float aspectRatio = 160.0f / 180.0f; |
|||
List<GalleryDemoCategory> categoriesList = this.categories.ToList(); |
|||
int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3; |
|||
|
|||
return new SingleChildScrollView( |
|||
key: new PageStorageKey<string>("categories"), |
|||
child: new LayoutBuilder( |
|||
builder: (_, constraints) => { |
|||
float columnWidth = constraints.biggest.width / columnCount; |
|||
float rowHeight = Mathf.Min(225.0f, columnWidth * aspectRatio); |
|||
int rowCount = (categoriesList.Count + columnCount - 1) / columnCount; |
|||
|
|||
return new RepaintBoundary( |
|||
child: new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: Enumerable.Range(0, rowCount).Select(rowIndex => { |
|||
int columnCountForRow = rowIndex == rowCount - 1 |
|||
? categoriesList.Count - columnCount * Mathf.Max(0, rowCount - 1) |
|||
: columnCount; |
|||
|
|||
return (Widget) new Row( |
|||
children: Enumerable.Range(0, columnCountForRow).Select(columnIndex => { |
|||
int index = rowIndex * columnCount + columnIndex; |
|||
GalleryDemoCategory category = categoriesList[index]; |
|||
|
|||
return (Widget) new SizedBox( |
|||
width: columnWidth, |
|||
height: rowHeight, |
|||
child: new _CategoryItem( |
|||
category: category, |
|||
onTap: () => { this.onCategoryTap(category); } |
|||
) |
|||
); |
|||
}).ToList() |
|||
); |
|||
}).ToList() |
|||
) |
|||
); |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _DemoItem : StatelessWidget { |
|||
public _DemoItem(Key key = null, GalleryDemo demo = null) : base(key: key) { |
|||
this.demo = demo; |
|||
} |
|||
|
|||
public readonly GalleryDemo demo; |
|||
|
|||
void _launchDemo(BuildContext context) { |
|||
if (this.demo.routeName != null) { |
|||
Navigator.pushNamed(context, this.demo.routeName); |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
ThemeData theme = Theme.of(context); |
|||
bool isDark = theme.brightness == Brightness.dark; |
|||
float textScaleFactor = MediaQuery.textScaleFactorOf(context); |
|||
|
|||
List<Widget> titleChildren = new List<Widget> { |
|||
new Text( |
|||
this.demo.title, |
|||
style: theme.textTheme.subhead.copyWith( |
|||
color: isDark ? Colors.white : new Color(0xFF202124) |
|||
) |
|||
), |
|||
}; |
|||
|
|||
if (this.demo.subtitle != null) { |
|||
titleChildren.Add( |
|||
new Text( |
|||
this.demo.subtitle, |
|||
style: theme.textTheme.body1.copyWith( |
|||
color: isDark ? Colors.white : new Color(0xFF60646B) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
return new RawMaterialButton( |
|||
padding: EdgeInsets.zero, |
|||
splashColor: theme.primaryColor.withOpacity(0.12f), |
|||
highlightColor: Colors.transparent, |
|||
onPressed: () => { this._launchDemo(context); }, |
|||
child: new Container( |
|||
constraints: new BoxConstraints(minHeight: HomeUtils._kDemoItemHeight * textScaleFactor), |
|||
child: new Row( |
|||
children: new List<Widget> { |
|||
new Container( |
|||
width: 56.0f, |
|||
height: 56.0f, |
|||
alignment: Alignment.center, |
|||
child: new Icon( |
|||
this.demo.icon, |
|||
size: 24.0f, |
|||
color: isDark ? Colors.white : HomeUtils._kUIWidgetsBlue |
|||
) |
|||
), |
|||
new Expanded( |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.center, |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: titleChildren |
|||
) |
|||
), |
|||
new SizedBox(width: 44.0f), |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _DemosPage : StatelessWidget { |
|||
public _DemosPage(GalleryDemoCategory category) { |
|||
this.category = category; |
|||
} |
|||
|
|||
public readonly GalleryDemoCategory category; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
float windowBottomPadding = MediaQuery.of(context).padding.bottom; |
|||
return new KeyedSubtree( |
|||
key: new ValueKey<string>("GalleryDemoList"), |
|||
child: new ListView( |
|||
key: new PageStorageKey<string>(this.category.name), |
|||
padding: EdgeInsets.only(top: 8.0f, bottom: windowBottomPadding), |
|||
children: DemoUtils.kGalleryCategoryToDemos[this.category] |
|||
.Select(demo => (Widget) new _DemoItem(demo: demo)).ToList() |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class GalleryHome : StatefulWidget { |
|||
public GalleryHome( |
|||
Key key = null, |
|||
bool testMode = false, |
|||
Widget optionsPage = null |
|||
) : base(key: key) { |
|||
this.testMode = testMode; |
|||
this.optionsPage = optionsPage; |
|||
} |
|||
|
|||
public readonly Widget optionsPage; |
|||
public readonly bool testMode; |
|||
|
|||
public static bool showPreviewBanner = true; |
|||
|
|||
public override State createState() { |
|||
// return new _GalleryHomeState();
|
|||
return null; |
|||
} |
|||
} |
|||
|
|||
// 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;
|
|||
// }
|
|||
// }
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b6b1570fca0b749e688be67e7bb61a5c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue