separate init bindings

This commit is contained in:
Stewart Allen 2025-12-25 12:27:13 -05:00
commit b79c8da8e2
9 changed files with 288 additions and 241 deletions

133
src/kiri/app/init/bind.js Normal file
View file

@ -0,0 +1,133 @@
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
import { $ } from '../../../moto/webui.js';
import { api } from '../api.js';
export function bind() {
return {
alert: {
dialog: $('alert-area'),
text: $('alert-text')
},
func: {
slice: $('act-slice'),
preview: $('act-preview'),
animate: $('act-animate'),
export: $('act-export')
},
label: {
slice: $('label-slice'),
preview: $('label-preview'),
animate: $('label-animate'),
export: $('label-export'),
},
acct: {
help: $('app-help'),
don8: $('app-don8'),
mesh: $('app-mesh'),
export: $('app-export')
},
dev: {
header: $('dev-header'),
search: $('dev-search'),
filter: $('dev-filter')
},
mesh: {
name: $('mesh-name'),
points: $('mesh-points'),
faces: $('mesh-faces'),
},
stats: {
fps: $('fps'),
rms: $('rms'),
div: $('stats'),
rnfo: $('rnfo'),
},
load: $('load-file'),
speeds: $('speeds'),
speedbar: $('speedbar'),
context: $('context-menu'),
// ltsetup: $('lt-setup'),
// ltfile: $('lt-file'),
// ltview: $('lt-view'),
// ltact: $('lt-start'),
// edit: $('lt-tools'),
nozzle: $('menu-nozzle'),
modal: $('modal'),
modalBox: $('modal-box'),
modals: {
help: $('mod-help'),
setup: $('mod-setup'),
prefs: $('mod-prefs'),
files: $('mod-files'),
saves: $('mod-saves'),
tools: $('mod-tools'),
xany: $('mod-x-any'),
xsla: $('mod-x-sla'),
xlaser: $('mod-x-laser'),
don8: $('mod-don8'),
any: $('mod-any'),
},
catalog: {
body: $('catalogBody'),
list: $('catalogList'),
},
devices: {
div: $('devices'),
add: $('device-add'),
delete: $('device-del'),
export: $('device-exp'),
rename: $('device-ren'),
save: $('device-save'),
},
setMenu: $('set-menu'),
settings: $('settings'),
settingsBody: $('settingsBody'),
settingsList: $('settingsList'),
slider: {
div: $('slider'),
hi: $('slider-hi'),
hold: $('slider-hold'),
lo: $('slider-lo'),
max: $('slider-max'),
mid: $('slider-mid'),
min: $('slider-zero'),
range: $('slider-center'),
},
loading: $('progress').style,
progress: $('progbar').style,
prostatus: $('progtxt'),
selection: $('selection'),
size: {
X: $('size_x'),
Y: $('size_y'),
Z: $('size_z'),
},
scale: {
X: $('scale_x'),
Y: $('scale_y'),
Z: $('scale_z'),
},
lock: {
X: $('lock_x'),
Y: $('lock_y'),
Z: $('lock_z'),
},
stock: $('stock'),
stockWidth: $('stock-width'),
stockDepth: $('stock-width'),
stockHeight: $('stock-width'),
};
}

View file

