Message Boards Message Boards

0
|
2292 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Design the controls of a DynamicModule as a pure function?

Posted 8 years ago

Dear colleagues,

I try to write the well-known design of the controls in a compact form, using the concept of a pure function.

Source:

DynamicModule [ {  mm = Array [m, 5],n },  
Column[{
Row [{"n   " , Slider[Dynamic[n], {1, 5, 1}], Dynamic[n] }],
Dynamic[Grid[
Table[  
With[{i = i }, { "m" <> ToString [i] ,  Slider[Dynamic[m[i]], {1, (11 -  n), 1} ], Dynamic [m[i]]  }],  {i, n}]   
]]   }]
]

The modified code:

DynamicModule [ {  mm = Array [m, 5],n }, 

cont =  Row [{ #1 ,  Slider[Dynamic[ #2 ], {1, #3, 1}],  "   ",  Dynamic[ #2 ]  }]&;

Column[{
cont ["n   ", n , 5],

Dynamic[Grid[
Table[
With[{i = i }, { cont [ "m" <> ToString [i] , m[i] ,  (11 - n)  ] } ],  {i, n}]
]]   }]

]

It is clear that the problems lie in the assignment inside Table[ ]

Thanks in advance for your support. E.T.

POSTED BY: Eugen Tsarfin

The idea comes from Roman Osipov . He consulted me this day in 1 Hour in the russian community for WM . This post was 13 days unanswered. One uses attribute HoldAll by pure function.

DynamicModule [ { mm = Array [m, 5],n } ,
cont =Function [ {t,x, xmax} , Row [{ t , Slider[Dynamic[ x ], {1, xmax, 1}], " ", Dynamic[ x ] }], HoldAll];
Column[{
cont ["n ", n , 5],
Dynamic[Grid[Table[
With[{i = i }, {cont ["m" <> ToString [i] , m[i] , 10 - n ] }] , {i, n}] ]]
}]]

And... A slyder with names, dates and buttons for the fine tuning:

DynamicModule [ { mm = Array [m, 5],n } ,
cont =  Function [{t,x,xmin,xmax} , Row [{ t , " ", Slider[Dynamic[ x ], { xmin, xmax, 1}], " ", Dynamic[x ] , " ", 
Button [" +1" , If [ x>= xmax, x= xmax, ++x ] ] , " ", Button [" -1" , If [ x <= xmin, x = xmin ,— x ] ] } ], HoldAll] ; 
Column[{ cont ["n ", n ,1, 5], Dynamic[Grid[Table[
With[{i = i }, {cont ["m" <> ToString [i] , m[i] , 1, 10 - n ] }] , {i, n}] ]]
}]] 

Voila!

POSTED BY: Eugen Tsarfin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract