Notifications
Clear all

[Closed] Generating UI dynamically?

Hi,

Is it possible to add UI elements dynamically based on a user parameter?

For example:

Let’s say I have an integer spinner which the user can adjust.

Beneath it, I want to have N edittext boxes, where N is the spinner’s value. And I would like it to be updated whenever N changes.

Is something like this possible?

5 Replies
 rdg

For rollouts this would be possible.
Take a look at the rolloutCreator or at P. Janssen’s UIControlManager [1].

The workflow should be something like this:
In the on changed handler of your spinner call a function the defines a new rollout. then destroy the old ui and create a new one.
I use this in my PSD2MAT [2] – but not in a slider.

Maybe this is possible with customAttributes as well.

Hope this helps.

Georg

[1] http://forums.cgsociety.org/showthread.php?f=98&t=496482
[2] http://www.preset.de/2007/0329/psd2mat/

Another option is to create, say 100, edit texts then move them outside the bouns of the rollout. Then when teh spinner changes value, you just move them in accordingly, and resize the rollout. The advantage of this is that you’re not destroying the rollout or controls and so any values the user has entered will be saved (if you don’t reset them).

This is a bit of code I posted a few weeks ago:


[left] [/left]
[left]global variety2 = 0
fn changerollouts variety = 
(
  if variety2 < variety then 
  ( 
   for j = 1 to (variety - variety2) do 
   ( 
 i = (variety2 + j) as string
 
 -- Begin Dynamic Rollout Generation --
 codestream = "" as stringstream
 format ("
 rollout box_% \"Box %\" height:400
 (
  edittext data width:133 pos:[6,6]
	
  on data changed true do
  (
   if data.text.count > 0 then 
   (
	boxer.subroll02.box_%.title = data.text
   )
   else
   (
   boxer.subroll02.box_%.title = \"Box %\"
   )
  )
 )
 ") i i i i i to:codestream
 format "addsubrollout boxer.subroll02 box_%" i to:codestream
 execute (codestream as string)
 codestream = undefined
 -- End Dynamic Rollout Generation --
   )
  )
  else
  (
   if variety2 > 1 then
   (
 for j = 1 to (variety2 - variety) do
 (
  i = (variety2 - j + 1) as string
  
  -- Begin Dynamic Rollout Destruction --  
  codestream = "" as stringstream
  format "removesubrollout boxer.subroll02 box_%" i to:codestream
  execute (codestream as string)
  codestream = undefined
  -- End Dynamic Rollout Destruction  -- 
  
 )
   )
  )
  variety2 = variety
)
 
rollout boxer "Boxes" height:360 width:200
( 
 subrollout subroll01 ""
 subrollout subroll02 ""
)
rollout setup "Setup"
(
 spinner vrty "Products:" type:#integer range:[1,15,1] pos:[32,7] width:65
 
 on vrty changed true do 
 (
  changerollouts vrty.value
 )
)
createdialog boxer
AddsubRollout boxer.subroll01 setup
boxer.subroll02.pos += [0,55]
boxer.subroll02.height += 250
boxer.subroll01.pos += [0,5]
boxer.subroll01.height += 45
changerollouts 1[/left]
[left] [/left]

You could also keep the dynamic method but then store the subroll’s contents into an array on destruction if it’s not empty.

I have a bit of code which does that but I can’t post it just because it’s too deeply embedded into ‘non-generic’ code. But it’s less than 20 lines of code effectively it:

Checks to see if the rollout values are empty on destruction.
If not it reads off all of the fields and saves it into a struct and saves the struct in an array.

On Load it checks to see if the array is undefined for that rolloutID and if it’s not it fills out the fields and then sets the array[id] to undefined.

Thank you very much for the help. Will surely come in handy at some stage. (For the particular task I was going to use it for, I decided to use a different approach)