Author Topic: wrapping UIGrid contents  (Read 4608 times)

jrhee

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 13
    • View Profile
wrapping UIGrid contents
« on: July 27, 2014, 10:33:41 PM »
Hi Aren,

I have a horizontal UIGrid with a column limit of 3. I'd like to have the grid contents wrap onto additional rows if the combined cell width exceeds the grid widget dimensions (example attached). Is this possible currently out of the box? Would like to check before scripting something.



Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: wrapping UIGrid contents
« Reply #1 on: July 27, 2014, 11:25:31 PM »
There is nothing in NGUI that would facilitate this kind of functionality -- you would need to code it yourself.

jrhee

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 13
    • View Profile
Re: wrapping UIGrid contents
« Reply #2 on: July 28, 2014, 02:58:13 AM »
Ok thanks- here's the script I came up with in case anyone's interested.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class UIGridWrapping : UIGrid {
  5.  
  6.         void Start()    {
  7.                 UpdateMaxPerLine ();
  8.                 base.Start ();
  9.         }
  10.  
  11.         [ContextMenu("Execute")]
  12.         public override void Reposition()       {
  13.                 UpdateMaxPerLine();
  14.                 base.Reposition ();
  15.         }
  16.  
  17.         void UpdateMaxPerLine() {
  18.                 maxPerLine = (int) (GetComponent<UIWidget>().width/cellWidth);
  19.         }
  20. }
  21.