Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Canvas Slider Handle Positioning and Impose MinMax Limits to Slider Value #549

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ RectTransform:
m_AnchorMin: {x: 1, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 617.13, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &5677198132984834579
GameObject:
Expand Down
1 change: 1 addition & 0 deletions org.mixedrealitytoolkit.uxcore/Slider/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public float Value
{
if (this.value != value)
{
value = Mathf.Clamp(value, minValue, maxValue);
var oldSliderValue = this.value;
this.value = value;
OnValueUpdated.Invoke(new SliderEventData(oldSliderValue, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,30 @@ void UpdateHandle(SliderEventData data)
// Update the things that depend on the slider value.
void UpdateHandle(float value)
{
handle.position = SliderState.SliderStart.position + (value * SliderState.SliderTrackDirection);

switch (SliderDirection)
{
case Direction.LeftToRight:
fillVisual.anchorMax = new Vector2(value, 1.0f);
handle.anchorMin = new Vector2(value, handle.anchorMin.y);
handle.anchorMax = new Vector2(value, handle.anchorMax.y);
break;
case Direction.RightToLeft:
fillVisual.anchorMin = new Vector2(1.0f - value, 0.0f);
handle.anchorMin = new Vector2(1.0f - value, handle.anchorMin.y);
handle.anchorMax = new Vector2(1.0f - value, handle.anchorMax.y);
break;
case Direction.BottomToTop:
fillVisual.anchorMax = new Vector2(1.0f, value);
handle.anchorMin = new Vector2(handle.anchorMin.x, value);
handle.anchorMax = new Vector2(handle.anchorMax.x, value);
break;
case Direction.TopToBottom:
fillVisual.anchorMin = new Vector2(0.0f, 1.0f - value);
handle.anchorMin = new Vector2(handle.anchorMin.x, 1.0f - value);
handle.anchorMax = new Vector2(handle.anchorMax.x, 1.0f - value);
break;
}
handle.anchoredPosition = Vector3.zero;
}

void SetLayout(Direction direction)
Expand Down