|
|
|
|
|
|
using Rect = Unity.UIWidgets.ui.Rect; |
|
|
|
|
|
|
|
namespace Unity.UIWidgets.material { |
|
|
|
public enum _SliderType { |
|
|
|
material, |
|
|
|
adaptive |
|
|
|
} |
|
|
|
|
|
|
|
public class Slider : StatefulWidget { |
|
|
|
public Slider( |
|
|
|
Key key = null, |
|
|
|
|
|
|
int? divisions = null, |
|
|
|
string label = null, |
|
|
|
Color activeColor = null, |
|
|
|
Color inactiveColor = null |
|
|
|
Color inactiveColor = null, |
|
|
|
_SliderType _sliderType = _SliderType.material |
|
|
|
) : base(key: key) { |
|
|
|
D.assert(value != null); |
|
|
|
D.assert(min <= max); |
|
|
|
|
|
|
this.label = label; |
|
|
|
this.activeColor = activeColor; |
|
|
|
this.inactiveColor = inactiveColor; |
|
|
|
this._sliderType = _sliderType; |
|
|
|
} |
|
|
|
|
|
|
|
public static Slider adaptive( |
|
|
|
Key key = null, |
|
|
|
float? value = null, |
|
|
|
ValueChanged<float> onChanged = null, |
|
|
|
ValueChanged<float> onChangeStart = null, |
|
|
|
ValueChanged<float> onChangeEnd = null, |
|
|
|
float min = 0.0f, |
|
|
|
float max = 1.0f, |
|
|
|
int? divisions = null, |
|
|
|
string label = null, |
|
|
|
Color activeColor = null, |
|
|
|
Color inactiveColor = null |
|
|
|
) { |
|
|
|
return new Slider( |
|
|
|
key: key, |
|
|
|
value: value, |
|
|
|
onChanged: onChanged, |
|
|
|
onChangeStart: onChangeStart, |
|
|
|
onChangeEnd: onChangeEnd, |
|
|
|
min: min, |
|
|
|
max: max, |
|
|
|
divisions: divisions, |
|
|
|
label: label, |
|
|
|
activeColor: activeColor, |
|
|
|
inactiveColor: inactiveColor, |
|
|
|
_sliderType: _SliderType.adaptive |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public readonly float value; |
|
|
|
|
|
|
|
|
|
|
public readonly Color inactiveColor; |
|
|
|
|
|
|
|
public readonly _SliderType _sliderType; |
|
|
|
|
|
|
|
public override State createState() { |
|
|
|
return new _SliderState(); |
|
|
|
} |
|
|
|
|
|
|
base.debugFillProperties(properties); |
|
|
|
properties.add(new FloatProperty("value", value)); |
|
|
|
properties.add(new ObjectFlagProperty<ValueChanged<float>>("onChanged", onChanged, ifNull: "disabled")); |
|
|
|
properties.add(ObjectFlagProperty<ValueChanged<float>>.has("onChangeStart", onChangeStart)); |
|
|
|
properties.add(ObjectFlagProperty<ValueChanged<float>>.has("onChangeEnd", onChangeEnd)); |
|
|
|
properties.add(new IntProperty("divisions", divisions)); |
|
|
|
properties.add(new StringProperty("label", label)); |
|
|
|
properties.add(new ColorProperty("activeColor", activeColor)); |
|
|
|
properties.add(new ColorProperty("inactiveColor", inactiveColor)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
? (value - widget.min) / (widget.max - widget.min) |
|
|
|
: 0.0f; |
|
|
|
} |
|
|
|
|
|
|
|
const double _defaultTrackHeight = 2; |
|
|
|
static readonly SliderTrackShape _defaultTrackShape = new RoundedRectSliderTrackShape(); |
|
|
|
static readonly SliderTickMarkShape _defaultTickMarkShape = new RoundSliderTickMarkShape(); |
|
|
|
static readonly SliderComponentShape _defaultOverlayShape = new RoundSliderOverlayShape(); |
|
|
|
static readonly SliderComponentShape _defaultThumbShape = new RoundSliderThumbShape(); |
|
|
|
static readonly SliderComponentShape _defaultValueIndicatorShape = new PaddleSliderValueIndicatorShape(); |
|
|
|
static readonly ShowValueIndicator _defaultShowValueIndicator = ShowValueIndicator.onlyForDiscrete; |
|
|
|
|
|
|
|
public override Widget build(BuildContext context) { |
|
|
|
D.assert(material_.debugCheckHasMaterial(context)); |
|
|
|