PDA

View Full Version : dynamic Button caption?


bhnh
03-29-2008, 02:00 PM
Anyone know if there's a way to change the caption on a Button when it's pressed? I'm thinking of a Boolean-type situation, where clicking the Button alternates the Boolean state between true and false. So the caption would read "Click for true" or "Click for false" depending on the Boolean state. Many thanks.

bhnh
03-29-2008, 02:25 PM
Problem solved...
(
rollout test "test" (

button pressthis "Press for true"

on pressthis pressed do
(
text1 = pressthis.text
if text1 == "Press for true" then
(
pressthis.text = "Press for false"
)
else pressthis.text = "Press for true"
)
)
createdialog test
)

EricDLegare
03-29-2008, 02:40 PM
Have you looked into CheckButtons, they could esaily do this.


This is a little exemple with buttons ^_^


local bState = false;
on btn_Button pressed do
(
___bState = not(bState);
___btn_Button.caption = ("Click for " + ((not(bState)) as string));
)

bhnh
03-29-2008, 02:53 PM
That's a neat alternate solution, Eric. Thanks! :thumbsup:

bhnh
03-29-2008, 08:33 PM
I suppose it's obvious, but I just realized this method can also make labels dynamic...

rollout test "Dynamic Label"
(
label lbl "Apples"
button btn "Comparison"
local Lstate = false

on btn pressed do
(
Lstate = not Lstate
if Lstate then lbl.text = "Oranges" else lbl.text = "Apples"
)

)

createDialog test

Bobo
03-30-2008, 04:24 AM
I suppose it's obvious, but I just realized this method can also make labels dynamic...


Welcome to the wonderful world of... captions :)
Generally, all captions are dynamic, but there are some caveats in controls like Spinners where the caption is NEXT to the editable field - MAXScript seems to reserve a specific amount of space for the caption of the spinner and if the new caption is longer, it might get clipped a bit. If you intend to use longer captions in spinners, be sure to add some spaces in the initial string to pre-initialize the size correctly.

In contrast, in earlier version of Max, the tooltips were static and not dynamically changeable. This has been somewhat improved in Max 9 where the .tooltip property was introduced for buttons/pickbuttons/checkbuttons. In Max 2009, tooltips were added to some rather unsuspecting controls like dropdownlists and checkboxes. Not only that, but long tooltips will now be warped automatically into mutli-line tooltips, making them much easier to read and a lot cooler!

bhnh
03-30-2008, 11:38 AM
Thanks for filling out the picture, Bobo.:D This is a little gem of a feature, IMHO, that I couldn't find any reference to in the Reference.

Bobo
03-30-2008, 04:36 PM
Thanks for filling out the picture, Bobo.:D This is a little gem of a feature, IMHO, that I couldn't find any reference to in the Reference.

The logic is this:

Anything that is a Read/Write PROPERTY is dynamic and can be changed at any time after the UI control has been created. This includes all common properties like .caption, .pos, .enabled and .visible and the own properties like .checked in checkboxes or .items in a dropdownlist.

And then there are the CONSTRUCTION PARAMETERS which are often duplicated by the properties but not always. For example, the align:#left can only be specified as a construction parameter for MAXScript to figure out the alignment when initially building the rollout, but not as a property to change the alignment later. Some construction parameters like the .tooltip were exposed later as properties to make them dynamic based on userbase wishes...

The construction parameters are given in the Constructor syntax (the big blue box on top of the UI Control's page), they are also listed in detail below it. Then the properties are listed and finally the handlers. If a Construction Parameter does not appear on the Properties list, it is not dynamically changeable.

bhnh
03-30-2008, 04:40 PM
Got it. Many thanks! :thumbsup:

CGTalk Moderation
03-30-2008, 04:40 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.