|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class _RenderSlider : RenderBox { |
|
|
|
class _RenderSlider : RelayoutWhenSystemFontsChangeMixinRenderBox { |
|
|
|
static float _positionAnimationDurationMilliSeconds = 75; |
|
|
|
static float _minimumInteractionTimeMilliSeconds = 500; |
|
|
|
|
|
|
|
|
|
|
int? divisions = null, |
|
|
|
string label = null, |
|
|
|
SliderThemeData sliderTheme = null, |
|
|
|
ThemeData theme = null, |
|
|
|
MediaQueryData mediaQueryData = null, |
|
|
|
RuntimePlatform? platform = null, |
|
|
|
ValueChanged<float> onChanged = null, |
|
|
|
|
|
|
TextDirection? texDirection = null |
|
|
|
TextDirection? textDirection = null |
|
|
|
|
|
|
|
|
|
|
|
this.onChangeStart = onChangeStart; |
|
|
|
this.onChangeEnd = onChangeEnd; |
|
|
|
_platform = platform; |
|
|
|
|
|
|
_sliderTheme = sliderTheme; |
|
|
|
_theme = theme; |
|
|
|
_textDirection = textDirection.Value; |
|
|
|
|
|
|
|
_updateLabelPainter(); |
|
|
|
GestureArenaTeam team = new GestureArenaTeam(); |
|
|
|
|
|
|
float maxValue = 0; |
|
|
|
foreach (Size size in _sliderPartSizes) { |
|
|
|
if (size.width > maxValue) { |
|
|
|
maxValue = size.width; |
|
|
|
maxValue = size.height; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
public ValueChanged<float> onChangeStart; |
|
|
|
public ValueChanged<float> onChangeEnd; |
|
|
|
|
|
|
|
public TextDirection textDirection { |
|
|
|
get { return _textDirection; } |
|
|
|
set { |
|
|
|
if (value == _textDirection) { |
|
|
|
return; |
|
|
|
} |
|
|
|
_textDirection = value; |
|
|
|
_updateLabelPainter(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TextDirection _textDirection; |
|
|
|
|
|
|
|
public bool showValueIndicator { |
|
|
|
get { |
|
|
|
bool showValueIndicator = false; |
|
|
|
|
|
|
get { |
|
|
|
switch (_platform) { |
|
|
|
case RuntimePlatform.IPhonePlayer: |
|
|
|
case RuntimePlatform.OSXPlayer: |
|
|
|
case RuntimePlatform.OSXEditor: |
|
|
|
return 0.1f; |
|
|
|
default: |
|
|
|
return 0.05f; |
|
|
|
|
|
|
style: _sliderTheme.valueIndicatorTextStyle, |
|
|
|
text: label |
|
|
|
); |
|
|
|
_labelPainter.textDirection = textDirection; |
|
|
|
_labelPainter.textScaleFactor = _mediaQueryData.textScaleFactor; |
|
|
|
_labelPainter.layout(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
markNeedsLayout(); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void systemFontsDidChange() { |
|
|
|
base.systemFontsDidChange(); |
|
|
|
_labelPainter.markNeedsLayout(); |
|
|
|
_updateLabelPainter(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void attach(object owner) { |
|
|
|
base.attach(owner); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
float _getValueFromVisualPosition(float visualPosition) { |
|
|
|
switch (textDirection) { |
|
|
|
case TextDirection.rtl: |
|
|
|
return 1.0f - visualPosition; |
|
|
|
case TextDirection.ltr: |
|
|
|
return visualPosition; |
|
|
|
} |
|
|
|
return visualPosition; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void _handleDragUpdate(DragUpdateDetails details) { |
|
|
|
if (isInteractive) { |
|
|
|
float valueDelta = details.primaryDelta.Value / _trackRect.width; |
|
|
|
_currentDragValue += valueDelta; |
|
|
|
switch (textDirection) { |
|
|
|
case TextDirection.rtl: |
|
|
|
_currentDragValue -= valueDelta; |
|
|
|
break; |
|
|
|
case TextDirection.ltr: |
|
|
|
_currentDragValue += valueDelta; |
|
|
|
break; |
|
|
|
} |
|
|
|
onChanged(_discretize(_currentDragValue)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
public override void paint(PaintingContext context, Offset offset) { |
|
|
|
float value = _state.positionController.value; |
|
|
|
float visualPosition = value; |
|
|
|
switch (textDirection) { |
|
|
|
case TextDirection.rtl: |
|
|
|
visualPosition = 1.0f - value; |
|
|
|
break; |
|
|
|
case TextDirection.ltr: |
|
|
|
visualPosition = value; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
Rect trackRect = _sliderTheme.trackShape.getPreferredRect( |
|
|
|
parentBox: this, |
|
|
|
|
|
|
parentBox: this, |
|
|
|
sliderTheme: _sliderTheme, |
|
|
|
enableAnimation: _enableAnimation, |
|
|
|
textDirection: _textDirection, |
|
|
|
thumbCenter: thumbCenter, |
|
|
|
isDiscrete: isDiscrete, |
|
|
|
isEnabled: isInteractive |
|
|
|
|
|
|
labelPainter: _labelPainter, |
|
|
|
parentBox: this, |
|
|
|
sliderTheme: _sliderTheme, |
|
|
|
textDirection: _textDirection, |
|
|
|
value: _value |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
parentBox: this, |
|
|
|
sliderTheme: _sliderTheme, |
|
|
|
enableAnimation: _enableAnimation, |
|
|
|
textDirection: _textDirection, |
|
|
|
thumbCenter: thumbCenter, |
|
|
|
isEnabled: isInteractive |
|
|
|
); |
|
|
|
|
|
|
labelPainter: _labelPainter, |
|
|
|
parentBox: this, |
|
|
|
sliderTheme: _sliderTheme, |
|
|
|
textDirection: _textDirection, |
|
|
|
value: _value |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
labelPainter: _labelPainter, |
|
|
|
parentBox: this, |
|
|
|
sliderTheme: _sliderTheme, |
|
|
|
textDirection: _textDirection, |
|
|
|
value: _value |
|
|
|
); |
|
|
|
} |