cocopon / tweakpane

:control_knobs: Compact GUI for fine-tuning parameters and monitoring value changes
https://tweakpane.github.io/docs/
MIT License
3.41k stars 85 forks source link

export folder -> import folder not working as expected #600

Closed autonome closed 4 months ago

autonome commented 4 months ago

Here is example code for creating a new basic pane, with a folder and a binding, and exporting the folder state.

Then it adds a new folder, and imports the folder state.

The second folder should now look exactly like the first.

However, the binding is missing.

const pane = new Pane({
  container: el,
  title: labels.containerTitle
});

const f = pane.addFolder(
  {title: 'test folder'}
);

const strBinding = f.addBinding(
  {foo:'bar'},
  'foo', {}
);

const str = JSON.stringify(f.exportState(), null, ' ');

console.log(str);

const f2 = pane.addFolder(
  {title: 'test folder 2'}
);  

f2.importState(state);
autonome commented 4 months ago

Aha, it appears that the original example does not behave as I expected because it's importing a binding name that already exists - and will not create a duplicate, even if in a separate part of the binding hierarchy.

If that's the case, there is no bug and this can be closed!

cocopon commented 4 months ago

importState and exportState are literally for importing/exporting a pane state. They don't create new controls even if the state contains missing properties. If you want to import the value, you have to create a binding with the same name before importing.

autonome commented 4 months ago

Aha, in that case this issue can certainly be closed.