HI,
For EDGE devices with touch screen....
We are developing a data field and we would like to add a button on screen to show certain info via pop up. Is it possible?
Thanks in advance,
HI,
For EDGE devices with touch screen....
We are developing a data field and we would like to add a button on screen to show certain info via pop up. Is it possible?
Thanks in advance,
Set up a delegate with onTap(), draw the button, and in onTap check to make sure the tap is within the bounds of the button.
Thanks Jim,
Do you know where we can find an example? Thanks in advance,
It's really pretty simple. He's some code from one of my test apps to draw a button:
dc.setColor(Gfx.COLOR_WHITE,Gfx.COLOR_WHITE); dc.drawRectangle(butX, butY, butW, butH); dc.setColor(Gfx.COLOR_WHITE,Gfx.COLOR_TRANSPARENT); dc.drawText(butX+butW/2,butY+butH/2,xtF,"button",Gfx.TEXT_JUSTIFY_CENTER|Gfx.TEXT_JUSTIFY_VCENTER);
Then in the input delegate:
function onTap(evt) { var coord=evt.getCoordinates(); tapX=coord[0]; tapY=coord[1]; tapGood=false; if(tapX>=butX && tapX<=butX+butW && tapY>=butY && tapY<=butY+butH) { tapGood=true; } Ui.requestUpdate(); return true; }
tapGood=true says you got a tap within the bounds of your button
Hi Jim If I wish to do a simple tap command for whole screen to change a property, is this ok??
function onTap(evt) { Model = getProperty("Model"); if(Model == 2) { Model = 1; } Ui.requestUpdate(); return true; }
It depends on how/where "Model" is defined. Is it something you can access in the view's onUpdate()? do you get an error for getProperty? Do you mean Application.getApp().getProperty()?
no, it works fine with this string, but I want to change from Model 1 to 2 on tap and viceversa. with a tap o whole screen, I do not need an specific button.
function getProperty(key){ if(Application has :Storage) {return Application.Properties.getValue(key); } else { return Application.getApp().getProperty(key); } }
o don't get an error but it does not work it just works changing from settings
or this is the way??
function onTap(evt) { if(evt == false) { Model = 1; }else{ if(evt == true) { Model = 2; } } Ui.requestUpdate(); }
evt isn't a boolean. It's a click event
using Toybox.System; using Toybox.WatchUi; class InputDelegate extends WatchUi.BehaviorDelegate { function onTap(clickEvent) { System.println(clickEvent.getCoordinates()); // e.g. [36, 40] System.println(clickEvent.getType()); // CLICK_TYPE_TAP = 0 return true; } }
You can find out where the screen was tapped if you want.
thanks I really does care about the position
I just want to use on tap as a boolean
can I do that with this?
var evt = false; function onTap(evt) { evt = true; Ui.requestUpdate(); return true; }
That really does nothing
function onTap(evt) { val=!val; return true; }
This toggles "val" each time the screen is tapped. How you define and use "val" is up to you.
You probably want to spend some time with the input sample in the SDK.