Skip to content

Commit

Permalink
Fix Canvas Slider Handle Positioning and Impose MinMax Limits to Slid…
Browse files Browse the repository at this point in the history
…er Value (#549)
  • Loading branch information
marlenaklein-msft authored Nov 10, 2023
1 parent f669f5a commit fb8de1f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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

0 comments on commit fb8de1f

Please sign in to comment.