Skip to content

Commit

Permalink
ScrollBar done
Browse files Browse the repository at this point in the history
  • Loading branch information
qiankanglai committed Oct 12, 2016
1 parent d478c66 commit 5104ca9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Assets/Scripts/Editor/SGDefaultControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public struct Resources
private const float kWidth = 160f;
private const float kThickHeight = 30f;
private const float kThinHeight = 20f;
private static Vector2 s_ThickElementSize = new Vector2(kWidth, kThickHeight);
//private static Vector2 s_ThickElementSize = new Vector2(kWidth, kThickHeight);
//private static Vector2 s_ThinElementSize = new Vector2(kWidth, kThinHeight);
//private static Vector2 s_ImageElementSize = new Vector2(100f, 100f);
private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f);
private static Color s_PanelColor = new Color(1f, 1f, 1f, 0.392f);
//private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f);
//private static Color s_PanelColor = new Color(1f, 1f, 1f, 0.392f);
private static Color s_TextColor = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f);

// Helper methods at top
Expand Down
36 changes: 26 additions & 10 deletions Assets/Scripts/LoopScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,23 +815,39 @@ public float verticalNormalizedPosition
SetNormalizedPosition(value, 1);
}
}

// TODO
private void SetHorizontalNormalizedPosition(float value) { /*SetNormalizedPosition(value, 0);*/ }
private void SetVerticalNormalizedPosition(float value) { /*SetNormalizedPosition(value, 1);*/ }

private void SetHorizontalNormalizedPosition(float value) { SetNormalizedPosition(value, 0); }
private void SetVerticalNormalizedPosition(float value) { SetNormalizedPosition(value, 1); }

private void SetNormalizedPosition(float value, int axis)
{
if (totalCount <= 0 || itemTypeEnd <= itemTypeStart)
return;

EnsureLayoutHasRebuilt();
UpdateBounds();
// How much the content is larger than the view.
float hiddenLength = m_ContentBounds.size[axis] - m_ViewBounds.size[axis];
// Where the position of the lower left corner of the content bounds should be, in the space of the view.
float contentBoundsMinPosition = m_ViewBounds.min[axis] - value * hiddenLength;
// The new content localPosition, in the space of the view.
float newLocalPosition = m_Content.localPosition[axis] + contentBoundsMinPosition - m_ContentBounds.min[axis];

//==========LoopScrollRect==========
Vector3 localPosition = m_Content.localPosition;
float newLocalPosition = localPosition[axis];
if (axis == 0)
{
float elementSize = m_ContentBounds.size.x / (itemTypeEnd - itemTypeStart);
float totalSize = elementSize * totalCount;
float offset = m_ContentBounds.min.x - elementSize * itemTypeStart;

newLocalPosition += m_ViewBounds.min.x - value * (totalSize - m_ViewBounds.size[axis]) - offset;
}
else if(axis == 1)
{
float elementSize = m_ContentBounds.size.y / (itemTypeEnd - itemTypeStart);
float totalSize = elementSize * totalCount;
float offset = m_ContentBounds.max.y + elementSize * itemTypeStart;

newLocalPosition -= offset - value * (totalSize - m_ViewBounds.size.y) - m_ViewBounds.max.y;
}
//==========LoopScrollRect==========

if (Mathf.Abs(localPosition[axis] - newLocalPosition) > 0.01f)
{
localPosition[axis] = newLocalPosition;
Expand Down

0 comments on commit 5104ca9

Please sign in to comment.