Hello Guest

Author Topic: UILayoutContainerSizer reset layout  (Read 4667 times)

calclavia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
UILayoutContainerSizer reset layout
« on: November 06, 2013, 02:46:50 pm »
Hi,

I'd like to ask if there is a function I can call on the UILayoutContainerSizer to make it reset all the UI elements inside of it to have fixed size during runtime (similar to the button pressed in the editor)?

I have a level selection menu with buttons being added in real-time based on how many levels are loaded. I need them to be able to layout-evenly row by row. It's a very typical level selection menu:



Any help is appreciated.

Thanks,
Calclavia

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: UILayoutContainerSizer reset layout
« Reply #1 on: November 06, 2013, 09:04:41 pm »
The scrollable area sample (#5) shows a demo of adding fixed size objects to layout container sizer. I think that should do what you need.

calclavia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: UILayoutContainerSizer reset layout
« Reply #2 on: November 07, 2013, 02:37:18 pm »
Thanks! That worked! Is there a way I can make it automatically create new lines? I want to have 3 columns (each with about 5-6 buttons for different levels) or do I have to do that manually by creating 3 layout containers?

Example of one column:



Also, is there a way to add an event so when someone clicks on the button, it will call a function with a specific parameter based on the id of that button?

Something like:

onClick += loadLevel(levelID);

Many thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: UILayoutContainerSizer reset layout
« Reply #3 on: November 07, 2013, 06:33:44 pm »
You can't do multiline automatically. If you want that functionality, it might be easier to just write a new LayoutContainerSizer that does this. The code that handles this is pretty straightforward - tk2dUILayoutContainerSizer.DoChildLayout is where everything happens. It'll be a lot easier if you only care about fixed size items.

calclavia

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: UILayoutContainerSizer reset layout
« Reply #4 on: November 08, 2013, 04:48:26 pm »
Thanks, I'll work around that then.

You might have missed my second question:

Is there a way to add an event so when someone clicks on the button, it will call a function with a specific parameter based on the id of that button?

Something like:

onClick += loadLevel(levelID);

Right now I can add an event for a function without parameter. Is there a way to do it for functions with parameters?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: UILayoutContainerSizer reset layout
« Reply #5 on: November 08, 2013, 05:20:51 pm »
use OnClickUIItem - that will pass a reference to your object to the callback, you can map that to levelIds or something somehow.