using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
using Toybox.Graphics as Gfx;
using Toybox.Application as App;
class WidgetMenuApp extends App.AppBase {
function initialize() {
AppBase.initialize();
}
function getInitialView() {
return [ new WidgetMenuView(), new MainViewInputDelegate() ];
}
}
class WidgetMenuView extends Ui.View {
function onUpdate(dc) {
dc.setColor( Gfx.COLOR_BLACK, Gfx.COLOR_BLACK );
dc.clear();
dc.setColor( Gfx.COLOR_DK_BLUE, Gfx.COLOR_TRANSPARENT );
dc.drawText( dc.getWidth() / 2, dc.getHeight() / 2, Gfx.FONT_LARGE, "Main screen", Gfx.TEXT_JUSTIFY_CENTER );
}
}
class MainViewInputDelegate extends Ui.InputDelegate
{
function onKey(key) {
Sys.println("key pressed :" +key.getKey() );
if(key.getKey() == Ui.KEY_ENTER || key.getKey() == Ui.KEY_MENU) {
var menuView = new CustomMenuView();
Ui.switchToView( menuView, new CustomMenuViewInputDelegate(), Ui.SLIDE_IMMEDIATE );
}
}
}
class CustomMenuView extends Ui.View {
function onUpdate(dc) {
dc.setColor( Gfx.COLOR_BLACK, Gfx.COLOR_BLACK );
dc.clear();
dc.setColor( Gfx.COLOR_DK_BLUE, Gfx.COLOR_TRANSPARENT );
dc.drawText( dc.getWidth() / 2, dc.getHeight() / 2, Gfx.FONT_LARGE, "Menu text", Gfx.TEXT_JUSTIFY_CENTER );
}
}
class CustomMenuViewInputDelegate extends Ui.InputDelegate
{
function onKey(key) {
Sys.println("key pressed :" +key.getKey() );
if(key.getKey() == Ui.KEY_ENTER || key.getKey() == Ui.KEY_MENU) {
Sys.println("Pressed enter or menu");
}
if(key.getKey() == Ui.KEY_UP ) {
Sys.println("Pressed up");
}
if(key.getKey() == Ui.KEY_DOWN ) {
Sys.println("Pressed down");
}
return true;
}
}