Update MUSliderHorizontal.cs

This commit is contained in:
MuHua-123
2024-12-06 15:43:44 +08:00
parent 4e498c5809
commit 511483319e
@@ -106,15 +106,21 @@ namespace MuHua {
tracker.style.width = CurrentPosition;
UpdateFloatField();
}
internal void UpdateFloatField(ChangeEvent<float> evt) {
float value = Mathf.Clamp(evt.newValue, MinValue, MaxValue);
slidingValue = (value - MinValue) / (MaxValue - MinValue);
tracker.style.width = CurrentPosition;
SlidingValueChanged?.Invoke(Value);
}
internal void UpdateFloatField(bool value) {
isDisplayInput = value;
floatField.style.display = isDisplayInput ? DisplayStyle.Flex : DisplayStyle.None;
}
internal void UpdateFloatField() {
floatField.value = Value;
floatField.SetValueWithoutNotify(Value);
}
internal float UpdateValue() {
float value = (MaxValue - MinValue) * SlidingValue;
float value = Mathf.Lerp(MinValue, MaxValue, SlidingValue);
if (dataType == RoundDataType.) { value = (float)Math.Round(value, 2); }
if (dataType == RoundDataType.) { value = Mathf.FloorToInt(value); }
return Mathf.Clamp(value, MinValue, MaxValue);
@@ -165,6 +171,8 @@ namespace MuHua {
dragger.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
dragger.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
floatField.RegisterCallback<ChangeEvent<float>>(UpdateFloatField);
container.RegisterCallback<PointerDownEvent>(ContainerDown);
}
private void DraggerDown(PointerDownEvent evt) {