@ -2,6 +2,7 @@
import { $ } from '../../../moto/webui.js';
import { api } from '../api.js';
import { bind } from './bind.js';
import { version } from '../../../moto/license.js';
import { fileOps } from '../file-ops.js';
import { init as initCAM } from '../../mode/cam/init-ui.js';
@ -207,118 +208,8 @@ function init_one() {
tracker: tracker,
container: container,
alert: {
dialog: $('alert-area'),
text: $('alert-text')
},
func: {
slice: $('act-slice'),
preview: $('act-preview'),
animate: $('act-animate'),
export: $('act-export')
},
label: {
slice: $('label-slice'),
preview: $('label-preview'),
animate: $('label-animate'),
export: $('label-export'),
},
acct: {
help: $('app-help'),
don8: $('app-don8'),
mesh: $('app-mesh'),
export: $('app-export')
},
dev: {
header: $('dev-header'),
search: $('dev-search'),
filter: $('dev-filter')
},
mesh: {
name: $('mesh-name'),
points: $('mesh-points'),
faces: $('mesh-faces'),
},
stats: {
fps: $('fps'),
rms: $('rms'),
div: $('stats'),
rnfo: $('rnfo'),
},
load: $('load-file'),
speeds: $('speeds'),
speedbar: $('speedbar'),
context: $('context-menu'),
ltsetup: $('lt-setup'),
ltfile: $('lt-file'),
ltview: $('lt-view'),
ltact: $('lt-start'),
edit: $('lt-tools'),
nozzle: $('menu-nozzle'),
modal: $('modal'),
modalBox: $('modal-box'),
modals: {
help: $('mod-help'),
setup: $('mod-setup'),
prefs: $('mod-prefs'),
files: $('mod-files'),
saves: $('mod-saves'),
tools: $('mod-tools'),
xany: $('mod-x-any'),
xsla: $('mod-x-sla'),
xlaser: $('mod-x-laser'),
don8: $('mod-don8'),
any: $('mod-any'),
},
catalog: {
body: $('catalogBody'),
list: $('catalogList'),
},
devices: $('devices'),
deviceAdd: $('device-add'),
deviceDelete: $('device-del'),
deviceRename: $('device-ren'),
deviceExport: $('device-exp'),
deviceSave: $('device-save'),
setMenu: $('set-menu'),
settings: $('settings'),
settingsBody: $('settingsBody'),
settingsList: $('settingsList'),
slider: $('slider'),
sliderMax: $('slider-max'),
sliderMin: $('slider-zero'),
sliderLo: $('slider-lo'),
sliderMid: $('slider-mid'),
sliderHi: $('slider-hi'),
sliderHold: $('slider-hold'),
sliderRange: $('slider-center'),
loading: $('progress').style,
progress: $('progbar').style,
prostatus: $('progtxt'),
selection: $('selection'),
sizeX: $('size_x'),
sizeY: $('size_y'),
sizeZ: $('size_z'),
scaleX: $('scale_x'),
scaleY: $('scale_y'),
scaleZ: $('scale_z'),
lockX: $('lock_x'),
lockY: $('lock_y'),
lockZ: $('lock_z'),
stock: $('stock'),
stockWidth: $('stock-width'),
stockDepth: $('stock-width'),
stockHeight: $('stock-width'),
// static html --> ui bindings
...bind(),
/** Device Browser / Editor */
@ -592,19 +483,19 @@ function init_one() {
input_binding(ui);
$('lab-axis').onclick = () => {
ui.lockX.checked =
ui.lockY.checked =
ui.lockZ.checked = !(
ui.lockX.checked ||
ui.lockY.checked ||
ui.lockZ.checked
ui.lock.X.checked =
ui.lock.Y.checked =
ui.lock.Z.checked = !(
ui.lock.X.checked ||
ui.lock.Y.checked ||
ui.lock.Z.checked
);
};
$('scale-reset').onclick = $('lab-scale').onclick = () => {
selection.scale(1 / ui.scaleX.was, 1 / ui.scaleY.was, 1 / ui.scaleZ.was);
ui.scaleX.value = ui.scaleY.value = ui.scaleZ.value =
ui.scaleX.was = ui.scaleY.was = ui.scaleZ.was = 1;
selection.scale(1 / ui.scale.X.was, 1 / ui.scale.Y.was, 1 / ui.scale.Z.was);
ui.scale.X.value = ui.scale.Y.value = ui.scale.Z.value =
ui.scale.X.was = ui.scale.Y.was = ui.scale.Z.was = 1;
};
$('app-xpnd').onclick = () => {

View file

@ -10,6 +10,7 @@ import { settings as set_ctrl } from '../conf/manager.js';
import { settingsOps } from '../conf/settings.js';
import { space } from '../../../moto/space.js';
import { VIEWS } from '../../core/consts.js';
import * as view_tools from '../tools.js';
const DOC = self.document;
const WIN = self.window;
@ -201,6 +202,18 @@ function setup_keybd_nav(ui, WIN, LANG) {
const { selection } = api;
// bind interface action elements
ui.acct.help.onclick = (ev) => { ev.stopPropagation(); api.help.show() };
ui.acct.don8.onclick = (ev) => { ev.stopPropagation(); api.modal.show('don8') };
ui.acct.mesh.onclick = (ev) => { ev.stopPropagation(); WIN.location = "/mesh" };
ui.acct.export.onclick = (ev) => { ev.stopPropagation(); settingsOps.profileExport() };
ui.acct.export.title = LANG.acct_xpo;
ui.func.slice.onclick = (ev) => { ev.stopPropagation(); api.function.slice() };
ui.func.preview.onclick = (ev) => { ev.stopPropagation(); api.function.print() };
ui.func.animate.onclick = (ev) => { ev.stopPropagation(); api.function.animate() };
ui.func.export.onclick = (ev) => { ev.stopPropagation(); api.function.export() };
// prevent modal input from propagating to parents
ui.modalBox.onclick = (ev) => { ev.stopPropagation() };
$('export-support-a').onclick = (ev) => { ev.stopPropagation(); api.modal.show('don8') };
$('mode-device').onclick = api.show.devices;
$('mode-profile').onclick = settingsOps.settingsLoad;
@ -215,18 +228,9 @@ function setup_keybd_nav(ui, WIN, LANG) {
$('set-profs').onclick = (ev) => { ev.stopPropagation(); api.conf.show() };
$('set-tools').onclick = (ev) => { ev.stopPropagation(); api.show.tools() };
$('set-prefs').onclick = (ev) => { ev.stopPropagation(); api.modal.show('prefs') };
ui.acct.help.onclick = (ev) => { ev.stopPropagation(); api.help.show() };
ui.acct.don8.onclick = (ev) => { ev.stopPropagation(); api.modal.show('don8') };
ui.acct.mesh.onclick = (ev) => { ev.stopPropagation(); WIN.location = "/mesh" };
ui.acct.export.onclick = (ev) => { ev.stopPropagation(); settingsOps.profileExport() };
ui.acct.export.title = LANG.acct_xpo;
$('file-new').onclick = (ev) => { ev.stopPropagation(); settingsOps.workspaceNew() };
$('file-recent').onclick = () => { api.modal.show('files') };
$('file-import').onclick = (ev) => { api.event.import(ev); };
ui.func.slice.onclick = (ev) => { ev.stopPropagation(); api.function.slice() };
ui.func.preview.onclick = (ev) => { ev.stopPropagation(); api.function.print() };
ui.func.animate.onclick = (ev) => { ev.stopPropagation(); api.function.animate() };
ui.func.export.onclick = (ev) => { ev.stopPropagation(); api.function.export() };
$('view-arrange').onclick = api.platform.layout;
$('view-top').onclick = space.view.top;
$('view-home').onclick = space.view.home;
@ -238,12 +242,14 @@ function setup_keybd_nav(ui, WIN, LANG) {
api.widgets.for(w => w.unrotate());
selection.update_info();
};
// attach button handlers to support targets
for (let btn of ["don8pt","don8gh","don8pp"]) {
$(btn).onclick = (ev) => {
window.open(ev.target.children[0].href);
}
}
// rotation buttons
let d = (Math.PI / 180);
$('rot_x_lt').onclick = () => { selection.rotate(-d * $('rot_x').value,0,0) };
@ -252,6 +258,7 @@ function setup_keybd_nav(ui, WIN, LANG) {
$('rot_y_gt').onclick = () => { selection.rotate(0, d * $('rot_y').value,0) };
$('rot_z_lt').onclick = () => { selection.rotate(0,0, d * $('rot_z').value) };
$('rot_z_gt').onclick = () => { selection.rotate(0,0,-d * $('rot_z').value) };
// rendering options
$('render-edges').onclick = () => { api.view.edges({ toggle: true }); api.conf.save() };
$('render-ghost').onclick = () => { api.view.wireframe(false, 0, api.view.is_arrange() ? 0.4 : 0.25); };
@ -263,21 +270,15 @@ function setup_keybd_nav(ui, WIN, LANG) {
$('mesh-split').onclick = selection.isolateBodies;
$('context-duplicate').onclick = selection.duplicate;
$('context-mirror').onclick = selection.mirror;
$('context-layflat').onclick = () => { api.event.emit("tool.mesh.lay-flat") };
$('context-lefty').onclick = () => { api.event.emit("tool.mesh.lefty") };
$('context-layflat').onclick = view_tools.startLayFlat;
$('context-lefty').onclick = view_tools.startLeftAlign;
$('context-setfocus').onclick = () => {
api.event.emit(
"tool.camera.focus",
ev => api.space.set_focus(undefined, ev.object.point)
);
view_tools.startFocus(ev => api.space.set_focus(undefined, ev.object.point));
};
$('context-contents').onclick = () => { api.SPACE.view.fit() };
$('view-fit').onclick = () => { api.SPACE.view.fit() };
$('context-contents').onclick = api.const.SPACE.view.fit;
$('view-fit').onclick = api.const.SPACE.view.fit;
$('wassup').onmouseover = () => { $('suppopp').classList.remove('hide') };
// prevent modal input from propagating to parents
ui.modalBox.onclick = (ev) => { ev.stopPropagation() };
// enable modal hiding
$('mod-x').onclick = api.modal.hide;