I'm playing with Canvas GUI, and I'm missing 2 features about the canvas checkbox:
first case:
Create a canvas window and insert a checkbox, with "setCheckable()" to false. I want that this checkbox become checkable as soon as another checkbox is checked.
Unfortunately it's not possible because "setCheckable()" doesn't listen to my other checkbox.
second case:
Again, a canvas window with a checkbox and "setChecked()" to false. I want that this checkbox become checked without user action (the user don't click on the checkbox, instead he press a button on his joystick).
Unfortunately it's not possible because "setChecked()" doesn't listen to a property.
In order to fit my need I implemented this:
- Code: Select all
diff --git a/Nasal/canvas/gui/widgets/Button.nas b/Nasal/canvas/gui/widgets/Button.nas
index e185323..3e594b4 100644
--- a/Nasal/canvas/gui/widgets/Button.nas
+++ b/Nasal/canvas/gui/widgets/Button.nas
@@ -24,6 +24,13 @@ gui.widgets.Button = {
me._checkable = checkable;
return me;
},
+ setCheckableProp: func(prop)
+ {
+ setlistener(prop, func(v){
+ me._checkable = v.getBoolValue();
+ });
+ return me;
+ },
setChecked: func(checked = 1)
{
if( !me._checkable or me._down == checked )
@@ -36,6 +43,14 @@ gui.widgets.Button = {
me._onStateChange();
return me;
},
+ setCheckedProp: func(prop)
+ {
+ setlistener(prop, func(v){
+ me._down = v.getBoolValue();
+ me._onStateChange();
+ });
+ return me;
+ },
setDown: func(down = 1)
{
if( me._checkable or me._down == down )
With this change I have everything working as I want.
Does it look ok ? can I commit it ?
Regards,
Clément