wid_edit: only allow top row, don't "disable" widgets
parent
0be14efaec
commit
66120e31e4
|
|
@ -1,18 +1,15 @@
|
||||||
# Widget Editor
|
# Widget Editor
|
||||||
|
|
||||||
This adds a setting menu which allows you to change the location of all widgets.
|
This adds a setting menu which allows you to change the location of widgets.
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
There is no app icon in the launcher; you can find the settings under
|
There is no app icon in the launcher; you can find the settings under
|
||||||
`Settings`->`App/Widget Settings`->`Widget Editor`.
|
`Apps`->`Widget Editor`.
|
||||||
|
|
||||||
For every widget, you have these options:
|
For every widget, you have these options:
|
||||||
* **Area**: In which corner to draw the widget.
|
* **Side**: On which side to draw the widget.
|
||||||
* **Note**: Not all apps handle widgets in the bottom corners well.
|
* **Sort Order**: Changes the order if several widgets use the same side.
|
||||||
* **Sort Order**: Changes the order if several widgets use the same corner.
|
|
||||||
* **Enabled**: We do our best to hide disabled widgets, but they are still
|
|
||||||
loaded and use RAM.
|
|
||||||
|
|
||||||
## Creator
|
## Creator
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,39 +7,19 @@ Bangle.loadWidgets = function() {
|
||||||
});
|
});
|
||||||
const o = require("Storage").readJSON("wid_edit.json", 1) || {},
|
const o = require("Storage").readJSON("wid_edit.json", 1) || {},
|
||||||
c = o.custom || {};
|
c = o.custom || {};
|
||||||
let _W;
|
|
||||||
for (const w in c){
|
for (const w in c){
|
||||||
if (!(w in WIDGETS)) continue;
|
if (!(w in WIDGETS)) continue;
|
||||||
_W= {};
|
let _W = {};
|
||||||
if (c[w].hide) {
|
// store default area/sortorder in _WIDGETS
|
||||||
// disabled: move widget to _WIDGETS, and place it way offscreen (in case it tries to draw itself anyway)
|
if (c[w].area) _W.area = WIDGETS[w].area;
|
||||||
_W = WIDGETS[w]; _W.x = 1000; _W.y = 1000;
|
if ('sortorder' in c[w]) _W.sortorder = WIDGETS[w].sortorder;
|
||||||
WIDGETS[w] = {draw:()=>{}}; // in case it tries to call itself
|
Object.assign(WIDGETS[w], c[w]);
|
||||||
}
|
_WIDGETS[w] = _W;
|
||||||
else {
|
|
||||||
// enabled: store default area/sortorder in _WIDGETS (only if changed)
|
|
||||||
if (c[w].area) _W.area = WIDGETS[w].area;
|
|
||||||
if ('sortorder' in c[w]) _W.sortorder = WIDGETS[w].sortorder;
|
|
||||||
Object.assign(WIDGETS[w], c[w]);
|
|
||||||
}
|
|
||||||
if (Object.keys(_W).length) _WIDGETS[w] = _W;
|
|
||||||
}
|
}
|
||||||
if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no need for this
|
if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no need for this
|
||||||
const W = WIDGETS;
|
const W = WIDGETS;
|
||||||
WIDGETS = {};
|
WIDGETS = {};
|
||||||
let a, t=0, b=0;
|
|
||||||
Object.keys(W)
|
Object.keys(W)
|
||||||
.sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder))
|
.sort((a, b) => (0|W[b].sortorder)-(0|W[a].sortorder))
|
||||||
.forEach(k => {
|
.forEach(k => WIDGETS[k] = W[k]);
|
||||||
WIDGETS[k] = W[k];
|
|
||||||
if (a=W[k].area) {
|
|
||||||
t = t || (a[0]=="t");
|
|
||||||
b = b || (a[0]=="b");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Bangle.appRect = {
|
|
||||||
x: 0, y: t*24,
|
|
||||||
w: g.getWidth(), h: g.getHeight()-1-(t+b)*24,
|
|
||||||
x2: g.getWidth()-1, y2: g.getHeight()-1-b*24
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 8.1 KiB |
|
|
@ -6,10 +6,7 @@
|
||||||
const settings = require("Storage").readJSON("wid_edit.json", 1) || {};
|
const settings = require("Storage").readJSON("wid_edit.json", 1) || {};
|
||||||
if (!('custom' in settings)) settings.custom = {};
|
if (!('custom' in settings)) settings.custom = {};
|
||||||
global._WIDGETS = global._WIDGETS || {};
|
global._WIDGETS = global._WIDGETS || {};
|
||||||
// Adjust appRect to always have room for widgets while in this app
|
|
||||||
Object.assign(Bangle.appRect, {
|
|
||||||
y: 24, h: g.getHeight()-25, y2: g.getHeight()-48,
|
|
||||||
});
|
|
||||||
/**
|
/**
|
||||||
* Sort & redraw all widgets
|
* Sort & redraw all widgets
|
||||||
*/
|
*/
|
||||||
|
|
@ -41,23 +38,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit(id) {
|
function edit(id) {
|
||||||
// disabled widgets were moved to _WIDGETS and replaced with a dummy {draw}, so don't have area set
|
let WIDGET = WIDGETS[id],
|
||||||
let WIDGET = WIDGETS[id].area ? WIDGETS[id] : _WIDGETS[id],
|
def = {area: WIDGET.area, sortorder: WIDGET.sortorder|0}; // default values
|
||||||
def = {area: WIDGET.area, sortorder: WIDGET.sortorder|0}; // default values (disabled is never the default)
|
Object.assign(def, _WIDGETS[id]||{}); // defaults were saved in _WIDGETS
|
||||||
if (WIDGET.area && id in _WIDGETS) Object.assign(def, _WIDGETS[id]); // enabled widgets have defaults saved in _WIDGETS
|
|
||||||
|
|
||||||
const areas = ['tl','tr','bl','br'];
|
|
||||||
settings.custom = settings.custom||{};
|
settings.custom = settings.custom||{};
|
||||||
let saved = settings.custom[id] || {},
|
let saved = settings.custom[id] || {},
|
||||||
area = saved.area || def.area,
|
area = saved.area || def.area,
|
||||||
sortorder = ("sortorder" in saved) ? saved.sortorder : def.sortorder,
|
sortorder = ("sortorder" in saved) ? saved.sortorder : def.sortorder;
|
||||||
enabled = !saved.hide;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw highlighted widget (if enabled)
|
* Draw highlighted widget
|
||||||
*/
|
*/
|
||||||
function highlight() {
|
function highlight() {
|
||||||
if (WIDGET.width && enabled) {
|
if (WIDGET.width) {
|
||||||
WIDGET.draw();
|
WIDGET.draw();
|
||||||
g.setColor(g.theme.fgH)
|
g.setColor(g.theme.fgH)
|
||||||
.drawRect(WIDGET.x, WIDGET.y, WIDGET.x+WIDGET.width-1, WIDGET.y+23);
|
.drawRect(WIDGET.x, WIDGET.y, WIDGET.x+WIDGET.width-1, WIDGET.y+23);
|
||||||
|
|
@ -71,10 +65,9 @@
|
||||||
function save() {
|
function save() {
|
||||||
// we only save non-default values
|
// we only save non-default values
|
||||||
saved = {};
|
saved = {};
|
||||||
if ((area!==def.area) || (sortorder!==def.sortorder) || !enabled) {
|
if ((area!==def.area) || (sortorder!==def.sortorder)) {
|
||||||
if (area!==def.area) saved.area = area;
|
if (area!==def.area) saved.area = area;
|
||||||
if (sortorder!==def.sortorder) saved.sortorder = sortorder;
|
if (sortorder!==def.sortorder) saved.sortorder = sortorder;
|
||||||
if (!enabled) saved.hide = true;
|
|
||||||
settings.custom = settings.custom || {};
|
settings.custom = settings.custom || {};
|
||||||
settings.custom[id] = saved;
|
settings.custom[id] = saved;
|
||||||
} else if (settings.custom) {
|
} else if (settings.custom) {
|
||||||
|
|
@ -82,26 +75,16 @@
|
||||||
}
|
}
|
||||||
if (!Object.keys(settings.custom).length) delete settings.custom;
|
if (!Object.keys(settings.custom).length) delete settings.custom;
|
||||||
require("Storage").writeJSON("wid_edit.json", settings);
|
require("Storage").writeJSON("wid_edit.json", settings);
|
||||||
delete saved.hide; // no need to save this inside the widget
|
|
||||||
Object.assign(WIDGET, def, saved);
|
Object.assign(WIDGET, def, saved);
|
||||||
if (WIDGET.sortorder === undefined) delete WIDGET.sortorder; // default can be undefined, but don't put that in the widget
|
if (WIDGET.sortorder === undefined) delete WIDGET.sortorder; // default can be undefined, but don't put that in the widget
|
||||||
if (enabled) {
|
// if we assigned custom values, store defaults in _WIDGETS
|
||||||
WIDGETS[id] = WIDGET;
|
let _W = {};
|
||||||
delete _WIDGETS[id];
|
if (saved.area) _W.area = def.area;
|
||||||
// if we assigned custom values, store defaults in _WIDGETS
|
if ('sortorder' in saved) _W.sortorder = def.sortorder;
|
||||||
let _W = {};
|
if (Object.keys(_W).length) _WIDGETS[id] = _W;
|
||||||
if (saved.area) _W.area = def.area;
|
else delete _WIDGETS[id];
|
||||||
if (def.sortorder !== undefined) {
|
|
||||||
if ('sortorder' in saved) _W.sortorder = def.sortorder;
|
|
||||||
}
|
|
||||||
if (Object.keys(_W).length) _WIDGETS[id] = _W;
|
|
||||||
} else {
|
|
||||||
// disabled: move original widget into _WIDGETS, and place it offscreen
|
|
||||||
_WIDGETS[id] = WIDGET;
|
|
||||||
WIDGETS[id] = {draw: () => {}}; // in case it tries to call itself
|
|
||||||
}
|
|
||||||
// drawWidgets won't clear e.g. bottom bar if we just disabled the last bottom widget
|
// drawWidgets won't clear e.g. bottom bar if we just disabled the last bottom widget
|
||||||
if (WIDGET.width) g.reset().clearRect(WIDGET.x, WIDGET.y, WIDGET.x+WIDGET.width-1, WIDGET.y+23);
|
|
||||||
redrawWidgets();
|
redrawWidgets();
|
||||||
|
|
||||||
highlight();
|
highlight();
|
||||||
|
|
@ -117,15 +100,11 @@
|
||||||
}
|
}
|
||||||
mainMenu();
|
mainMenu();
|
||||||
},
|
},
|
||||||
/*LANG*/"Area": {
|
/*LANG*/"Side": {
|
||||||
value: areas.indexOf(area),
|
value: (area === 'tl'),
|
||||||
min: 0, max: 3, wrap: true,
|
format: tl => tl ? /*LANG*/"Left" : /*LANG*/"Right",
|
||||||
format: a => [
|
onchange: tl => {
|
||||||
/*LANG*/"Top Left", /*LANG*/"Top Right",
|
area = tl ? "tl" : "tr";
|
||||||
/*LANG*/"Bottom Left", /*LANG*/"Bottom Right"
|
|
||||||
][a],
|
|
||||||
onchange: a => {
|
|
||||||
area = areas[a];
|
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -136,18 +115,9 @@
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/*LANG*/"Enabled": {
|
|
||||||
value: enabled,
|
|
||||||
format: e => e ?/*LANG*/"Yes" :/*LANG*/"No",
|
|
||||||
onchange: e => {
|
|
||||||
enabled = e;
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/*LANG*/"Reset": () => {
|
/*LANG*/"Reset": () => {
|
||||||
area = def.area;
|
area = def.area;
|
||||||
sortorder = def.sortorder;
|
sortorder = def.sortorder;
|
||||||
enabled = true;
|
|
||||||
save();
|
save();
|
||||||
mainMenu(); // changing multiple values made the rest of the menu wrong, so take the easy out
|
mainMenu(); // changing multiple values made the rest of the menu wrong, so take the easy out
|
||||||
}
|
}
|
||||||
|
|
@ -162,33 +132,13 @@
|
||||||
"": {"title": /*LANG*/"Widgets"},
|
"": {"title": /*LANG*/"Widgets"},
|
||||||
};
|
};
|
||||||
menu[/*LANG*/"< Back"] = ()=>{
|
menu[/*LANG*/"< Back"] = ()=>{
|
||||||
if (!Object.keys(_WIDGETS).length) delete _WIDGETS;
|
if (!Object.keys(_WIDGETS).length) delete _WIDGETS; // no defaults to remember
|
||||||
// adjust appRect for new widget locations
|
|
||||||
let a, t=0, b=0;
|
|
||||||
for (let WIDGET of WIDGETS) {
|
|
||||||
if (a=WIDGET.area) {
|
|
||||||
t = t || (a[0]=="t");
|
|
||||||
b = b || (a[0]=="b");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object.assign(Bangle.appRect, {
|
|
||||||
y: t*24,
|
|
||||||
h: g.getHeight()-(t+b)*24,
|
|
||||||
y2: g.getHeight()-1-b*24
|
|
||||||
});
|
|
||||||
back();
|
back();
|
||||||
};
|
};
|
||||||
const enabled = Object.keys(WIDGETS).filter(id => WIDGETS[id].area);
|
Object.keys(WIDGETS).forEach(id=>{
|
||||||
enabled.forEach(function(id) {
|
// mark customized widgets with asterisk
|
||||||
menu[name(id)+((id in _WIDGETS) ? " *" : "")] = () => edit(id);
|
menu[name(id)+((id in _WIDGETS) ? " *" : "")] = () => edit(id);
|
||||||
});
|
});
|
||||||
const disabled = Object.keys(WIDGETS).filter(id => !WIDGETS[id].area);
|
|
||||||
if (disabled.length) {
|
|
||||||
menu[" == "+/*LANG*/"Disabled"+" == "] = undefined;
|
|
||||||
disabled.forEach(function(id) {
|
|
||||||
menu[name(id)+" *"] = () => edit(id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (Object.keys(_WIDGETS).length) { // only show reset if there is anything to reset
|
if (Object.keys(_WIDGETS).length) { // only show reset if there is anything to reset
|
||||||
menu[/*LANG*/"Reset All"] = () => {
|
menu[/*LANG*/"Reset All"] = () => {
|
||||||
E.showPrompt(/*LANG*/"Reset all widgets?").then(confirm => {
|
E.showPrompt(/*LANG*/"Reset all widgets?").then(confirm => {
|
||||||
|
|
@ -196,15 +146,9 @@
|
||||||
delete settings.custom;
|
delete settings.custom;
|
||||||
require("Storage").writeJSON("wid_edit.json", settings);
|
require("Storage").writeJSON("wid_edit.json", settings);
|
||||||
for(let id in _WIDGETS) {
|
for(let id in _WIDGETS) {
|
||||||
if (WIDGETS[id].area) Object.assign(WIDGETS[id], _WIDGETS[id]) // restore defaults
|
Object.assign(WIDGETS[id], _WIDGETS[id]) // restore defaults
|
||||||
else WIDGETS[id] = _WIDGETS[id]; // restore widget
|
|
||||||
}
|
}
|
||||||
global._WIDGETS = {};
|
global._WIDGETS = {};
|
||||||
for(let WIDGET of WIDGETS) {
|
|
||||||
// drawWidgets won't clear e.g. bottom bar if there are no bottom widgets because we just moved them away
|
|
||||||
// (area has been reset by now, but x/y not yet)
|
|
||||||
if (WIDGET.width) g.reset().clearRect(WIDGET.x, WIDGET.y, WIDGET.x+WIDGET.width-1, WIDGET.y+23);
|
|
||||||
}
|
|
||||||
redrawWidgets();
|
redrawWidgets();
|
||||||
}
|
}
|
||||||
mainMenu(); // reload with reset widgets
|
mainMenu(); // reload with reset widgets
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue