Which widget gets tl or tr first ?

Posted on
  • I am wondering what controls the order in which widgets that occupy the same area are loaded / displayed. I like the lock widget to display in the extreme top left hand corner.

    Try as I might I cant get this to happen. I have tried deleting all widgets and installing them in different orders but the lock widget is displaying to the right of the 'Lato Pedometer' widget.

    The 2 widgets in the screenshot are

    • Lato Pedometer - widpb
    • Lock Widget - widlock

    Short of a factory reset is there something else I can try ?


    1 Attachment

    • download.png
  • It seems to be the sortorder attribute of the widget: https://github.com/espruino/Espruino/commit/8ae6fe20d99f158cac2afef5a6841048f349dafd

    But I don't know where that comes from because I can't see it on any widget in the BangleApps repository.

  • Maybe it's species in apps.json.

  • I wondered. It is specified for some entries there, but didn't see it for the widgets you screenshot so I don't know what the fallback is in that case.

    But I also thought that might serve another purpose. Was just guessing though.

  • If there's no sortorder specified (which I implemented I believe but isn't used) the order is just the order the files happened to be listed in storage - so if you need to specify something best to just stick a sortorder in apps.json and I think that should work its way into the app info file.

  • if you need to specify something best to just stick a sortorder in apps.json

    I think you want to put it in the widget code instead: the apps.json affects the order in the App Loader page, but loadWidgets() looks at the widget.

    So something like

    WIDGETS["lock"]={area:"tl",sortorder:-1,width:Bangle.isLocked()?16:0,...
    
  • I've done it through apps.json as that makes it more visible and standard. PR issued.

  • Did that actually work? Because as far as I can tell, loadWidgets doesn't look at the .info file, just at the sortorder defined inside the widget code.

    (Also, editing the code to change widget order seems suboptimal, so I made a widget editor)

  • as far as I can tell, loadWidgets doesn't look at the .info file, just at the sortorder defined inside the widget code.

    That's a good point! I may well have been wrong :)

  • Did that actually work?

    No it didn't work. but it was not immediately obvious as it is hard to test. Lots of installing and uninstalling etc.

    so I made a widget editor

    Just tried it out. Good job.

    editing the code to change widget order seems suboptimal

    I would agree with the exception that certain widgets (eg lock widget) should have good defaults to start with.

  • Apologies for revisiting, this. I just noticed that when I installed the gps widget that it got first place in the tr corner and usurpped the battery theme widget.

    for the lato pedometer widget I have, and this ensure its always the tl most widget.

    WIDGETS["widpb"]={area:"tl",sortorder:-1,width:13,draw:function()
    

    for the batthery themed widget I have:

    WIDGETS["bata"]={area:"tr",sortorder:-10,width:27,draw:function() 
    

    this doe not seem to work and force the battery widget to always be in the top righmost corner.

    What value of sortorder should I use ?

  • The actual code for loading widgets is:

    (function() {
      global.WIDGETS={};
      require("Storage").list(/\.wid\.js$/).forEach(widget=>{try { eval(require("Storage").read(widget)); } catch (e) {print(widget,e);}}); 
      var W = WIDGETS;
      WIDGETS = {};
      Object.keys(W).sort((a,b)=>(0|W[b].sortorder)-(0|W[a].sortorder)).forEach(k=>WIDGETS[k]=W[k]);
    })
    

    So it should work just to have what you're doing... You could check the WIDGETS object and make sure everything is in the order you want and has sortorder set right?

  • Should I be putting positive values for sortorder if I want the battery widget to always be displayed on the extreme rhs?

  • No... I think negative makes it go near the start of the element - so leftmost for tl and rightmost for tr but as I mention above it's best to test

  • I forced a sort order of "10" throught Widget Editor to keep the battery widget top-right.

  • @HughB could it be that you have the Widget Editor installed so it's overwriting the positions you are setting?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Which widget gets tl or tr first ?

Posted by Avatar for HughB @HughB

Actions