Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: wallabie on June 24, 2014, 09:50:49 AM

Title: How to do a CenterOnChild with custom offset.
Post by: wallabie 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.
Title: Re: How to do a CenterOnChild with custom offset.
Post by: ArenMook 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);
Title: Re: How to do a CenterOnChild with custom offset.
Post by: wallabie 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)
Title: Re: How to do a CenterOnChild with custom offset.
Post by: ArenMook 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.
Title: Re: How to do a CenterOnChild with custom offset.
Post by: hexaust 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?
Title: Re: How to do a CenterOnChild with custom offset.
Post by: ArenMook 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
Title: Re: How to do a CenterOnChild with custom offset.
Post by: hexaust 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

(https://i.imgur.com/Fd7DSgM.png)

Title: Re: How to do a CenterOnChild with custom offset.
Post by: ArenMook on December 12, 2014, 11:07:18 PM
UIPanel has a clippingOffset value you can adjust that will let you do just that.