Hooray
I have a working solution - it turned out to be quite simple.
In fgdata/Nasal/canvas/gui/Buttons.nas, some code added to setDown. Note that at present it only works if the button is not checkable.
- Code: Select all
setDown: func(down = 1)
{
if( me._checkable or me._down == down )
return me;
me._down = down;
me._onStateChange();
if (!me._down){
me._trigger("mouse_up", {checked: 0});
print ("mouse up");
}
else{
me._trigger("mouse_down", {checked: 0});
print ("mouse down");
}
return me;
},
It is called from my canvas gui
- Code: Select all
me.Enter_button = canvas.gui.widgets.Button.new(root, canvas.style, {})
.setText("ENTER")
.setFixedSize(100, 30)
.listen("mouse_down",func {Enter_key_press()})
.listen("mouse_up",func {Enter_key_release()});
buttons1.addItem(me.Enter_button);
var Enter_key_press = func {
print("Enter key press");
setprop("systems/navigation/switches/Enter_key",1);
}
var Enter_key_release = func {
print("Enter key release");
setprop("systems/navigation/switches/Enter_key",0);
}
For many purposes setting a property on mouse down is preferable to waiting for a complete mouse click cycle (click = down followed by release).
I will submit this to the devel list after some more testing, and deciding what is best to do if the button is checkable. If you have any observations please let me know.
Alan