dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Pebble.JS: Selecting from a menu object created in a function

  1. #1
    Join Date
    Oct 2015
    Posts
    2

    Pebble.JS: Selecting from a menu object created in a function

    This is mostly a pebble.js question, but If you're not familiar with that you might be able to help anyway.

    So, my problem is that I cannot use/access a (menu)object created in a function.

    In the function createMyMenu() , a menu object is created and displayed. That works fine and the user can move up/down in the menu using the buttons on the pebble smartwatch.

    In my main script, I call the function createMyMenu() and so the menu is sown and used as described above.

    I would like the user to be able to select an item in that menu, but that does not work. The menu is created and the user can navigate in it, but the select event handler does not work.

    I have tried to return the menu object from the function and I have also tried to make that menu object global (bad thing, I know) but without success. The user can (of course) see and browse the menu, but not select any item.

    The code:

    function createMyMenu()
    {
    // Some code to create the menu object myMenu. Works fine
    myMenu.show(); // Also works fine, the menu ant it contents are displayed.
    return myMenu; // No errors
    }
    And the script

    mainMenu = createMyMenu();
    mainMenu.on('select', function(e) // Nothing happens here. This event is never trigged.
    {
    // Code to execute when the user selects a menu item.
    }

    Any suggestions would be highly appreciated.

  2. #2
    Join Date
    Dec 2012
    Posts
    801
    Read about your event here:
    http://www.javascriptkit.com/jsref/events.shtml
    Obviously the event onselect is available for textarea and input only.

  3. #3
    Join Date
    Dec 2012
    Posts
    801
    PS: When answering I assumed that Pebble.js is a javascript framework. Having a look at the website it seems to me that it is not but a software providing a javascript API. Nevertheless check whether the select event is available for your menu object.

  4. #4
    Join Date
    Oct 2015
    Posts
    2
    Thanks for your reply.

    If this was a web page, the function function createMyMenu() would have altered the DOM, but in this case there is no DOM. Therefore, I need an other way to access the menu object.

  5. #5
    Join Date
    Sep 2015
    Posts
    95
    The "select" is being triggered with this code:

    Code:
    var UI = require('ui');
    var Vector2 = require('vector2');
    
    var main = new UI.Card({
      title: 'Pebblexxx.js',
      icon: 'images/menu_icon.png',
      subtitle: 'Hello Worldxxx!',
      body: 'Press any buttonxxx.'
    });
    
    main.show();
    
    function CreateMyMenu()
    {
      var menu = new UI.Menu({
        sections: [{
          items: [{
            title: 'Pebble.js',
            icon: 'images/menu_icon.png',
            subtitle: 'Can do Menus'
          }, {
            title: 'Second Item',
            subtitle: 'Subtitle Text'
          }]
        }]
      });
     menu.show();
      return menu;
    }
    
    main.on('click', 'up', function(e) {
      var myMenu = CreateMyMenu();
      myMenu.on('select', function(e) {
     var wind = new UI.Window({
        fullscreen: true,
      });
    
      var textfield = new UI.Text({
        position: new Vector2(0, 65),
        size: new Vector2(144, 30),
        font: 'gothic-24-bold',
        text: 'Text Anywhere!',
        textAlign: 'center'
      });
      wind.add(textfield);
      wind.show();
      });
     
    });

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles