浏览代码
Merge branch 'material' into 'master'
Merge branch 'material' into 'master'
Material tab widget See merge request upm-packages/ui-widgets/com.unity.uiwidgets!129/main
Shenhua Gu
6 年前
当前提交
a542dc73
共有 14 个文件被更改,包括 1542 次插入 和 17 次删除
-
15Runtime/material/theme_data.cs
-
12Runtime/widgets/preferred_size.cs
-
81Samples/UIWidgetSample/MaterialSample.cs
-
107Runtime/material/tab_bar_theme.cs
-
11Runtime/material/tab_bar_theme.cs.meta
-
187Runtime/material/tab_controller.cs
-
11Runtime/material/tab_controller.cs.meta
-
90Runtime/material/tab_indicator.cs
-
11Runtime/material/tab_indicator.cs.meta
-
1001Runtime/material/tabs.cs
-
11Runtime/material/tabs.cs.meta
-
11Runtime/widgets/preferred_size.cs.meta
-
11Runtime/widgets/perferred_size.cs.meta
-
0/Runtime/widgets/preferred_size.cs
|
|||
using System; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class TabBarTheme : Diagnosticable, IEquatable<TabBarTheme> { |
|||
public TabBarTheme( |
|||
Decoration indicator = null, |
|||
TabBarIndicatorSize? indicatorSize = null, |
|||
Color labelColor = null, |
|||
Color unselectedLabelColor = null) { |
|||
this.indicator = indicator; |
|||
this.indicatorSize = indicatorSize; |
|||
this.labelColor = labelColor; |
|||
this.unselectedLabelColor = unselectedLabelColor; |
|||
} |
|||
|
|||
public readonly Decoration indicator; |
|||
|
|||
public readonly TabBarIndicatorSize? indicatorSize; |
|||
|
|||
public readonly Color labelColor; |
|||
|
|||
public readonly Color unselectedLabelColor; |
|||
|
|||
public TabBarTheme copyWith( |
|||
Decoration indicator = null, |
|||
TabBarIndicatorSize? indicatorSize = null, |
|||
Color labelColor = null, |
|||
Color unselectedLabelColor = null |
|||
) { |
|||
return new TabBarTheme( |
|||
indicator: indicator ?? this.indicator, |
|||
indicatorSize: indicatorSize ?? this.indicatorSize, |
|||
labelColor: labelColor ?? this.labelColor, |
|||
unselectedLabelColor: unselectedLabelColor ?? this.unselectedLabelColor); |
|||
} |
|||
|
|||
public static TabBarTheme of(BuildContext context) { |
|||
return Theme.of(context).tabBarTheme; |
|||
} |
|||
|
|||
public static TabBarTheme lerp(TabBarTheme a, TabBarTheme b, float t) { |
|||
D.assert(a != null); |
|||
D.assert(b != null); |
|||
return new TabBarTheme( |
|||
indicator: Decoration.lerp(a.indicator, b.indicator, t), |
|||
indicatorSize: t < 0.5 ? a.indicatorSize : b.indicatorSize, |
|||
labelColor: Color.lerp(a.labelColor, b.labelColor, t), |
|||
unselectedLabelColor: Color.lerp(a.unselectedLabelColor, b.unselectedLabelColor, t) |
|||
); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
var hashCode = this.indicator != null ? this.indicator.GetHashCode() : 0; |
|||
hashCode = (hashCode * 397) ^ (this.indicatorSize != null ? this.indicatorSize.GetHashCode() : 0); |
|||
hashCode = (hashCode * 397) ^ (this.labelColor != null ? this.labelColor.GetHashCode() : 0); |
|||
hashCode = (hashCode * 397) ^ |
|||
(this.unselectedLabelColor != null ? this.unselectedLabelColor.GetHashCode() : 0); |
|||
return hashCode; |
|||
} |
|||
} |
|||
|
|||
|
|||
public bool Equals(TabBarTheme other) { |
|||
if (ReferenceEquals(null, other)) { |
|||
return false; |
|||
} |
|||
|
|||
if (ReferenceEquals(this, other)) { |
|||
return true; |
|||
} |
|||
|
|||
return other.indicator == this.indicator && |
|||
other.indicatorSize == this.indicatorSize && |
|||
other.labelColor == this.labelColor && |
|||
other.unselectedLabelColor == this.unselectedLabelColor; |
|||
} |
|||
|
|||
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((TabBarTheme) obj); |
|||
} |
|||
|
|||
public static bool operator ==(TabBarTheme left, TabBarTheme right) { |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(TabBarTheme left, TabBarTheme right) { |
|||
return !Equals(left, right); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e5dde8f06134e4f07a597b48fa14a6eb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.scheduler; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class TabController : ChangeNotifier { |
|||
public TabController( |
|||
int initialIndex = 0, |
|||
int? length = null, |
|||
TickerProvider vsync = null) { |
|||
D.assert(length != null && length >= 0); |
|||
D.assert(initialIndex >= 0 && (length == 0 || initialIndex < length)); |
|||
D.assert(vsync != null); |
|||
this.length = length.Value; |
|||
|
|||
this._index = initialIndex; |
|||
this._previousIndex = initialIndex; |
|||
this._animationController = length < 2 |
|||
? null |
|||
: new AnimationController( |
|||
value: initialIndex, |
|||
upperBound: length.Value - 1, |
|||
vsync: vsync); |
|||
} |
|||
|
|||
public Animation<float> animation { |
|||
get { return this._animationController?.view ?? Animations.kAlwaysCompleteAnimation; } |
|||
} |
|||
|
|||
readonly AnimationController _animationController; |
|||
|
|||
public readonly int length; |
|||
|
|||
void _changeIndex(int value, TimeSpan? duration = null, Curve curve = null) { |
|||
D.assert(value >= 0 && (value < this.length || this.length == 0)); |
|||
D.assert(duration == null ? curve == null : true); |
|||
D.assert(this._indexIsChangingCount >= 0); |
|||
|
|||
if (value == this._index || this.length < 2) { |
|||
return; |
|||
} |
|||
|
|||
this._previousIndex = this.index; |
|||
this._index = value; |
|||
if (duration != null) { |
|||
this._indexIsChangingCount++; |
|||
this.notifyListeners(); |
|||
this._animationController.animateTo( |
|||
this._index, duration: duration, curve: curve).whenCompleteOrCancel(() => { |
|||
this._indexIsChangingCount--; |
|||
this.notifyListeners(); |
|||
}); |
|||
} |
|||
else { |
|||
this._indexIsChangingCount++; |
|||
this._animationController.setValue(this._index); |
|||
this._indexIsChangingCount--; |
|||
this.notifyListeners(); |
|||
} |
|||
} |
|||
|
|||
public int index { |
|||
get { return this._index; } |
|||
set { this._changeIndex(value); } |
|||
} |
|||
|
|||
int _index; |
|||
|
|||
public int previousIndex { |
|||
get { return this._previousIndex; } |
|||
} |
|||
|
|||
int _previousIndex; |
|||
|
|||
public bool indexIsChanging { |
|||
get { return this._indexIsChangingCount != 0; } |
|||
} |
|||
|
|||
int _indexIsChangingCount = 0; |
|||
|
|||
public void animateTo(int value, TimeSpan? duration = null, Curve curve = null) { |
|||
duration = duration ?? Constants.kTabScrollDuration; |
|||
curve = curve ?? Curves.ease; |
|||
this._changeIndex(value, duration: duration, curve: curve); |
|||
} |
|||
|
|||
public float offset { |
|||
get { return this.length > 1 ? this._animationController.value - this._index : 0.0f; } |
|||
set { |
|||
D.assert(this.length > 1); |
|||
D.assert(value >= -1.0f && value <= 1.0f); |
|||
D.assert(!this.indexIsChanging); |
|||
if (value == this.offset) { |
|||
return; |
|||
} |
|||
|
|||
this._animationController.setValue(value + this._index); |
|||
} |
|||
} |
|||
|
|||
public override void dispose() { |
|||
this._animationController?.dispose(); |
|||
base.dispose(); |
|||
} |
|||
} |
|||
|
|||
class _TabControllerScope : InheritedWidget { |
|||
public _TabControllerScope( |
|||
Key key = null, |
|||
TabController controller = null, |
|||
bool? enabled = null, |
|||
Widget child = null |
|||
) : base(key: key, child: child) { |
|||
this.controller = controller; |
|||
this.enabled = enabled; |
|||
} |
|||
|
|||
public readonly TabController controller; |
|||
|
|||
public readonly bool? enabled; |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget old) { |
|||
_TabControllerScope _old = (_TabControllerScope) old; |
|||
return this.enabled != _old.enabled |
|||
|| this.controller != _old.controller; |
|||
} |
|||
} |
|||
|
|||
class DefaultTabController : StatefulWidget { |
|||
public DefaultTabController( |
|||
Key key = null, |
|||
int? length = null, |
|||
int initialIndex = 0, |
|||
Widget child = null |
|||
) : base(key: key) { |
|||
D.assert(length != null); |
|||
D.assert(child != null); |
|||
this.length = length; |
|||
this.initialIndex = initialIndex; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly int? length; |
|||
|
|||
public readonly int initialIndex; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public static TabController of(BuildContext context) { |
|||
_TabControllerScope scope = |
|||
(_TabControllerScope) context.inheritFromWidgetOfExactType(typeof(_TabControllerScope)); |
|||
return scope?.controller; |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _DefaultTabControllerState(); |
|||
} |
|||
} |
|||
|
|||
class _DefaultTabControllerState : SingleTickerProviderStateMixin<DefaultTabController> { |
|||
TabController _controller; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this._controller = new TabController( |
|||
vsync: this, |
|||
length: this.widget.length, |
|||
initialIndex: this.widget.initialIndex |
|||
); |
|||
} |
|||
|
|||
public override void dispose() { |
|||
this._controller.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new _TabControllerScope( |
|||
controller: this._controller, |
|||
enabled: TickerMode.of(context), |
|||
child: this.widget.child |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f6cf1d3578f4a4effa3b0988822e3b2e |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class UnderlineTabIndicator : Decoration { |
|||
public UnderlineTabIndicator( |
|||
BorderSide borderSide = null, |
|||
EdgeInsets insets = null) { |
|||
borderSide = borderSide ?? new BorderSide(width: 2.0f, color: Colors.white); |
|||
insets = insets ?? EdgeInsets.zero; |
|||
this.borderSide = borderSide; |
|||
this.insets = insets; |
|||
} |
|||
|
|||
public readonly BorderSide borderSide; |
|||
|
|||
public readonly EdgeInsets insets; |
|||
|
|||
public override Decoration lerpFrom(Decoration a, float t) { |
|||
if (a is UnderlineTabIndicator) { |
|||
UnderlineTabIndicator _a = (UnderlineTabIndicator) a; |
|||
return new UnderlineTabIndicator( |
|||
borderSide: BorderSide.lerp(_a.borderSide, this.borderSide, t), |
|||
insets: EdgeInsets.lerp(_a.insets, this.insets, t) |
|||
); |
|||
} |
|||
|
|||
return base.lerpFrom(a, t); |
|||
} |
|||
|
|||
public override Decoration lerpTo(Decoration b, float t) { |
|||
if (b is UnderlineTabIndicator) { |
|||
UnderlineTabIndicator _b = (UnderlineTabIndicator) b; |
|||
return new UnderlineTabIndicator( |
|||
borderSide: BorderSide.lerp(this.borderSide, _b.borderSide, t), |
|||
insets: EdgeInsets.lerp(this.insets, _b.insets, t) |
|||
); |
|||
} |
|||
|
|||
return base.lerpTo(b, t); |
|||
} |
|||
|
|||
|
|||
public override BoxPainter createBoxPainter(VoidCallback onChanged) { |
|||
return new _UnderlinePainter(this, onChanged); |
|||
} |
|||
} |
|||
|
|||
|
|||
class _UnderlinePainter : BoxPainter { |
|||
public _UnderlinePainter( |
|||
UnderlineTabIndicator decoration = null, |
|||
VoidCallback onChanged = null |
|||
) : base(onChanged: onChanged) { |
|||
D.assert(decoration != null); |
|||
this.decoration = decoration; |
|||
} |
|||
|
|||
public readonly UnderlineTabIndicator decoration; |
|||
|
|||
public BorderSide borderSide { |
|||
get { return this.decoration.borderSide; } |
|||
} |
|||
|
|||
public EdgeInsets insets { |
|||
get { return this.decoration.insets; } |
|||
} |
|||
|
|||
Rect _indicatorRectFor(Rect rect) { |
|||
D.assert(rect != null); |
|||
Rect indicator = this.insets.deflateRect(rect); |
|||
return Rect.fromLTWH( |
|||
indicator.left, |
|||
indicator.bottom - this.borderSide.width, |
|||
indicator.width, |
|||
this.borderSide.width); |
|||
} |
|||
|
|||
public override void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { |
|||
D.assert(configuration != null); |
|||
D.assert(configuration.size != null); |
|||
Rect rect = offset & configuration.size; |
|||
Rect indicator = this._indicatorRectFor(rect).deflate(this.borderSide.width / 2.0f); |
|||
Paint paint = this.borderSide.toPaint(); |
|||
paint.strokeCap = StrokeCap.square; |
|||
canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 07582ba5529ac435f98f69a5eea30831 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Runtime/material/tabs.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 27058ed141c4f4476a7db65aacfda644 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 47c0eb9f305f0431a9a06da1a3f19875 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 60513bb9173ce47ad8d4c7840bcfe836 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue