Skip to content

Commit

Permalink
add theme
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Oct 31, 2023
1 parent 1ebacc8 commit 0679644
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 95 deletions.
67 changes: 36 additions & 31 deletions dist/0.x/muigui.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,30 +867,27 @@
const { min, max } = options;
const guiMinRange = options.minRange || 0;
const valueMinRange = from(guiMinRange)[1];
console.log('guiMinRange', guiMinRange);
console.log('valueMinRange', valueMinRange);
return [
gui
.add(properties, minPropName, {
...options,
min,
max: max - guiMinRange,
})
.listen()
.onChange(v => {
properties[maxPropName] = Math.min(max, Math.max(v + valueMinRange, properties[maxPropName]));
}),
gui
.add(properties, maxPropName, {
...options,
min: min + guiMinRange,
max,
})
.listen()
.onChange(v => {
properties[minPropName] = Math.max(min, Math.min(v - valueMinRange, properties[minPropName]));
}),
];
const minGui = gui
.add(properties, minPropName, {
...options,
min,
max: max - guiMinRange,
})
// .listen()
.onChange(v => {
maxGui.setValue(Math.min(max, Math.max(v + valueMinRange, properties[maxPropName])));
});
const maxGui = gui
.add(properties, maxPropName, {
...options,
min: min + guiMinRange,
max,
})
// .listen()
.onChange(v => {
minGui.setValue(Math.max(min, Math.min(v - valueMinRange, properties[minPropName])));
});
return [ minGui, maxGui ];
}

class View {
Expand Down Expand Up @@ -1358,31 +1355,39 @@
return view;
}
#setValueImpl(v, ignoreCache) {
let isDifferent = false;
if (typeof v === 'object') {
const dst = this.#object[this.#property];
// don't replace objects, just their values.
if (Array.isArray(v)) {
if (Array.isArray(v) || isTypedArray(v)) {
for (let i = 0; i < v.length; ++i) {
isDifferent ||= dst[i] !== v[i];
dst[i] = v[i];
}
} else if (isTypedArray(v)) {
dst.set(v);
} else {
for (const key of Object.keys(v)) {
isDifferent ||= dst[key] !== v[key];
}
Object.assign(dst, v);
}
} else {
isDifferent = this.#object[this.#property] !== v;
this.#object[this.#property] = v;
}
this.updateDisplay(ignoreCache);
this.emitChange(this.getValue(), this.#object, this.#property);
return this;
if (isDifferent) {
this.emitChange(this.getValue(), this.#object, this.#property);
}
return isDifferent;
}
setValue(v) {
this.#setValueImpl(v);
}
setFinalValue(v) {
this.#setValueImpl(v, true);
this.emitFinalChange(this.getValue(), this.#object, this.#property);
const isDifferent = this.#setValueImpl(v, true);
if (isDifferent) {
this.emitFinalChange(this.getValue(), this.#object, this.#property);
}
return this;
}
updateDisplay(ignoreCache) {
Expand Down
2 changes: 1 addition & 1 deletion dist/0.x/muigui.min.js

Large diffs are not rendered by default.

67 changes: 36 additions & 31 deletions dist/0.x/muigui.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,30 +861,27 @@ function makeMinMaxPair(gui, properties, minPropName, maxPropName, options) {
const { min, max } = options;
const guiMinRange = options.minRange || 0;
const valueMinRange = from(guiMinRange)[1];
console.log('guiMinRange', guiMinRange);
console.log('valueMinRange', valueMinRange);
return [
gui
.add(properties, minPropName, {
...options,
min,
max: max - guiMinRange,
})
.listen()
.onChange(v => {
properties[maxPropName] = Math.min(max, Math.max(v + valueMinRange, properties[maxPropName]));
}),
gui
.add(properties, maxPropName, {
...options,
min: min + guiMinRange,
max,
})
.listen()
.onChange(v => {
properties[minPropName] = Math.max(min, Math.min(v - valueMinRange, properties[minPropName]));
}),
];
const minGui = gui
.add(properties, minPropName, {
...options,
min,
max: max - guiMinRange,
})
// .listen()
.onChange(v => {
maxGui.setValue(Math.min(max, Math.max(v + valueMinRange, properties[maxPropName])));
});
const maxGui = gui
.add(properties, maxPropName, {
...options,
min: min + guiMinRange,
max,
})
// .listen()
.onChange(v => {
minGui.setValue(Math.max(min, Math.min(v - valueMinRange, properties[minPropName])));
});
return [ minGui, maxGui ];
}

class View {
Expand Down Expand Up @@ -1352,31 +1349,39 @@ class ValueController extends LabelController {
return view;
}
#setValueImpl(v, ignoreCache) {
let isDifferent = false;
if (typeof v === 'object') {
const dst = this.#object[this.#property];
// don't replace objects, just their values.
if (Array.isArray(v)) {
if (Array.isArray(v) || isTypedArray(v)) {
for (let i = 0; i < v.length; ++i) {
isDifferent ||= dst[i] !== v[i];
dst[i] = v[i];
}
} else if (isTypedArray(v)) {
dst.set(v);
} else {
for (const key of Object.keys(v)) {
isDifferent ||= dst[key] !== v[key];
}
Object.assign(dst, v);
}
} else {
isDifferent = this.#object[this.#property] !== v;
this.#object[this.#property] = v;
}
this.updateDisplay(ignoreCache);
this.emitChange(this.getValue(), this.#object, this.#property);
return this;
if (isDifferent) {
this.emitChange(this.getValue(), this.#object, this.#property);
}
return isDifferent;
}
setValue(v) {
this.#setValueImpl(v);
}
setFinalValue(v) {
this.#setValueImpl(v, true);
this.emitFinalChange(this.getValue(), this.#object, this.#property);
const isDifferent = this.#setValueImpl(v, true);
if (isDifferent) {
this.emitFinalChange(this.getValue(), this.#object, this.#property);
}
return this;
}
updateDisplay(ignoreCache) {
Expand Down
2 changes: 1 addition & 1 deletion dist/0.x/muigui.module.min.js

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions src/controllers/ValueController.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,39 @@ export default class ValueController extends LabelController {
return view;
}
#setValueImpl(v, ignoreCache) {
let isDifferent = false;
if (typeof v === 'object') {
const dst = this.#object[this.#property];
// don't replace objects, just their values.
if (Array.isArray(v)) {
if (Array.isArray(v) || isTypedArray(v)) {
for (let i = 0; i < v.length; ++i) {
isDifferent ||= dst[i] !== v[i];
dst[i] = v[i];
}
} else if (isTypedArray(v)) {
dst.set(v);
} else {
for (const key of Object.keys(v)) {
isDifferent ||= dst[key] !== v[key];
}
Object.assign(dst, v);
}
} else {
isDifferent = this.#object[this.#property] !== v;
this.#object[this.#property] = v;
}
this.updateDisplay(ignoreCache);
this.emitChange(this.getValue(), this.#object, this.#property);
return this;
if (isDifferent) {
this.emitChange(this.getValue(), this.#object, this.#property);
}
return isDifferent;
}
setValue(v) {
this.#setValueImpl(v);
}
setFinalValue(v) {
this.#setValueImpl(v, true);
this.emitFinalChange(this.getValue(), this.#object, this.#property);
const isDifferent = this.#setValueImpl(v, true);
if (isDifferent) {
this.emitFinalChange(this.getValue(), this.#object, this.#property);
}
return this;
}
updateDisplay(ignoreCache) {
Expand Down
43 changes: 19 additions & 24 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,24 @@ export function makeMinMaxPair(gui, properties, minPropName, maxPropName, option
const { min, max } = options;
const guiMinRange = options.minRange || 0;
const valueMinRange = from(guiMinRange)[1];
console.log('guiMinRange', guiMinRange);
console.log('valueMinRange', valueMinRange);
return [
gui
.add(properties, minPropName, {
...options,
min,
max: max - guiMinRange,
})
.listen()
.onChange(v => {
properties[maxPropName] = Math.min(max, Math.max(v + valueMinRange, properties[maxPropName]));
}),
gui
.add(properties, maxPropName, {
...options,
min: min + guiMinRange,
max,
})
.listen()
.onChange(v => {
properties[minPropName] = Math.max(min, Math.min(v - valueMinRange, properties[minPropName]));
}),
];
const minGui = gui
.add(properties, minPropName, {
...options,
min,
max: max - guiMinRange,
})
.onChange(v => {
maxGui.setValue(Math.min(max, Math.max(v + valueMinRange, properties[maxPropName])));
});
const maxGui = gui
.add(properties, maxPropName, {
...options,
min: min + guiMinRange,
max,
})
.onChange(v => {
minGui.setValue(Math.max(min, Math.min(v - valueMinRange, properties[minPropName])));
});
return [ minGui, maxGui ];
}

0 comments on commit 0679644

Please sign in to comment.