Author Topic: Pattern to create tabs with ngui?  (Read 2641 times)

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Pattern to create tabs with ngui?
« on: April 10, 2013, 04:40:44 PM »
Hi there,

I am having alot of problems to create a UI with 2 tabs with enabled/disabled content.

Today I am using NGUI.SetActive to enable/disable tabs and content. Like:

  1. # Tabs.js
  2. function SetActiveTab(current: int) {
  3.         for (var i = 0 ; i < tabs.length ; i++)
  4.                 NGUITools.SetActive(tabs[i], i == current);
  5. }
  6.  
  7. # Tab0.js
  8. functoin Start() {
  9.     NGUITools.SetActive(button, false);
  10. }

When I activate a tab, its activate the disabled button too. OnEnable don't work because parent are enabled before its children.

I can only see some not to good solutions:

1) I must change the hidden content to disable Components instead GameObjects. Like:

  1. # Tab0.js
  2. function Start() {
  3.     for (var c: UIWidgetd in button.GetComponentsInChildren(UIWidgetd)) c.enabled = false;
  4. }

It works, but don't scale, in situations where you create tabs of tabs (or popups with tabs) we will have this problema again.

2) Instead disable, move it offscrean. Smells bad and I will have some problem enabling/disabling Anchors.

3) Broadcast some message after Active to allow any object to disabled again.

  1. NGUITools.SetActive(tab, true);
  2. parent.BroadcastMessage("EnabledAgainHa");
  3.  
Can someone see a better solution for the problem?
« Last Edit: April 10, 2013, 04:50:09 PM by sisso »

cgb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Pattern to create tabs with ngui?
« Reply #1 on: April 10, 2013, 05:14:15 PM »
I think you could have different Panels, one that is always on that shows the tab buttons. When the user clicks a tab, it activates a different Panel Hierarchy.

I use a setup like this
UIRoot
 - - Camera
 - - - - Control
 - - - - - - Panel Always On
 - - - - - - Panel A
 - - - - - - - - Anchor
 - - - - - - - - - - Widgets
 - - - - - - Panel B
 - - - - - - - - Anchor
 - - - - - - - - - - Widgets

sisso

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 46
    • View Profile
Re: Pattern to create tabs with ngui?
« Reply #2 on: April 10, 2013, 05:19:27 PM »
Same problem, if you disable on widget in Panel B, after user go back to PanelA, and back again to PanelB, it will appear.