浏览代码

[1.5.4] Upgrade most of material.

/main
Yuncong Zhang 5 年前
当前提交
9a2e58bf
共有 11 个文件被更改,包括 571 次插入319 次删除
  1. 131
      Runtime/material/dropdown.cs
  2. 32
      Runtime/material/expansion_panel.cs
  3. 16
      Runtime/material/progress_indicator.cs
  4. 113
      Runtime/material/scaffold.cs
  5. 2
      Runtime/material/floating_action_button.cs.meta
  6. 2
      Runtime/material/floating_action_button_location.cs.meta
  7. 314
      Runtime/material/floating_action_button.cs
  8. 280
      Runtime/material/float_action_button.cs
  9. 0
      /Runtime/material/floating_action_button_location.cs
  10. 0
      /Runtime/material/floating_action_button.cs.meta
  11. 0
      /Runtime/material/floating_action_button_location.cs.meta

131
Runtime/material/dropdown.cs


public override Widget buildPage(BuildContext context, Animation<float> animation,
Animation<float> secondaryAnimation) {
return new LayoutBuilder(
builder: (ctx, constraints) => {
return new _DropdownRoutePage<T>(
route: this,
constraints: constraints,
items: this.items,
padding: this.padding,
buttonRect: this.buttonRect,
selectedIndex: this.selectedIndex,
elevation: this.elevation,
theme: this.theme,
style: this.style
);
}
);
}
internal void _dismiss() {
this.navigator?.removeRoute(this);
}
}
class _DropdownRoutePage<T> : StatelessWidget where T : class {
public _DropdownRoutePage(
Key key = null,
_DropdownRoute<T> route = null,
BoxConstraints constraints = null,
List<DropdownMenuItem<T>> items = null,
EdgeInsets padding = null,
Rect buttonRect = null,
int? selectedIndex = null,
int elevation = 0,
ThemeData theme = null,
TextStyle style = null
) : base(key: key) {
this.route = route;
this.constraints = constraints;
this.items = items;
this.padding = padding;
this.buttonRect = buttonRect;
this.selectedIndex = selectedIndex;
this.elevation = elevation;
this.theme = theme;
this.style = style;
}
public readonly _DropdownRoute<T> route;
public readonly BoxConstraints constraints;
public readonly List<DropdownMenuItem<T>> items;
public readonly EdgeInsets padding;
public readonly Rect buttonRect;
public readonly int? selectedIndex;
public readonly int elevation;
public readonly ThemeData theme;
public readonly TextStyle style;
public override Widget build(BuildContext context) {
float screenHeight = MediaQuery.of(context).size.height;
float maxMenuHeight = screenHeight - 2.0f * DropdownConstants._kMenuItemHeight;
float availableHeight = this.constraints.maxHeight;
float maxMenuHeight = availableHeight - 2.0f * DropdownConstants._kMenuItemHeight;
float buttonBottom = this.buttonRect.bottom;
float buttonBottom = Mathf.Min(this.buttonRect.bottom, availableHeight);
float bottomLimit = Mathf.Max(screenHeight - DropdownConstants._kMenuItemHeight, buttonBottom);
float bottomLimit = Mathf.Max(availableHeight - DropdownConstants._kMenuItemHeight, buttonBottom);
float? selectedItemOffset = this.selectedIndex * DropdownConstants._kMenuItemHeight +
Constants.kMaterialListPadding.top;

menuTop = menuBottom - menuHeight;
}
if (this.scrollController == null) {
if (this.route.scrollController == null) {
this.scrollController = new ScrollController(initialScrollOffset: scrollOffset);
this.route.scrollController = new ScrollController(initialScrollOffset: scrollOffset);
route: this,
route: this.route,
padding: this.padding
);

}
)
);
}
public void _dismiss() {
this.navigator?.removeRoute(this);
}
}

ValueChanged<T> onChanged = null,
int elevation = 8,
TextStyle style = null,
Widget underline = null,
Widget icon = null,
Color iconDisabledColor = null,
Color iconEnabledColor = null,
float iconSize = 24.0f,
bool isDense = false,
bool isExpanded = false

