Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to change min/max/step etc at Runtime #63

Closed
ciknowles opened this issue Jun 6, 2020 · 9 comments
Closed

Ability to change min/max/step etc at Runtime #63

ciknowles opened this issue Jun 6, 2020 · 9 comments

Comments

@ciknowles
Copy link

Hi,

I'm confused by this one. I don't know how to update any config of the config parameters at runtime.

For example:

Create a point 2D menu
config = {label:'Center',x: {min: -100, max: 100, step:0.1 },y: {min: -100, max: 100, step:0.1 }};
tweakpane.addInput(menu, 'value', config);

If I then change config sometime later (because the user has changed a container size for example)
config.x.min = -10
tweakpane.refresh();

The min/max values are not updated. Not sure how to even hack this one?

Chris

@cocopon
Copy link
Owner

cocopon commented Jun 6, 2020

Currently there is no way to change parameters at runtime for maintainability reason. Please dispose a component and re-create it with new config.

@ciknowles
Copy link
Author

Hi,

This might work but how do I dispose a component (say an input) and then recreate it in the same place?

Thanks,

Chris

@cocopon
Copy link
Owner

cocopon commented Jun 7, 2020

Ah I forgot to add dispose() to input binding API. I just released the latest version 1.3.5 so please check it.

@ciknowles
Copy link
Author

Ah,

I see that. So calling .dispose on the input binding will remove the item.

My next difficult question is - can I then re-add a new input in the same place that I've just removed one?

I've taken a look at the codebase - I see the problem with updating the config at runtime . Views are created in the view constructor with a div which is then appended. Unfortunately, I don't code ts so I'm struggling to work out how to allow the view to be recreated in the same place if the config is changed.

Chris

@cocopon
Copy link
Owner

cocopon commented Jun 7, 2020

You can use index config to specify a position of input. https://cocopon.github.io/tweakpane/misc.html

@cocopon
Copy link
Owner

cocopon commented Jun 7, 2020

Here is a simple example for re-creating a component with new config: https://codepen.io/cocopon/pen/pogJVQp

@ciknowles
Copy link
Author

AH,

Missed that. Fabulous.

FYI, I am asking about the config because I'm controlling a 3D scene where you can put sub objects on the face of an existing object.

Obviously, if you choose a different face, then the boundary of where you can place the sub object will change. Hence my questions!

Chris

@cocopon
Copy link
Owner

cocopon commented Jun 7, 2020

I understand! Thank you for the detailed information.

@cocopon cocopon closed this as completed Jun 7, 2020
@ciknowles
Copy link
Author

Hi,
I'm now using 1.3.5.

Hidden works really well - thanks.
Dispose and then recreate also works - thanks! It's a little tricky (well not that tricky) as you need to maintain a reference to the InputBinding interface and also the index when you first add.

Many thanks.

Chris

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants