muigui 0.0.16 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -179,9 +179,9 @@ into using tweakpane and it doesn't meet my needs as of v4.0.0. Examples below
179
179
  ```js
180
180
  const uniforms = {
181
181
  color1: [1, 0.5, 0.25], // orange
182
- color2: new Float32Array([0, 1, 1]); // cyan
183
- color3: new Uint8Array([0, 128, 0, 128]); // transparent green
184
- }
182
+ color2: new Float32Array([0, 1, 1]), // cyan
183
+ color3: new Uint8Array([0, 128, 0, 128]), // transparent green
184
+ };
185
185
  ```
186
186
 
187
187
  Neither dat.gui, lil.gui, nor tweakpane can edit these AFAICT. (2023)
@@ -311,11 +311,11 @@ have not made it into muigui yet.
311
311
  But that's not really what you get from a typed system.
312
312
  In a typed system, the fact that `someOption` is an enum
313
313
  is known from its type. Similar that `someColor` is a
314
- a color is known from it's type. `someNumber` is still
314
+ a color is known from its type. `someNumber` is still
315
315
  problematic because it needs a range which is probably
316
316
  not part of its type.
317
317
 
318
- In any case, I'd be nice to find a way to get an
318
+ In any case, It'd be nice to find a way to get an
319
319
  instant UI like C#/Unity does.
320
320
 
321
321
  * ## Modularity
@@ -325,7 +325,10 @@ have not made it into muigui yet.
325
325
  editor that is the combination of 3 number editors.
326
326
 
327
327
  I'm still experimenting. While muigui has components that
328
- do this I'm not happy with the API ergonomics yet.
328
+ do this I'm not happy with the API ergonomics yet and is
329
+ why I haven't documented them. In fact I'd pretty much like
330
+ to re-write all of the code for like the 4th time 😅 but
331
+ I hope to keep the normal usage API the same.
329
332
 
330
333
  Similarly I'd like to more easily split layout so it's trivial
331
334
  to layout sub components. Again, still experimenting.
@@ -380,6 +383,36 @@ have not made it into muigui yet.
380
383
  just returned a canvas and left the rest outside
381
384
  the library made it way more flexible.
382
385
 
386
+ Another example might be monitoring. Some libraries
387
+ provide a way to make a GUI part poll its value for
388
+ the purpose of displaying values but does that really
389
+ need to be part of the library?
390
+
391
+ Compare
392
+
393
+ ```js
394
+ pane.addBinding(PARAMS, 'data', {
395
+ readonly: true,
396
+ interval: 200,
397
+ });
398
+ ```
399
+
400
+ vs
401
+
402
+ ```js
403
+ const label = gui.addLabel();
404
+ setInterval(() => {
405
+ label.text(JSON.stringify(PARAMS.data, null, 2));
406
+ }, 200);
407
+ ```
408
+
409
+ They're about the same amount of code but in the first version
410
+ you can only make that area show the data at `PARAMS.data` where
411
+ as in the 2nd version you can show whatever you want. Data
412
+ for the currently select item, player stats, a text based graph.
413
+ You're not limited to only properties of `PARAMS` nor are you
414
+ limited to how it chooses to format those.
415
+
383
416
  This problem of providing too specialized a solution
384
417
  is endemic throughout the library ecosystem of pretty much
385
418
  every language.
@@ -389,6 +422,8 @@ have not made it into muigui yet.
389
422
  wrong solution. It's better to provide the
390
423
  building blocks.
391
424
 
425
+ `</rant>` 😅
426
+
392
427
  ## No Save/Restore
393
428
 
394
429
  The problem with save/restore in lil.gui etc is it assumes the data
@@ -1,7 +1,7 @@
1
1
  export default class Button extends Controller {
2
2
  constructor(object: any, property: any, options?: {});
3
- name(name: any): void;
4
- setOptions(options: any): void;
3
+ name(name: any): this;
4
+ setOptions(options: any): this;
5
5
  #private;
6
6
  }
7
7
  import Controller from './Controller.js';
@@ -1,6 +1,7 @@
1
1
  export default class Canvas extends LabelController {
2
2
  constructor(name: any);
3
3
  get canvas(): HTMLElement;
4
+ listen(): this;
4
5
  #private;
5
6
  }
6
7
  import LabelController from './LabelController.js';
@@ -8,6 +8,7 @@ export default class Container extends Controller {
8
8
  addController(controller: any): any;
9
9
  pushContainer(container: any): any;
10
10
  popContainer(): this;
11
+ listen(): this;
11
12
  #private;
12
13
  }
13
14
  import Controller from './Controller.js';
@@ -1,4 +1,4 @@
1
- /* muigui@0.0.16, license MIT */
1
+ /* muigui@0.0.20, license MIT */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -91,6 +91,7 @@
91
91
  font-size: var(--font-size);
92
92
  box-sizing: border-box;
93
93
  line-height: 100%;
94
+ white-space: nowrap;
94
95
  }
95
96
  .muigui * {
96
97
  box-sizing: inherit;
@@ -294,7 +295,7 @@
294
295
  }
295
296
  .muigui-closed>.muigui-open-container>* {
296
297
  transition: all 0.1s ease-out;
297
- margin-top: -100%;
298
+ margin-top: -1000%;
298
299
  }
299
300
 
300
301
  /* ---- popdown ---- */
@@ -1214,11 +1215,13 @@
1214
1215
  }
1215
1216
  name(name) {
1216
1217
  this.#buttonElem.textContent = name;
1218
+ return this;
1217
1219
  }
1218
1220
  setOptions(options) {
1219
1221
  copyExistingProperties(this.#options, options);
1220
1222
  const {name} = this.#options;
1221
1223
  this.#buttonElem.textContent = name;
1224
+ return this;
1222
1225
  }
1223
1226
  }
1224
1227
 
@@ -2626,6 +2629,9 @@
2626
2629
  get canvas() {
2627
2630
  return this.#canvasElem;
2628
2631
  }
2632
+ listen() {
2633
+ return this;
2634
+ }
2629
2635
  }
2630
2636
 
2631
2637
  class ColorView extends EditView {
@@ -2767,6 +2773,12 @@
2767
2773
  this.#childDestController = this.#childDestController.parent;
2768
2774
  return this;
2769
2775
  }
2776
+ listen() {
2777
+ this.#controllers.forEach(c => {
2778
+ c.listen();
2779
+ });
2780
+ return this;
2781
+ }
2770
2782
  }
2771
2783
 
2772
2784
  class Folder extends Container {
@@ -3275,11 +3287,22 @@
3275
3287
  }
3276
3288
  }
3277
3289
 
3290
+ function camelCaseToSnakeCase(id) {
3291
+ return id
3292
+ .replace(/(.)([A-Z][a-z]+)/g, '$1_$2')
3293
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
3294
+ .toLowerCase();
3295
+ }
3296
+
3297
+ function prepName(name) {
3298
+ return camelCaseToSnakeCase(name.toString()).replaceAll('_', ' ');
3299
+ }
3300
+
3278
3301
  class GUIFolder extends Folder {
3279
3302
  add(object, property, ...args) {
3280
3303
  const controller = object instanceof Controller
3281
3304
  ? object
3282
- : createController(object, property, ...args);
3305
+ : createController(object, property, ...args).name(prepName(property));
3283
3306
  return this.addController(controller);
3284
3307
  }
3285
3308
  addCanvas(name) {
@@ -3288,9 +3311,13 @@
3288
3311
  addColor(object, property, options = {}) {
3289
3312
  const value = object[property];
3290
3313
  if (hasAlpha(options.format || guessFormat(value))) {
3291
- return this.addController(new ColorChooser(object, property, options));
3314
+ return this
3315
+ .addController(new ColorChooser(object, property, options))
3316
+ .name(prepName(property));
3292
3317
  } else {
3293
- return this.addController(new Color(object, property, options));
3318
+ return this
3319
+ .addController(new Color(object, property, options))
3320
+ .name(prepName(property));
3294
3321
  }
3295
3322
  }
3296
3323
  addDivider() {
@@ -3304,7 +3331,7 @@
3304
3331
  }
3305
3332
  addButton(name, fn) {
3306
3333
  const o = {fn};
3307
- return this.add(o, 'fn').name(name);
3334
+ return this.add(o, 'fn').name(prepName(name));
3308
3335
  }
3309
3336
  }
3310
3337