A very useful feature of label and shape widgets is that you can change their transparency by changing their value. However, if you change the hide state of such a widget to false (meaning, make it visible), then it will show at full opacity regardless of its value. I’m not sure whether this is a feature or a bug, but I know that it’s not the behaviour I’m seeking, and I’m having trouble finding a workaround.
The obvious thing to do would be to make the widget visible first and then set its value immediately afterward. Here is an example script that demonstrates this situation:
var label, button : Widget On WidgetValueChanged (w : Widget, index : Integer, newValue : Double) from button If newValue == 0.0 Then SetWidgetHideOnPresentation(label, true) Else SetWidgetHideOnPresentation(label, false) SetWidgetValue(label, 0.5) // this line doesn't succeed in setting the transparency End End
Unfortunately, it seems that the call to “SetWidgetHideOnPresentation(label, false)” seems to delay completing its task until some time after it returns. (I suppose this means its doing its work in a different thread.) Then even though I set the value of the widget to 0.5, it shows at full brightness due to being unhidden. You can see verify in the value pane of the widget editor that its value is truly 50%, even though it’s showing on the screen at full opacity. If you edit the value, even without changing it, then the transparency suddenly changes to match.
Here is a workaround that has the desired outcome:
var label, button : Widget On WidgetValueChanged (w : Widget, index : Integer, newValue : Double) from button If newValue == 0.0 Then SetWidgetHideOnPresentation(label, true) Else SetWidgetHideOnPresentation(label, false) While GetWidgetHideState(label) Do // wait until it's unhidden End SetWidgetValue(label, 0.5) // now this line successfully makes the widget semitransparent End End
This seems to work fine, but I am aware that this sort of loop (hanging this thread while I wait for the other thread to catch up) is considered poor practice.
So I guess I have two questions;
A feature request: would it be possible to change the behaviour of SetWidgetHideOnPresentation so as to respect the transparency implied by the widget value? Or is there some reason why this would be undesirable?
Failing that, what’s the correct way to achieve what I’m seeking without hanging my thread as I’ve done here?