Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

React to slider changes after mouse is released #159

Closed
MoritzBrueckner opened this issue Sep 28, 2022 · 4 comments
Closed

React to slider changes after mouse is released #159

MoritzBrueckner opened this issue Sep 28, 2022 · 4 comments

Comments

@MoritzBrueckner
Copy link
Contributor

Following armory3d/armory2d#70:

It doesn't seem to be possible to run code only when a slider has been released after dragging. handle.change will already be false when ui.inputDown is false, and if the user doesn't move the mouse in the very last frame of holding down the mouse, value.changed isn't even true obviously. ui.inputReleased isn't even set for sliders when the mouse was moved.

This feature would be quite useful, since sometimes there are some costly calculations needed after changing a value, and changing it every frame could slow down the program. Or, in Armory2D's case, it is needed for the slider that changes the UI size. Unlike in Blender*, the amount the user has dragged a slider seems to be affected by the UI scale which will result in an uncontrollable feedback loop if the UI size changes while dragging the slider. If there was a way to update the UI size only after the slider was released, this problem wouldn't matter. If you want to see yourself what I mean with "feedback loop", change this line in Armory2D to if (hscale.changed) {.

*I guess this is because in Blender, sliders can be configured to not show the visual progress, in which case it doesn't matter whether the mouse aligns with the drawn progress bar.

@luboslenco
Copy link
Member

@luboslenco
Copy link
Member

Not a fix, but temporary workaround:

ui.slider(handle, "Slider");
if (wasChanged && !ui.inputDown) {
	wasChanged  = false;
	// Code
}
if (handle.changed) wasChanged = true;

@MoritzBrueckner
Copy link
Contributor Author

Thanks, that works like a charm 🎉

I think it needs to be slightly adjusted to

if (uiScaleChanged && (!ui.inputDown || ui.isReturnDown)) {

to also account for keyboard-only input, but I can't test it at the moment because the return key doesn't seem to work for sliders for some reason, it immediately resets the value to the previous one (not just with this particular slider)... It works neither with the Zui version currently used by Armory2D, nor with latest main. Is this a known issue, or even by purpose?

@luboslenco
Copy link
Member

Keeping the workaround in place, but a fix is still welcome if anyone gets to it.

Is this a known issue, or even by purpose?

Hm don't think so.

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

No branches or pull requests

2 participants