this.onChanged = onChanged;
this.elevation = elevation;
this.style = style;
this.underline = underline;
this.icon = icon;
this.iconDisabledColor = iconDisabledColor;
this.iconEnabledColor = iconEnabledColor;
this.iconSize = iconSize;
this.isDense = isDense;
this.isExpanded = isExpanded;

public readonly TextStyle style;
public readonly Widget underline;
public readonly Widget icon;
public readonly Color iconDisabledColor;
public readonly Color iconEnabledColor;
public readonly float iconSize;
public readonly bool isDense;

}
}
Color _downArrowColor {
Color _iconColor {
if (Theme.of(this.context).brightness == Brightness.light) {
return Colors.grey.shade700;
if (this.widget.iconEnabledColor != null) {
return this.widget.iconEnabledColor;
else {
return Colors.white70;
switch (Theme.of(this.context).brightness) {
case Brightness.light:
return Colors.grey.shade700;
case Brightness.dark:
return Colors.white70;
if (Theme.of(this.context).brightness == Brightness.light) {
return Colors.grey.shade400;
if (this.widget.iconDisabledColor != null) {
return this.widget.iconDisabledColor;
else {
return Colors.white10;
switch (Theme.of(this.context).brightness) {
case Brightness.light:
return Colors.grey.shade400;
case Brightness.dark:
return Colors.white10;
D.assert(false);
return null;
}
}

children: items
);
Icon defaultIcon = new Icon(Icons.arrow_drop_down);
Widget result = new DefaultTextStyle(
style: this._textStyle,
child: new Container(

mainAxisSize: MainAxisSize.min,
children: new List<Widget> {
this.widget.isExpanded ? new Expanded(child: innerItemsWidget) : (Widget) innerItemsWidget,
new Icon(Icons.arrow_drop_down,
size: this.widget.iconSize,
color: this._downArrowColor
new IconTheme(
data: new IconThemeData(
color: this._iconColor,
size: this.widget.iconSize
),
child: this.widget.icon ?? defaultIcon
)
}
)

left: 0.0f,
right: 0.0f,
bottom: bottom,
child: new Container(
child: this.widget.underline ?? new Container(
height: 1.0f,
decoration: new BoxDecoration(
border: new Border(

32
Runtime/material/expansion_panel.cs


public ExpansionPanel(
ExpansionPanelHeaderBuilder headerBuilder = null,
Widget body = null,
bool isExpanded = false) {
bool isExpanded = false,
bool canTapOnHeader = false) {
this.canTapOnHeader = false;
}
public readonly ExpansionPanelHeaderBuilder headerBuilder;

public readonly bool isExpanded;
public readonly bool canTapOnHeader;
}

ExpansionPanelHeaderBuilder headerBuilder = null,
Widget body = null) : base(body: body, headerBuilder: headerBuilder) {
Widget body = null,
bool canTapOnHeader = false)
: base(body: body, headerBuilder: headerBuilder, canTapOnHeader: canTapOnHeader) {
D.assert(headerBuilder != null);
D.assert(body != null);
D.assert(value != null);

}
ExpansionPanel child = this.widget.children[index];
Widget headerWidget = child.headerBuilder(
context,
this._isChildExpanded(index)
);
Row header = new Row(
children: new List<Widget> {
new Expanded(

child: new ConstrainedBox(
constraints: new BoxConstraints(
minHeight: ExpansionPanelUtils._kPanelHeaderCollapsedHeight),
child: child.headerBuilder(
context,
this._isChildExpanded(index))
child: headerWidget
)
)
),

isExpanded: this._isChildExpanded(index),
padding: EdgeInsets.all(16.0f),
onPressed: (bool isExpanded) => this._handlePressed(isExpanded, expandIndex)
onPressed: !child.canTapOnHeader
? (ValueChanged<bool>) ((bool isExpanded) => {
this._handlePressed(isExpanded, expandIndex);
})
: null
)
)
}

key: new _SaltedKey<BuildContext, int>(context, index * 2),
child: new Column(
children: new List<Widget> {
header,
child.canTapOnHeader
? (Widget) new InkWell(
onTap: () =>
this._handlePressed(this._isChildExpanded(expandIndex), expandIndex),
child: header
)
: header,
new AnimatedCrossFade(
firstChild: new Container(height: 0.0f),
secondChild: child.body,

16
Runtime/material/progress_indicator.cs


class _CircularProgressIndicatorPainter : AbstractCustomPainter {
public _CircularProgressIndicatorPainter(
Color backgroundColor = null,
Color valueColor = null,
float? value = null,
float? headValue = null,

float? strokeWidth = null
) {
this.backgroundColor = backgroundColor;
this.valueColor = valueColor;
this.value = value;
this.headValue = headValue;

: Mathf.Max(headValue * 3 / 2 * Mathf.PI - tailValue * 3 / 2 * Mathf.PI ?? 0.0f, _epsilon);
}
public readonly Color backgroundColor;
public readonly Color valueColor;
public readonly float? value;
public readonly float? headValue;

paint.strokeWidth = this.strokeWidth ?? 0.0f;
paint.style = PaintingStyle.stroke;
if (this.backgroundColor != null) {
Paint backgroundPaint = new Paint() {
color = this.backgroundColor,
strokeWidth = this.strokeWidth ?? 0.0f,
style = PaintingStyle.stroke
};
canvas.drawArc(Offset.zero & size, 0, _sweep, false, backgroundPaint);
}
if (this.value == null)
{
paint.strokeCap = StrokeCap.square;

public override bool shouldRepaint(CustomPainter oldPainter) {
D.assert(oldPainter is _CircularProgressIndicatorPainter);
_CircularProgressIndicatorPainter painter = oldPainter as _CircularProgressIndicatorPainter;
return painter.valueColor != this.valueColor
return painter.backgroundColor != this.backgroundColor
|| painter.valueColor != this.valueColor
|| painter.value != this.value
|| painter.headValue != this.headValue
|| painter.tailValue != this.tailValue

),
child: new CustomPaint(
painter: new _CircularProgressIndicatorPainter(
backgroundColor: this.widget.backgroundColor,
valueColor: this.widget._getValueColor(context),
value: this.widget.value,
headValue: headValue,

113
Runtime/material/scaffold.cs


}
}
class _BodyBoxConstraints : BoxConstraints {
public _BodyBoxConstraints(
float minWidth = 0.0f,
float maxWidth = float.PositiveInfinity,
float minHeight = 0.0f,
float maxHeight = float.PositiveInfinity,
float? bottomWidgetsHeight = null
) : base(minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight) {
D.assert(bottomWidgetsHeight != null);
D.assert(bottomWidgetsHeight >= 0);
this.bottomWidgetsHeight = bottomWidgetsHeight.Value;
}
public readonly float bottomWidgetsHeight;
public bool Equals(_BodyBoxConstraints other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return this.bottomWidgetsHeight.Equals(other.bottomWidgetsHeight)
&& base.Equals(other);
}
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((_BodyBoxConstraints) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ this.bottomWidgetsHeight.GetHashCode();
return hashCode;
}
}
public static bool operator ==(_BodyBoxConstraints left, _BodyBoxConstraints right) {
return Equals(left, right);
}
public static bool operator !=(_BodyBoxConstraints left, _BodyBoxConstraints right) {
return !Equals(left, right);
}
}
class _BodyBuilder : StatelessWidget {
public _BodyBuilder(Key key = null, Widget body = null) : base(key: key) {
this.body = body;
}
public readonly Widget body;
public override Widget build(BuildContext context) {
return new LayoutBuilder(
builder: (ctx, constraints) => {
_BodyBoxConstraints bodyConstraints = (_BodyBoxConstraints) constraints;
MediaQueryData metrics = MediaQuery.of(context);
return new MediaQuery(
data: metrics.copyWith(
padding: metrics.padding.copyWith(
bottom: Mathf.Max(metrics.padding.bottom, bodyConstraints.bottomWidgetsHeight)
)
)
);
}
);
}
}
class _ScaffoldLayout : MultiChildLayoutDelegate {
public _ScaffoldLayout(
EdgeInsets minInsets,

float floatingActionButtonMoveAnimationProgress,
FloatingActionButtonAnimator floatingActionButtonMotionAnimator
FloatingActionButtonAnimator floatingActionButtonMotionAnimator,
bool extendBody
) {
D.assert(minInsets != null);
D.assert(geometryNotifier != null);

this.currentFloatingActionButtonLocation = currentFloatingActionButtonLocation;
this.floatingActionButtonMoveAnimationProgress = floatingActionButtonMoveAnimationProgress;
this.floatingActionButtonMotionAnimator = floatingActionButtonMotionAnimator;
this.extendBody = extendBody;
public readonly bool extendBody;
public readonly EdgeInsets minInsets;
public readonly _ScaffoldGeometryNotifier geometryNotifier;

float contentBottom = Mathf.Max(0.0f, bottom - Mathf.Max(this.minInsets.bottom, bottomWidgetsHeight));
if (this.hasChild(_ScaffoldSlot.body)) {
BoxConstraints bodyConstraints = new BoxConstraints(
float bodyMaxHeight = Mathf.Max(0.0f, contentBottom - contentTop);
if (this.extendBody) {
bodyMaxHeight += bottomWidgetsHeight;
D.assert(bodyMaxHeight <= Mathf.Max(0.0f, looseConstraints.maxHeight - contentTop));
}
BoxConstraints bodyConstraints = new _BodyBoxConstraints(
maxHeight: Mathf.Max(0.0f, contentBottom - contentTop)
maxHeight: bodyMaxHeight,
bottomWidgetsHeight: this.extendBody ? bottomWidgetsHeight : 0.0f
);
this.layoutChild(_ScaffoldSlot.body, bodyConstraints);
this.positionChild(_ScaffoldSlot.body, new Offset(0.0f, contentTop));

bool? resizeToAvoidBottomPadding = null,
bool? resizeToAvoidBottomInset = null,
bool primary = true,
DragStartBehavior drawerDragStartBehavior = DragStartBehavior.down
DragStartBehavior drawerDragStartBehavior = DragStartBehavior.start,
bool extendBody = false
) : base(key: key) {
this.appBar = appBar;
this.body = body;

this.resizeToAvoidBottomInset = resizeToAvoidBottomInset;
this.primary = primary;
this.drawerDragStartBehavior = drawerDragStartBehavior;
this.extendBody = extendBody;
public readonly bool extendBody;
public readonly PreferredSizeWidget appBar;

this._addIfNonNull(
children: children,
child: this.widget.body,
child: this.widget.body != null && this.widget.extendBody
? new _BodyBuilder(body: this.widget.body) : this.widget.body,
childId: _ScaffoldSlot.body,
removeLeftPadding: false,
removeTopPadding: this.widget.appBar != null,

bottom: this._resizeToAvoidBottomInset ? mediaQuery.viewInsets.bottom : 0.0f
);
bool _extendBody = !(minInsets.bottom > 0) && this.widget.extendBody;
return new _ScaffoldScope(
hasDrawer: this.hasDrawer,
geometryNotifier: this._geometryNotifier,

return new CustomMultiChildLayout(
children: new List<Widget>(children),
layoutDelegate: new _ScaffoldLayout(
extendBody: _extendBody,
minInsets: minInsets,
currentFloatingActionButtonLocation: this._floatingActionButtonLocation,
floatingActionButtonMoveAnimationProgress: this

2
Runtime/material/floating_action_button.cs.meta


fileFormatVersion: 2
guid: 274f3c1005cd046a28b169d8048c0292
guid: 44d53f5996891c54780cbc0073567bfd
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
Runtime/material/floating_action_button_location.cs.meta


fileFormatVersion: 2
guid: cfa1c894caa2a46b19d419f6f53ae91f
guid: 6c8b71fe76d6bdb4ca66ecad56f25d3f
MonoImporter:
externalObjects: {}
serializedVersion: 2

314
Runtime/material/floating_action_button.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
static class FloatActionButtonUtils {
public static readonly BoxConstraints _kSizeConstraints = BoxConstraints.tightFor(width: 56.0f, height: 56.0f);
public static readonly BoxConstraints _kMiniSizeConstraints =
BoxConstraints.tightFor(width: 40.0f, height: 40.0f);
public static readonly BoxConstraints _kExtendedSizeConstraints =
new BoxConstraints(minHeight: 48.0f, maxHeight: 48.0f);
}
class _DefaultHeroTag {
public _DefaultHeroTag() {
}
public override string ToString() {
return "<default FloatingActionButton tag>";
}
}
public class FloatingActionButton : StatelessWidget {
FloatingActionButton(
Key key = null,
Widget child = null,
string tooltip = null,
Color foregroundColor = null,
Color backgroundColor = null,
object heroTag = null,
float? elevation = null,
float? highlightElevation = null,
float? disabledElevation = null,
VoidCallback onPressed = null,
bool mini = false,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize? materialTapTargetSize = null,
bool isExtended = false,
BoxConstraints _sizeConstraints = null
) : base(key: key) {
D.assert(elevation == null || elevation >= 0.0f);
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(disabledElevation == null || disabledElevation >= 0.0f);
heroTag = heroTag ?? new _DefaultHeroTag();
this.child = child;
this.tooltip = tooltip;
this.foregroundColor = foregroundColor;
this.backgroundColor = backgroundColor;
this.heroTag = heroTag;
this.elevation = elevation;
this.highlightElevation = highlightElevation;
this.onPressed = onPressed;
this.mini = mini;
this.shape = shape;
this.clipBehavior = clipBehavior;
this.materialTapTargetSize = materialTapTargetSize;
this.isExtended = isExtended;
this.disabledElevation = disabledElevation;
this._sizeConstraints = _sizeConstraints ?? (mini
? FloatActionButtonUtils._kMiniSizeConstraints
: FloatActionButtonUtils._kSizeConstraints);
}
public FloatingActionButton(
Key key = null,
Widget child = null,
string tooltip = null,
Color foregroundColor = null,
Color backgroundColor = null,
object heroTag = null,
float elevation = 6.0f,
float highlightElevation = 12.0f,
VoidCallback onPressed = null,
bool mini = false,
ShapeBorder shape = null,
Clip clipBehavior = Clip.none,
MaterialTapTargetSize? materialTapTargetSize = null,
bool isExtended = false
) : this(key: key,
child: child,
tooltip: tooltip,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
heroTag: heroTag,
elevation: elevation,
highlightElevation: highlightElevation,
onPressed: onPressed,
mini: mini,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
isExtended: isExtended,
_sizeConstraints: null) {
}
public static FloatingActionButton extended(
Key key = null,
string tooltip = null,
Color foregroundColor = null,
Color backgroundColor = null,
object heroTag = null,
float? elevation = null,
float? highlightElevation = null,
float? disabledElevation = null,
VoidCallback onPressed = null,
ShapeBorder shape = null,
bool isExtended = true,
MaterialTapTargetSize? materialTapTargetSize = null,
Clip clipBehavior = Clip.none,
Widget icon = null,
Widget label = null
) {
D.assert(elevation == null || elevation >= 0.0f);
D.assert(highlightElevation == null || highlightElevation >= 0.0f);
D.assert(disabledElevation == null || disabledElevation >= 0.0f);
D.assert(label != null);
heroTag = heroTag ?? new _DefaultHeroTag();
BoxConstraints _sizeConstraints = FloatActionButtonUtils._kExtendedSizeConstraints;
bool mini = false;
Widget child = new _ChildOverflowBox(
child: new Row(
mainAxisSize: MainAxisSize.min,
children: icon == null
? new List<Widget> {
new SizedBox(width: 20.0f),
label,
new SizedBox(width: 20.0f),
}
: new List<Widget> {
new SizedBox(width: 16.0f),
icon,
new SizedBox(width: 8.0f),
label,
new SizedBox(width: 20.0f)
}));
return new FloatingActionButton(
key: key,
child: child,
tooltip: tooltip,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
heroTag: heroTag,
elevation: elevation,
highlightElevation: highlightElevation,
disabledElevation: disabledElevation,
onPressed: onPressed,
mini: mini,
shape: shape,
clipBehavior: clipBehavior,
materialTapTargetSize: materialTapTargetSize,
isExtended: isExtended,
_sizeConstraints: _sizeConstraints
);
}
public readonly Widget child;
public readonly string tooltip;
public readonly Color foregroundColor;
public readonly Color backgroundColor;
public readonly object heroTag;
public readonly VoidCallback onPressed;
public readonly float? elevation;
public readonly float? highlightElevation;
public readonly float? disabledElevation;
public readonly bool mini;
public readonly ShapeBorder shape;
public readonly Clip clipBehavior;
public readonly bool isExtended;
public readonly MaterialTapTargetSize? materialTapTargetSize;
readonly BoxConstraints _sizeConstraints;
const float _defaultElevation = 6;
const float _defaultHighlightElevation = 12;
readonly ShapeBorder _defaultShape = new CircleBorder();
readonly ShapeBorder _defaultExtendedShape = new StadiumBorder();
public override Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme;
Color backgroundColor = this.backgroundColor
?? floatingActionButtonTheme.backgroundColor
?? theme.colorScheme.secondary;
Color foregroundColor = this.foregroundColor
?? floatingActionButtonTheme.foregroundColor
?? theme.accentIconTheme.color
?? theme.colorScheme.onSecondary;
float elevation = this.elevation
?? floatingActionButtonTheme.elevation
?? _defaultElevation;
float disabledElevation = this.disabledElevation
?? floatingActionButtonTheme.disabledElevation
?? elevation;
float highlightElevation = this.highlightElevation
?? floatingActionButtonTheme.highlightElevation
?? _defaultHighlightElevation;
MaterialTapTargetSize materialTapTargetSize = this.materialTapTargetSize
?? theme.materialTapTargetSize;
TextStyle textStyle = theme.accentTextTheme.button.copyWith(
color: foregroundColor,
letterSpacing: 1.2f
);
ShapeBorder shape = this.shape
?? floatingActionButtonTheme.shape
?? (this.isExtended ? this._defaultExtendedShape : this._defaultShape);
Widget result = null;
if (this.child != null) {
result = IconTheme.merge(
data: new IconThemeData(
color: foregroundColor),
child: this.child
);
}
result = new RawMaterialButton(
onPressed: this.onPressed,
elevation: elevation,
highlightElevation: highlightElevation,
disabledElevation: disabledElevation,
constraints: this._sizeConstraints,
materialTapTargetSize: materialTapTargetSize,
fillColor: backgroundColor,
textStyle: textStyle,
shape: shape,
clipBehavior: this.clipBehavior,
child: result);
if (this.tooltip != null) {
result = new Tooltip(
message: this.tooltip,
child: result);
}
if (this.heroTag != null) {
result = new Hero(
tag: this.heroTag,
child: result);
}
return result;
}
}
class _ChildOverflowBox : SingleChildRenderObjectWidget {
public _ChildOverflowBox(
Key key = null,
Widget child = null) : base(key: key, child: child) {
}
public override RenderObject createRenderObject(BuildContext context) {
return new _RenderChildOverflowBox();
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
}
}
class _RenderChildOverflowBox : RenderAligningShiftedBox {
public _RenderChildOverflowBox(
RenderBox child = null) : base(child: child, alignment: Alignment.center) {
}
protected override float computeMinIntrinsicWidth(float height) {
return 0.0f;
}
protected override float computeMinIntrinsicHeight(float width) {
return 0.0f;
}
protected override void performLayout() {
if (this.child != null) {
this.child.layout(new BoxConstraints(), parentUsesSize: true);
this.size = new Size(
Mathf.Max(this.constraints.minWidth, Mathf.Min(this.constraints.maxWidth, this.child.size.width)),
Mathf.Max(this.constraints.minHeight, Mathf.Min(this.constraints.maxHeight, this.child.size.height))
);
this.alignChild();
}
else {
this.size = this.constraints.biggest;
}
}
}
}

280
Runtime/material/float_action_button.cs


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

/Runtime/material/float_action_button_location.cs → /Runtime/material/floating_action_button_location.cs

/Runtime/material/float_action_button.cs.meta → /Runtime/material/floating_action_button.cs.meta

/Runtime/material/float_action_button_location.cs.meta → /Runtime/material/floating_action_button_location.cs.meta

正在加载...
取消
保存