add pop up log window

This commit is contained in:
Stewart Allen 2022-01-07 14:39:32 -05:00
commit 56454d7d24
6 changed files with 109 additions and 12 deletions

View file

@ -169,7 +169,7 @@ let selection = {
},
focus() {
api.focus(selected);
api.focus(selection.list());
},
bounds() {
@ -228,7 +228,7 @@ let tool = {
},
repair() {
api.modal.spin(true, 250);
api.log.emit('repairing mesh(es)...').pin();
for (let m of selection.models()) {
moto.client.fn.model_heal(m.id).then(data => {
if (data) {
@ -238,7 +238,7 @@ let tool = {
data.normals
);
}
api.modal.spin(false);
api.log.emit('repair complete').unpin();
});
}
}

View file

@ -69,6 +69,59 @@ let modal = mesh.api.modal = {
}
};
// transient logging window bottom/left
let log = mesh.api.log = {
age: 10000, // age out lines more than 10 seconds old
data: [], // last n messages
wait: 3000, // time before windows closes
lines: 20, // max log lines before forced-age out
emit(msg) {
let { age, data, lines, render } = log;
let now = Date.now();
data.push({
text: `${dbug.since()} | ${msg}`,
time: now
});
while (data.length && (data.length > lines || now - data[0].time > age)) {
data.shift();
}
return render();
},
hide() {
$('logger').style.display = 'none';
return log;
},
pin() {
return log.show(1 << 30);
},
unpin() {
return log.show();
},
// show log window for `time` milliseconds or default
show(time) {
clearTimeout(log.timer);
log.timer = setTimeout(log.hide, time || log.wait);
return log;
},
// re-render and show current log messages
render() {
let area = $('logtext');
h.bind(area, log.data.map(rec => h.div({ _: rec.text })));
area.scrollTop = area.scrollHeight;
$('logger').style.display = 'flex';
return log.show();
},
};
// create html elements
function ui_build() {
// set app version
@ -97,11 +150,15 @@ function ui_build() {
h.div({ id: 'actions' }),
h.div({ id: 'grouplist'}),
h.div({ id: 'selectlist'}),
h.div({ id: 'logger', onmouseover() { log.show() } })
]);
let { actions, grouplist, selectlist } = bound;
let { actions, grouplist, selectlist, logger } = bound;
let { api, util } = mesh;
// create slid in/out logging window
h.bind(logger, [ h.div({ id: 'logtext' }) ]);
// create hotkey/action menu (top/left)
h.bind(actions, [
h.div([

View file

@ -84,7 +84,7 @@ mesh.model = class MeshModel extends mesh.object {
// for debugging matrix ops
return mesh.api.group.new([new mesh.model({
file: `synth-${this.name}`,
mesh: data[0]
mesh: data
})]);
});
}