您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
121 行
4.1 KiB
121 行
4.1 KiB
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 IconButtonUtils {
|
|
public const float _kMinButtonSize = 48.0f;
|
|
}
|
|
|
|
|
|
public class IconButton : StatelessWidget {
|
|
public IconButton(
|
|
Key key = null,
|
|
float iconSize = 24.0f,
|
|
EdgeInsets padding = null,
|
|
Alignment alignment = null,
|
|
Widget icon = null,
|
|
Color color = null,
|
|
Color highlightColor = null,
|
|
Color splashColor = null,
|
|
Color disableColor = null,
|
|
VoidCallback onPressed = null,
|
|
string tooltip = null) : base(key: key) {
|
|
D.assert(icon != null);
|
|
|
|
this.iconSize = iconSize;
|
|
this.padding = padding ?? EdgeInsets.all(8.0f);
|
|
this.alignment = alignment ?? Alignment.center;
|
|
this.icon = icon;
|
|
this.color = color;
|
|
this.highlightColor = highlightColor;
|
|
this.splashColor = splashColor;
|
|
disabledColor = disableColor;
|
|
this.onPressed = onPressed;
|
|
this.tooltip = tooltip;
|
|
}
|
|
|
|
public readonly float iconSize;
|
|
|
|
public readonly EdgeInsets padding;
|
|
|
|
public readonly Alignment alignment;
|
|
|
|
public readonly Widget icon;
|
|
|
|
public readonly Color color;
|
|
|
|
public readonly Color splashColor;
|
|
|
|
public readonly Color highlightColor;
|
|
|
|
public readonly Color disabledColor;
|
|
|
|
public readonly VoidCallback onPressed;
|
|
|
|
public readonly string tooltip;
|
|
|
|
public override Widget build(BuildContext context) {
|
|
D.assert(MaterialD.debugCheckHasMaterial(context));
|
|
Color currentColor;
|
|
if (onPressed != null) {
|
|
currentColor = color;
|
|
}
|
|
else {
|
|
currentColor = disabledColor ?? Theme.of(context).disabledColor;
|
|
}
|
|
|
|
Widget result = new ConstrainedBox(
|
|
constraints: new BoxConstraints(minWidth: IconButtonUtils._kMinButtonSize,
|
|
minHeight: IconButtonUtils._kMinButtonSize),
|
|
child: new Padding(
|
|
padding: padding,
|
|
child: new SizedBox(
|
|
height: iconSize,
|
|
width: iconSize,
|
|
child: new Align(
|
|
alignment: alignment,
|
|
child: IconTheme.merge(
|
|
data: new IconThemeData(
|
|
size: iconSize,
|
|
color: currentColor),
|
|
child: icon)
|
|
)
|
|
)
|
|
)
|
|
);
|
|
|
|
if (tooltip != null) {
|
|
result = new Tooltip(
|
|
message: tooltip,
|
|
child: result);
|
|
}
|
|
|
|
return new InkResponse(
|
|
onTap: () => {
|
|
if (onPressed != null) {
|
|
onPressed();
|
|
}
|
|
},
|
|
child: result,
|
|
highlightColor: highlightColor ?? Theme.of(context).highlightColor,
|
|
splashColor: splashColor ?? Theme.of(context).splashColor,
|
|
radius: Mathf.Max(
|
|
Material.defaultSplashRadius,
|
|
(iconSize + Mathf.Min(padding.horizontal, padding.vertical)) * 0.7f)
|
|
);
|
|
}
|
|
|
|
|
|
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
base.debugFillProperties(properties);
|
|
properties.add(new DiagnosticsProperty<Widget>("icon", icon, showName: false));
|
|
properties.add(new ObjectFlagProperty<VoidCallback>("onPressed", onPressed, ifNull: "disabled"));
|
|
properties.add(new StringProperty("tooltip", tooltip, defaultValue: null, quoted: false));
|
|
}
|
|
}
|
|
}
|