Permalink
Browse files

ScrollableContainer now handles child objects and text clipping.

  • Loading branch information...
1 parent 3f7ff9b commit 81398d392bd0640c5c46b89d68a0a1c7b809cf2d @nsxdavid nsxdavid committed Dec 29, 2011
Binary file not shown.
@@ -6,7 +6,7 @@
public class ScrollableContainerManager : MonoBehaviour
{
private bool _movedContainer;
-
+ public UIToolkit TextManager;
void Start()
{
@@ -30,6 +30,27 @@ void Start()
{
touchable = UIButton.create( "optionsUp.png", "optionsDown.png", 0, 0 );
}
+ if (i == 1) {
+ var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
+ ch.parentUIObject = touchable;
+ ch.pixelsFromRight(0);
+ ch.client.name = "TEST THINGY";
+ ch.scale = new Vector3(0.5f, 0.5f, 1);
+ }
+ if (i == 4) {
+ var text = new UIText(TextManager, "prototype", "prototype.png");
+
+ var helloText = text.addTextInstance("Child Text", 0, 0,0.5f,-1,Color.cyan,UITextAlignMode.Center,UITextVerticalAlignMode.Middle);
+ helloText.parentUIObject = touchable;
+ helloText.positionCenter();
+
+ var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
+ ch.parentUIObject = helloText;
+ ch.pixelsFromRight(-16);
+ ch.client.name = "subsub";
+ ch.scale = new Vector3(0.25f, 0.25f, -2);
+ }
+
// only add a touchUpInside handler for buttons
if( touchable is UIButton )
Binary file not shown.
@@ -256,9 +256,7 @@ protected virtual void layoutChildren()
// Refresh child position to proper positions
foreach (var item in _children) {
- // if (!item.hidden) {
item.refreshPosition();
- // }
}
}
@@ -55,19 +55,46 @@ private void calculateMinMaxInsets()
// now that we have new insets clip
clipToBounds();
}
-
+
+ ITouchable TestTouchable(UIObject touchableObj, Vector2 touchPosition)
+ {
+
+
+ foreach (Transform t in touchableObj.client.transform) {
+ UIElement uie = t.GetComponent<UIElement>();
+ if (uie != null) {
+ UIObject o = t.GetComponent<UIElement>().UIObject;
+ if (o != null) {
+ var touched = TestTouchable(o, touchPosition);
+ if (touched != null)
+ return touched;
+ }
+ }
+ }
+
+ ITouchable touchable = touchableObj as ITouchable;
+ if (touchable != null) {
+ if (touchable.hitTest(touchPosition))
+ return touchable as ITouchable;
+ }
+
+
+
+ return null;
+ }
protected ITouchable getButtonForScreenPosition( Vector2 touchPosition )
{
// we loop backwards so that any clipped elements at the top dont try to override the hitTest
// due to their frame overlapping the touchable below
for( int i = _children.Count - 1; i >= 0; i-- )
{
- var touchable = _children[i] as ITouchable;
+ var touchable = _children[i];
if( touchable != null )
{
- if( touchable.hitTest( touchPosition ) )
- return touchable;
+ ITouchable touched = TestTouchable(touchable, touchPosition); // Recursive
+ if (touched != null)
+ return touched;
}
}
@@ -0,0 +1,7 @@
+using UnityEngine;
+using System.Collections;
+
+public class UIElement : MonoBehaviour {
+
+ public UIObject UIObject;
+}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -29,6 +29,10 @@ public UIObject()
_client.transform.parent = UI.instance.transform; // Just for orginization in the hierarchy
_client.layer = UI.instance.layer; // Set the proper layer so we only render on the UI camera
+ UIElement uie = _client.AddComponent<UIElement>();
+ uie.UIObject = this;
+
+
// Cache the clientTransform
clientTransform = _client.transform;
// Create a default anchor info object
@@ -135,8 +135,7 @@ public bool clipped
return;
_clipped = value;
- if( _clipped )
- _clippedTopYOffset = 0;
+ _clippedTopYOffset = 0;
updateVertPositions();
manager.updateUV( this );
@@ -263,18 +262,18 @@ public void updateVertPositions()
if( gameObjectOriginInCenter )
{
// Some objects need to rotate so we set the origin at the center of the GO
- v1 = new Vector3( -width / 2, height / 2, 0 ); // Upper-left
- v2 = new Vector3( -width / 2, -height / 2, 0 ); // Lower-left
- v3 = new Vector3( width / 2, -height / 2, 0 ); // Lower-right
- v4 = new Vector3( width / 2, height / 2, 0 ); // Upper-right
+ v1 = new Vector3( -width / 2, height / 2 - _clippedTopYOffset, 0 ); // Upper-left
+ v2 = new Vector3(-width / 2, -height / 2 - _clippedTopYOffset, 0); // Lower-left
+ v3 = new Vector3(width / 2, -height / 2 - _clippedTopYOffset, 0); // Lower-right
+ v4 = new Vector3(width / 2, height / 2 - _clippedTopYOffset, 0); // Upper-right
}
else
{
// Make the origin the top-left corner of the GO
- v1 = new Vector3( 0, 0, 0 ); // Upper-left
- v2 = new Vector3( 0, -height, 0 ); // Lower-left
- v3 = new Vector3( width, -height, 0 ); // Lower-right
- v4 = new Vector3( width, 0, 0 ); // Upper-right
+ v1 = new Vector3(0, 0 - _clippedTopYOffset, 0); // Upper-left
+ v2 = new Vector3(0, -height - _clippedTopYOffset, 0); // Lower-left
+ v3 = new Vector3(width, -height - _clippedTopYOffset, 0); // Lower-right
+ v4 = new Vector3(width, 0 - _clippedTopYOffset, 0); // Upper-right
}
}
@@ -286,18 +285,16 @@ public void updateVertPositions()
/// </summary>
public void setClippedSize( float width, float height, bool clippingTop )
{
- _clippedWidth = width;
- _clippedHeight = height;
+ _clippedWidth = width;
+ _clippedHeight = height;
if( clippingTop )
_clippedTopYOffset = _height - _clippedHeight;
else
_clippedTopYOffset = 0;
- position = new Vector3( position.x, position.y - _clippedTopYOffset, position.z );
-
updateVertPositions();
- updateTransform();
+ updateTransform();
}
Oops, something went wrong.

0 comments on commit 81398d3

Please sign in to comment.