Author Topic: How to do a CenterOnChild with custom offset.  (Read 4498 times)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
How to do a CenterOnChild with custom offset.
« on: June 24, 2014, 09:50:49 AM »
Use Case:

When the user clicks on an item that is half way out of the left boundary, the item should move so that it is just inside of the boundary and not to the center of the SV.  Perhaps there is another better way to do this instead of adding an offset to the CenterOnChild.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #1 on: June 25, 2014, 05:19:07 AM »
Yeah it wouldn't be CenterOnChild anymore. Easiest way to do this is to set a UICenterOnChild.onCenter, and in that function just call UIScrollView's RestrictWithinBounds(true);

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #2 on: June 26, 2014, 10:57:58 AM »
"Easiest way to do this is to set a UICenterOnChild.onCenter, and in that function just call UIScrollView's RestrictWithinBounds(true);"

Not sure how you mean.  Let's see if I understand correctly.

1. Add a CenterOnChild on the Grid of the SV.
2. set a callback function for onCenter and in this function, set the SV's RestrictWithinBounds(true)
« Last Edit: June 26, 2014, 11:15:27 AM by wallabie »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #3 on: June 26, 2014, 11:26:57 AM »
Yup, that's right -- except you wouldn't be "setting" the RestrictWithinBounds(true). You'd be simply calling that function. I assume that's what you meant.

hexaust

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 1
  • Posts: 35
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #4 on: December 11, 2014, 06:17:51 AM »
Yup, that's right -- except you wouldn't be "setting" the RestrictWithinBounds(true). You'd be simply calling that function. I assume that's what you meant.

This doesn't work, or it works very weird, like only the first time. Is there any other way of making the CenterOnChild work with the scrollview`s bounds?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #5 on: December 11, 2014, 09:18:01 AM »
Work with the scroll view's bounds? Not sure what you mean by that.

Adding an offset to center on child is as simple as adding an offset to your elements. Ie: instead of having this:

Grid
- Item 0
- Item 1
- Item 2

...you would have;

Grid
- Offset 0
-- Item 0
- Offset 1
-- Item 1
- Offset 2
-- Item 2

hexaust

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 1
  • Posts: 35
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #6 on: December 11, 2014, 09:23:00 AM »
I don't think I understand, I don't want to add offset to the elements, I want to move the scroll view so the desired element to be as centered as possible within the restriction of the panel.

This image illustrates the present behavior




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to do a CenterOnChild with custom offset.
« Reply #7 on: December 12, 2014, 11:07:18 PM »
UIPanel has a clippingOffset value you can adjust that will let you do just that.