Is it possible to use "dynamic" strings in menus and other layouts?

hi,

(Apologies if it's a basic question...)
When defining a menu layout such as:

<menu id="MainMenu">
<menu-item id="item_1">My Menu Text</menu-item>
</menu>

Can "My Menu Text" change in runtime based on the app's or user's settings? e.g., have a test such as "Vibrate - On" or "Vibrate - Off" depending on the user's previous selection? Or do I have to write my own menu implementation if I want dynamic strings?
Same for <label...> in a layout - can its text be something dynamic or must it be fixed to some static string?

Thanks!
  • Yes, you can build your own menu. He's an example:
    var myMenu=new Menu();
    myMenu.setTitle("Change Station");
    myMenu.addItem("Get Current Location",:item_GPS);
    myMenu.addItem("Home: "+HOMEstation,:item_HOME);
    myMenu.addItem("Save Current as Home",:item_SAVE);
    Ui.pushView(myMenu, new MyMenuDelegate(), Ui.SLIDE_UP);
  • Great, thanks!
    What about making getting a label's text at runtime, is it possible to "bind" it to some variable? Or can it be only a static text and for dynamic fields I should draw by myself?

    btw Menu renders pretty bad on the emulator, it doesn't show any borders between the items, just "floating" text. Is this a known issue? Will it look normal on the actual device?
  • I'm not a big layout user, so maybe someone else can help you there.

    The Menu in the sim is VERY generic and looks little like the real devices. It uses the native menu system on the device so it also varies based on the device.
  • What about making getting a label's text at runtime, is it possible to "bind" it to some variable?

    If you use the built-in Ui.Menu class, you do not have access to the labels, so you can't change them and there is no way to bind a label to a variable so changes to that variable are reflected in the menu.

    Or can it be only a static text and for dynamic fields I should draw by myself?

    I'm afraid I don't understand your question. With the built-in Ui.Menu class, you can't change the labels after the menu has been initialized. If you implement your own menu system, you can do pretty much whatever you want.

    Menu renders pretty bad on the emulator, it doesn't show any borders between the items, just "floating" text. Is this a known issue? Will it look normal on the actual device?

    Yes, they know about it. The native views (Ui.Confirmation, Ui.Menu and Ui.ProgressBar) don't look exactly like they do on devices. I don't believe that they intend to make it look exactly like it does on the device. There isn't really any benefit to making it look exactly the same. Since these views are defined inside the device firmware, and are device specific, that would add a bit of maintenance that doesn't really seem to be necessary. At least that is my thinking.

    Travis
  • Thank you both for the helpful answers.
  • ... Sorry, one more question - The code above to create a menu in runtime works fine when running from another view. However, I would like the menu to be my initial view, and if I run it from the AppBase class like this:

    class MyApp extends App.AppBase {
    ...
    function getInitialView() {
    var menu = new Ui.Menu();
    menu.setTitle("Change Station");
    menu.addItem("Get Current Location",:item_1);
    menu.addItem("Home: ",:item_2);
    return [menu, new MainMenuDelegate()];
    }
    ...

    App closes immediately. There's no error in the console.
    Can the menu serve as the initial view, or should I open another "host" view and then immediately open the menu from there, say from onShow? That would mess up a bit the views stack...

    Thanks again.
  • Can the menu serve as the initial view, or should I open another "host" view and then immediately open the menu from there, say from onShow?

    You can only use Ui.pushView() and Ui.popView() with the native views (Ui.Confirmation, Ui.Menu and Ui.ProgressBar). They cannot be the initial view, and they cannot be used with switchToView(). I believe that you can push a menu from onShow() as you've proposed, or you could use a timer.

    Travis