浏览代码

Merge pull request #166 from UnityTech/slider

1.0 -> 1.2
/main
GitHub 6 年前
当前提交
98aaab40
共有 3 个文件被更改,包括 337 次插入120 次删除
  1. 232
      Runtime/material/slider.cs
  2. 213
      Runtime/material/slider_theme.cs
  3. 12
      Samples/UIWidgetSample/MaterialSample.cs

232
Runtime/material/slider.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;

using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;

}
class _RenderSlider : RenderBox {
static float _positionAnimationDurationMilliSeconds = 75;
static float _minimumInteractionTimeMilliSeconds = 500;
const float _minPreferredTrackWidth = 144.0f;
public _RenderSlider(
float? value = null,
int? divisions = null,

curve: Curves.easeInOut);
}
const float _positionAnimationDurationMilliSeconds = 75;
const float _overlayRadius = 16.0f;
const float _overlayDiameter = _overlayRadius * 2.0f;
const float _trackHeight = 2.0f;
const float _preferredTrackWidth = 144.0f;
const float _preferredTotalWidth = _preferredTrackWidth + _overlayDiameter;
const float _minimumInteractionTimeMilliSeconds = 500;
static readonly Animatable<float> _overlayRadiusTween = new FloatTween(begin: 0.0f, end: _overlayRadius);
float _maxSliderPartWidth {
get {
float maxValue = 0;
foreach (Size size in this._sliderPartSizes) {
if (size.width > maxValue) {
maxValue = size.width;
}
}
return maxValue;
}
}
float _maxSliderPartHeight {
get {
float maxValue = 0;
foreach (Size size in this._sliderPartSizes) {
if (size.width > maxValue) {
maxValue = size.width;
}
}
return maxValue;
}
}
List<Size> _sliderPartSizes {
get {
return new List<Size> {
this._sliderTheme.overlayShape.getPreferredSize(this.isInteractive, this.isDiscrete),
this._sliderTheme.thumbShape.getPreferredSize(this.isInteractive, this.isDiscrete),
this._sliderTheme.tickMarkShape.getPreferredSize(isEnabled: this.isInteractive,
sliderTheme: this.sliderTheme)
};
}
}
float _minPreferredTrackHeight {
get { return this._sliderTheme.trackHeight; }
}
_SliderState _state;
Animation<float> _overlayAnimation;

bool _active = false;
float _currentDragValue = 0.0f;
float _trackLength {
get { return this.size.width - _overlayDiameter; }
Rect _trackRect {
get {
return this._sliderTheme.trackShape.getPreferredRect(
parentBox: this,
offset: Offset.zero,
sliderTheme: this._sliderTheme,
isDiscrete: false
);
}
}
bool isInteractive {

float _getValueFromGlobalPosition(Offset globalPosition) {
float visualPosition =
(this.globalToLocal(globalPosition).dx - _overlayRadius) / this._trackLength;
(this.globalToLocal(globalPosition).dx - this._trackRect.left) / this._trackRect.width;
return this._getValueFromVisualPosition(visualPosition);
}

result = (result * this.divisions.Value).round() / this.divisions.Value;
result = (result * this.divisions.Value).round() * 1.0f / this.divisions.Value;
}
return result;

this._state.valueIndicatorController.status == AnimationStatus.completed) {
this._state.valueIndicatorController.reverse();
}
});
}
);
}
}
}

void _handleDragUpdate(DragUpdateDetails details) {
if (this.isInteractive) {
float valueDelta = details.primaryDelta.Value / this._trackLength;
float valueDelta = details.primaryDelta.Value / this._trackRect.width;
this._currentDragValue += valueDelta;
this.onChanged(this._discretize(this._currentDragValue));
}

protected override float computeMinIntrinsicWidth(float height) {
return Mathf.Max(_overlayDiameter,
this._sliderTheme.thumbShape.getPreferredSize(this.isInteractive, this.isDiscrete).width);
return _minPreferredTrackWidth + this._maxSliderPartWidth;
return _preferredTotalWidth;
return _minPreferredTrackWidth + this._maxSliderPartWidth;
return _overlayDiameter;
return Mathf.Max(this._minPreferredTrackHeight, this._maxSliderPartHeight);
return _overlayDiameter;
return Mathf.Max(this._minPreferredTrackHeight, this._maxSliderPartHeight);
}
protected override bool sizedByParent {

this.size = new Size(
this.constraints.hasBoundedWidth
? this.constraints.maxWidth
: _preferredTotalWidth,
: _minPreferredTrackWidth + this._maxSliderPartWidth,
: _overlayDiameter
: Mathf.Max(this._minPreferredTrackHeight, this._maxSliderPartHeight)
void _paintTickMarks(
Canvas canvas,
Rect trackLeft,
Rect trackRight,
Paint leftPaint,
Paint rightPaint) {
if (this.isDiscrete) {
const float tickRadius = _trackHeight / 2.0f;
float trackWidth = trackRight.right - trackLeft.left;
float dx = (trackWidth - _trackHeight) / this.divisions.Value;
if (dx >= 3.0 * _trackHeight) {
for (int i = 0; i <= this.divisions.Value; i += 1) {
float left = trackLeft.left + i * dx;
Offset center = new Offset(left + tickRadius, trackLeft.top + tickRadius);
if (trackLeft.contains(center)) {
canvas.drawCircle(center, tickRadius, leftPaint);
}
else if (trackRight.contains(center)) {
canvas.drawCircle(center, tickRadius, rightPaint);
}
}
}
}
}
void _paintOverlay(
Canvas canvas,
Offset center) {
Paint overlayPaint = new Paint {color = this._sliderTheme.overlayColor};
float radius = _overlayRadiusTween.evaluate(this._overlayAnimation);
canvas.drawCircle(center, radius, overlayPaint);
}
Canvas canvas = context.canvas;
float trackLength = this.size.width - 2 * _overlayRadius;
ColorTween activeTrackEnableColor = new ColorTween(begin: this._sliderTheme.disabledActiveTrackColor,
end: this._sliderTheme.activeTrackColor);
ColorTween inactiveTrackEnableColor = new ColorTween(begin: this._sliderTheme.disabledInactiveTrackColor,
end: this._sliderTheme.inactiveTrackColor);
ColorTween activeTickMarkEnableColor = new ColorTween(begin: this._sliderTheme.disabledActiveTickMarkColor,
end: this._sliderTheme.activeTickMarkColor);
ColorTween inactiveTickMarkEnableColor =
new ColorTween(begin: this._sliderTheme.disabledInactiveTickMarkColor,
end: this._sliderTheme.inactiveTickMarkColor);
Paint activeTrackPaint = new Paint {color = activeTrackEnableColor.evaluate(this._enableAnimation)};
Paint inactiveTrackPaint = new Paint {color = inactiveTrackEnableColor.evaluate(this._enableAnimation)};
Paint activeTickMarkPaint = new Paint {color = activeTickMarkEnableColor.evaluate(this._enableAnimation)};
Paint inactiveTickMarkPaint = new Paint
{color = inactiveTickMarkEnableColor.evaluate(this._enableAnimation)};
Paint leftTrackPaint = activeTrackPaint;
Paint rightTrackPaint = inactiveTrackPaint;
Paint leftTickMarkPaint = activeTickMarkPaint;
Paint rightTickMarkPaint = inactiveTickMarkPaint;
float trackRadius = _trackHeight / 2.0f;
float thumbGap = 2.0f;
Rect trackRect = this._sliderTheme.trackShape.getPreferredRect(
parentBox: this,
offset: offset,
sliderTheme: this._sliderTheme,
isDiscrete: this.isDiscrete
);
float trackVerticalCenter = offset.dy + (this.size.height) / 2.0f;
float trackLeft = offset.dx + _overlayRadius;
float trackTop = trackVerticalCenter - trackRadius;
float trackBottom = trackVerticalCenter + trackRadius;
float trackRight = trackLeft + trackLength;
float trackActive = trackLeft + trackLength * visualPosition;
float thumbRadius =
this._sliderTheme.thumbShape.getPreferredSize(this.isInteractive, this.isDiscrete).width / 2.0f;
float trackActiveLeft = Mathf.Max(0.0f,
trackActive - thumbRadius - thumbGap * (1.0f - this._enableAnimation.value));
float trackActiveRight =
Mathf.Min(trackActive + thumbRadius + thumbGap * (1.0f - this._enableAnimation.value), trackRight);
Rect trackLeftRect = Rect.fromLTRB(trackLeft, trackTop, trackActiveLeft, trackBottom);
Rect trackRightRect = Rect.fromLTRB(trackActiveRight, trackTop, trackRight, trackBottom);
Offset thumbCenter = new Offset(trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
Offset thumbCenter = new Offset(trackActive, trackVerticalCenter);
if (visualPosition > 0.0) {
canvas.drawRect(trackLeftRect, leftTrackPaint);
}
this._sliderTheme.trackShape.paint(
context,
offset,
parentBox: this,
sliderTheme: this._sliderTheme,
enableAnimation: this._enableAnimation,
thumbCenter: thumbCenter,
isDiscrete: this.isDiscrete,
isEnabled: this.isInteractive
);
if (visualPosition < 1.0) {
canvas.drawRect(trackRightRect, rightTrackPaint);
if (!this._overlayAnimation.isDismissed) {
this._sliderTheme.overlayShape.paint(
context,
thumbCenter,
activationAnimation: this._overlayAnimation,
enableAnimation: this._enableAnimation,
isDiscrete: this.isDiscrete,
labelPainter: this._labelPainter,
parentBox: this,
sliderTheme: this._sliderTheme,
value: this._value
);
this._paintOverlay(canvas, thumbCenter);
if (this.isDiscrete) {
float tickMarkWidth = this._sliderTheme.tickMarkShape.getPreferredSize(
isEnabled: this.isInteractive,
sliderTheme: this._sliderTheme
).width;
this._paintTickMarks(
canvas,
trackLeftRect,
trackRightRect,
leftTickMarkPaint,
rightTickMarkPaint
);
if ((trackRect.width - tickMarkWidth) / this.divisions.Value >= 3.0f * tickMarkWidth) {
for (int i = 0; i <= this.divisions; i++) {
float tickValue = i / this.divisions.Value;
float tickX = trackRect.left +
tickValue * (trackRect.width - tickMarkWidth) + tickMarkWidth / 2;
float tickY = trackRect.center.dy;
Offset tickMarkOffset = new Offset(tickX, tickY);
this._sliderTheme.tickMarkShape.paint(
context,
tickMarkOffset,
parentBox: this,
sliderTheme: this._sliderTheme,
enableAnimation: this._enableAnimation,
thumbCenter: thumbCenter,
isEnabled: this.isInteractive
);
}
}
}
if (this.isInteractive && this.label != null &&
this._valueIndicatorAnimation.status != AnimationStatus.dismissed) {
if (this.isInteractive && this.label != null && !this._valueIndicatorAnimation.isDismissed) {
if (this.showValueIndicator) {
this._sliderTheme.valueIndicatorShape.paint(
context,

213
Runtime/material/slider_theme.cs


public class SliderThemeData : Diagnosticable {
public SliderThemeData(
float? trackHeight = null,
Color activeTrackColor = null,
Color inactiveTrackColor = null,
Color disabledActiveTrackColor = null,

Color disabledThumbColor = null,
Color overlayColor = null,
Color valueIndicatorColor = null,
SliderTrackShape trackShape = null,
SliderTickMarkShape tickMarkShape = null,
SliderComponentShape overlayShape = null,
D.assert(trackHeight != null);
D.assert(activeTrackColor != null);
D.assert(inactiveTrackColor != null);
D.assert(disabledActiveTrackColor != null);

D.assert(disabledThumbColor != null);
D.assert(overlayColor != null);
D.assert(valueIndicatorColor != null);
D.assert(trackShape != null);
D.assert(tickMarkShape != null);
D.assert(overlayShape != null);
this.trackHeight = trackHeight.Value;
this.activeTrackColor = activeTrackColor;
this.inactiveTrackColor = inactiveTrackColor;
this.disabledActiveTrackColor = disabledActiveTrackColor;

this.disabledThumbColor = disabledThumbColor;
this.overlayColor = overlayColor;
this.valueIndicatorColor = valueIndicatorColor;
this.trackShape = trackShape;
this.tickMarkShape = tickMarkShape;
this.overlayShape = overlayShape;
this.valueIndicatorShape = valueIndicatorShape;
this.showValueIndicator = showValueIndicator.Value;
this.valueIndicatorTextStyle = valueIndicatorTextStyle;

const int overlayLightAlpha = 0x29;
return new SliderThemeData(
trackHeight: 2.0f,
activeTrackColor: primaryColor.withAlpha(activeTrackAlpha),
inactiveTrackColor: primaryColor.withAlpha(inactiveTrackAlpha),
disabledActiveTrackColor: primaryColorDark.withAlpha(disabledActiveTrackAlpha),

disabledThumbColor: primaryColorDark.withAlpha(disabledThumbAlpha),
overlayColor: primaryColor.withAlpha(overlayLightAlpha),
valueIndicatorColor: primaryColor.withAlpha(valueIndicatorAlpha),
trackShape: new RectangularSliderTrackShape(),
tickMarkShape: new RoundSliderTickMarkShape(),
overlayShape: new RoundSliderOverlayShape(),
public readonly float trackHeight;
public readonly Color activeTrackColor;

public readonly Color valueIndicatorColor;
public readonly SliderTrackShape trackShape;
public readonly SliderTickMarkShape tickMarkShape;
public readonly SliderComponentShape overlayShape;
public readonly SliderComponentShape thumbShape;
public readonly SliderComponentShape valueIndicatorShape;

TextStyle valueIndicatorTextStyle = null
) {
return new SliderThemeData(
trackHeight: trackHeight ?? this.trackHeight,
activeTrackColor: activeTrackColor ?? this.activeTrackColor,
inactiveTrackColor: inactiveTrackColor ?? this.inactiveTrackColor,
disabledActiveTrackColor: disabledActiveTrackColor ?? this.disabledActiveTrackColor,

disabledThumbColor: disabledThumbColor ?? this.disabledThumbColor,
overlayColor: overlayColor ?? this.overlayColor,
valueIndicatorColor: valueIndicatorColor ?? this.valueIndicatorColor,
trackShape: trackShape ?? this.trackShape,
tickMarkShape: tickMarkShape ?? this.tickMarkShape,
overlayShape: overlayShape ?? this.overlayShape,
valueIndicatorShape: valueIndicatorShape ?? this.valueIndicatorShape,
showValueIndicator: showValueIndicator ?? this.showValueIndicator,
valueIndicatorTextStyle: valueIndicatorTextStyle ?? this.valueIndicatorTextStyle

D.assert(a != null);
D.assert(b != null);
return new SliderThemeData(
trackHeight: MathUtils.lerpFloat(a.trackHeight, b.trackHeight, t),
activeTrackColor: Color.lerp(a.activeTrackColor, b.activeTrackColor, t),
inactiveTrackColor: Color.lerp(a.inactiveTrackColor, b.inactiveTrackColor, t),
disabledActiveTrackColor: Color.lerp(a.disabledActiveTrackColor, b.disabledActiveTrackColor, t),

disabledThumbColor: Color.lerp(a.disabledThumbColor, b.disabledThumbColor, t),
overlayColor: Color.lerp(a.overlayColor, b.overlayColor, t),
valueIndicatorColor: Color.lerp(a.valueIndicatorColor, b.valueIndicatorColor, t),
trackShape: t < 0.5 ? a.trackShape : b.trackShape,
tickMarkShape: t < 0.5 ? a.tickMarkShape : b.tickMarkShape,
overlayShape: t < 0.5 ? a.overlayShape : b.overlayShape,
valueIndicatorShape: t < 0.5 ? a.valueIndicatorShape : b.valueIndicatorShape,
showValueIndicator: t < 0.5 ? a.showValueIndicator : b.showValueIndicator,
valueIndicatorTextStyle: TextStyle.lerp(a.valueIndicatorTextStyle, b.valueIndicatorTextStyle, t)

return true;
}
return other.activeTrackColor == this.activeTrackColor
return other.trackHeight == this.trackHeight
&& other.activeTrackColor == this.activeTrackColor
&& other.inactiveTrackColor == this.inactiveTrackColor
&& other.disabledActiveTrackColor == this.disabledActiveTrackColor
&& other.disabledInactiveTrackColor == this.disabledInactiveTrackColor

&& other.disabledThumbColor == this.disabledThumbColor
&& other.overlayColor == this.overlayColor
&& other.valueIndicatorColor == this.valueIndicatorColor
&& other.trackShape == this.trackShape
&& other.tickMarkShape == this.tickMarkShape
&& other.overlayShape == this.overlayShape
&& other.valueIndicatorShape == this.valueIndicatorShape
&& other.showValueIndicator == this.showValueIndicator
&& other.valueIndicatorTextStyle == this.valueIndicatorTextStyle;

}
unchecked {
var hashCode = this.activeTrackColor.GetHashCode();
var hashCode = this.trackHeight.GetHashCode();
hashCode = (hashCode * 397) ^ this.activeTrackColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.inactiveTrackColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.disabledActiveTrackColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.disabledInactiveTrackColor.GetHashCode();

hashCode = (hashCode * 397) ^ this.disabledThumbColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.overlayColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.valueIndicatorColor.GetHashCode();
hashCode = (hashCode * 397) ^ this.trackShape.GetHashCode();
hashCode = (hashCode * 397) ^ this.tickMarkShape.GetHashCode();
hashCode = (hashCode * 397) ^ this.overlayShape.GetHashCode();
hashCode = (hashCode * 397) ^ this.valueIndicatorShape.GetHashCode();
hashCode = (hashCode * 397) ^ this.showValueIndicator.GetHashCode();
hashCode = (hashCode * 397) ^ this.valueIndicatorTextStyle.GetHashCode();

defaultValue: defaultData.overlayColor, level: DiagnosticLevel.debug));
properties.add(new DiagnosticsProperty<Color>("valueIndicatorColor", this.valueIndicatorColor,
defaultValue: defaultData.valueIndicatorColor));
properties.add(new DiagnosticsProperty<SliderTrackShape>("trackShape", this.trackShape,
defaultValue: defaultData.trackShape, level: DiagnosticLevel.debug));
properties.add(new DiagnosticsProperty<SliderTickMarkShape>("tickMarkShape", this.tickMarkShape,
defaultValue: defaultData.tickMarkShape, level: DiagnosticLevel.debug));
properties.add(new DiagnosticsProperty<SliderComponentShape>("overlayShape", this.overlayShape,
defaultValue: defaultData.overlayShape, level: DiagnosticLevel.debug));
properties.add(new DiagnosticsProperty<SliderComponentShape>("valueIndicatorShape",
this.valueIndicatorShape, defaultValue: defaultData.valueIndicatorShape, level: DiagnosticLevel.debug));
properties.add(new EnumProperty<ShowValueIndicator>("showValueIndicator", this.showValueIndicator,

public abstract void paint(
PaintingContext context,
Offset thumbCenter,
Offset center,
Animation<float> activationAnimation = null,
Animation<float> enableAnimation = null,
bool? isDiscrete = null,

public override void paint(
PaintingContext context,
Offset thumbCenter,
Offset center,
Animation<float> activationAnimation = null,
Animation<float> enableAnimation = null,
bool? isDiscrete = null,

}
}
public class RectangularSliderTrackShape : SliderTrackShape {
public RectangularSliderTrackShape(
float disabledThumbGapWidth = 2.0f) {
this.disabledThumbGapWidth = disabledThumbGapWidth;
}
public readonly float disabledThumbGapWidth;
public override Rect getPreferredRect(
RenderBox parentBox = null,
Offset offset = null,
SliderThemeData sliderTheme = null,
bool? isEnabled = null,
bool? isDiscrete = null) {
float overlayWidth = sliderTheme.overlayShape.getPreferredSize(isEnabled, isDiscrete).width;
float trackHeight = sliderTheme.trackHeight;
D.assert(overlayWidth >= 0);
D.assert(trackHeight >= 0);
D.assert(parentBox.size.width >= overlayWidth);
D.assert(parentBox.size.height >= trackHeight);
float trackLeft = offset.dx + overlayWidth / 2f;
float trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2f;
float trackWidth = parentBox.size.width - overlayWidth;
return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
}
public override void paint(
PaintingContext context,
Offset offset,
RenderBox parentBox = null,
SliderThemeData sliderTheme = null,
Animation<float> enableAnimation = null,
Offset thumbCenter = null,
bool? isEnabled = null,
bool? isDiscrete = null) {
if (sliderTheme.trackHeight == 0) {
return;
}
ColorTween activeTrackColorTween = new ColorTween(begin: sliderTheme.disabledActiveTrackColor,
end: sliderTheme.activeTrackColor);
ColorTween inactiveTrackColorTween = new ColorTween(begin: sliderTheme.disabledInactiveTrackColor,
end: sliderTheme.inactiveTrackColor);
Paint activePaint = new Paint {color = activeTrackColorTween.evaluate(enableAnimation)};
Paint inactivePaint = new Paint {color = inactiveTrackColorTween.evaluate(enableAnimation)};
Paint leftTrackPaint = activePaint;
Paint rightTrackPaint = inactivePaint;
float horizontalAdjustment = 0.0f;
if (!isEnabled.Value) {
float disabledThumbRadius = sliderTheme.thumbShape.getPreferredSize(false, isDiscrete).width / 2.0f;
float gap = this.disabledThumbGapWidth * (1.0f - enableAnimation.value);
horizontalAdjustment = disabledThumbRadius + gap;
}
Rect trackRect = this.getPreferredRect(
parentBox: parentBox,
offset: offset,
sliderTheme: sliderTheme,
isEnabled: isEnabled,
isDiscrete: isDiscrete
);
Rect leftTrackSegment = Rect.fromLTRB(trackRect.left, trackRect.top, thumbCenter.dx - horizontalAdjustment,
trackRect.bottom);
context.canvas.drawRect(leftTrackSegment, leftTrackPaint);
Rect rightTrackSegment = Rect.fromLTRB(thumbCenter.dx + horizontalAdjustment, trackRect.top,
trackRect.right, trackRect.bottom);
context.canvas.drawRect(rightTrackSegment, rightTrackPaint);
}
}
public class RoundSliderTickMarkShape : SliderTickMarkShape {
public RoundSliderTickMarkShape(
float? tickMarkRadius = null) {
this.tickMarkRadius = tickMarkRadius;
}
public readonly float? tickMarkRadius;
public override Size getPreferredSize(
SliderThemeData sliderTheme = null,
bool? isEnabled = null
) {
return Size.fromRadius(this.tickMarkRadius ?? sliderTheme.trackHeight / 2f);
}
public override void paint(
PaintingContext context,
Offset center,
RenderBox parentBox = null,
SliderThemeData sliderTheme = null,
Animation<float> enableAnimation = null,
Offset thumbCenter = null,
bool? isEnabled = null
) {
Color begin;
Color end;
bool isTickMarkRightOfThumb = center.dx > thumbCenter.dx;
begin = isTickMarkRightOfThumb
? sliderTheme.disabledInactiveTickMarkColor
: sliderTheme.disabledActiveTickMarkColor;
end = isTickMarkRightOfThumb ? sliderTheme.inactiveTickMarkColor : sliderTheme.activeTickMarkColor;
Paint paint = new Paint {color = new ColorTween(begin: begin, end: end).evaluate(enableAnimation)};
float tickMarkRadius = this.getPreferredSize(
isEnabled: isEnabled,
sliderTheme: sliderTheme
).width / 2f;
context.canvas.drawCircle(center, tickMarkRadius, paint);
}
}
public class RoundSliderThumbShape : SliderComponentShape {
public RoundSliderThumbShape(
float enabledThumbRadius = 6.0f,

}
}
public class RoundSliderOverlayShape : SliderComponentShape {
public RoundSliderOverlayShape(
float overlayRadius = 16.0f) {
this.overlayRadius = overlayRadius;
}
public readonly float overlayRadius;
public override Size getPreferredSize(bool? isEnabled, bool? isDiscrete) {
return Size.fromRadius(this.overlayRadius);
}
public override void paint(
PaintingContext context,
Offset center,
Animation<float> activationAnimation = null,
Animation<float> enableAnimation = null,
bool? isDiscrete = null,
TextPainter labelPainter = null,
RenderBox parentBox = null,
SliderThemeData sliderTheme = null,
float? value = null
) {
Canvas canvas = context.canvas;
FloatTween radiusTween = new FloatTween(
begin: 0.0f,
end: this.overlayRadius
);
canvas.drawCircle(
center,
radiusTween.evaluate(activationAnimation),
new Paint {color = sliderTheme.overlayColor}
);
}
}
public class PaddleSliderValueIndicatorShape : SliderComponentShape {
public PaddleSliderValueIndicatorShape() {
}

const float _bottomLobeRadius = 6.0f;
const float _bottomLobeStartAngle = -1.1f * Mathf.PI / 4.0f;
const float _bottomLobeEndAngle = 1.1f * 5 * Mathf.PI / 4.0f;
const float _bottomLobeEndAngle = 1.1f * 5f * Mathf.PI / 4.0f;
const float _labelPadding = 8.0f;
const float _distanceBetweenTopBottomCenters = 40.0f;
static readonly Offset _topLobeCenter = new Offset(0.0f, -_distanceBetweenTopBottomCenters);

if (!_debuggingLabelLocation) {
return true;
}
Offset leftCenter = _topLobeCenter - new Offset(leftWidthNeeded, 0.0f) + neckStretch;
Offset rightCenter = _topLobeCenter + new Offset(rightWidthNeeded, 0.0f) + neckStretch;
Rect valueRect = Rect.fromLTRB(

12
Samples/UIWidgetSample/MaterialSample.cs


namespace UIWidgetsSample {
public class MaterialSample : UIWidgetsSamplePanel {
const int testCaseId = 7;
const int testCaseId = 6;
readonly List<Widget> testCases = new List<Widget> {
new MaterialButtonWidget(),

public class MaterialSliderState : State<MaterialSliderWidget> {
float _value = 0.0f;
float _value = 0.8f;
void onChanged(float value) {
this.setState(() => { this._value = value; });

title: new Text("Slider and Indicators")),
body: new Column(
children: new List<Widget> {
new Container(
new Padding(
padding: EdgeInsets.only(top: 100.0f),
child: new Container(
divisions: 10,
min: 0.4f,
label: "Here",
)
}
)
);

正在加载...
取消
保存