• Actually, the Button implementation has 3 callbacks -- onPress, onHold, and onRelease. What you're seeing on the action of the buttons is simply because I implemented the action in the onPress callback for those two buttons.

    However, you point out unimplemented functionality that I just went and implemented -- a check to see if the touch was still in the button area on release in order to call the onRelease callback... I agree that onRelease shouldn't be called if the finger isn't on the button anymore when lifted from the screen.

    I'm leaving onHold alone -- i.e. once the press is detected, the "focus" remains on that control even if the finger leaves the area of the control, and continues to affect it through the onHold callback. This allows seeing where the slider is more easily while moving it if you can still move it back and forth while your finger is above or below the actual control, after it's been "activated" with a press.

    Here's how easy it is to set up one of these buttons, if the GUI is available (this is the 3D purplish one):

    new Button({
    	area: [163,5,100,50],
    	text: 'LED2 on',
    	color: new Uint8Array([1, 0, 128, 153]),
    	onPress: function() {
    		LED2.write(!LED2.read());
    		this.text = LED2.read() ? "LED2 off" : "LED2 on";
    	},
    });
    
About

Avatar for dwallersv @dwallersv started