Window enabling / disabling

Hi,
I have a problem with Window.
I want to have scrollable inventory from which I could drag objects out of a Window.
I want to disable Window's scrolling when I click on object inside Window and then make another object appear in the same place (on Stage) and drag it out with mouse.
Disabling Window works but on mouseup when I enable Window again the Window is "out of focus". ScrollBar and MouseWheel do not work until I click inside Window container.
What is the right way to do it?
window

Here is my code with comments:

function initScrollWindow(){
	const insideFromAnimate = zimify(_main.insideMC, 300,552).addTo(S); //insideMC is made in Animate
	scrollWindow2 = new Window({
		width:300,
		height:300,
		paddingV:0,
		content:insideFromAnimate,
		scrollBarDrag:true,
		damp:.1
	}).pos(700, 100);
	scrollWindow2.update();
	
	redSquare = zimify(_main.insideMC.redSquare, 154,154); //insideMC contains redSquare that I want to drag
	redSquare.on("pressdown", function (evt) {
		point = scrollWindow2.localToGlobal(redSquare.x-redSquare.width/2,redSquare.y-redSquare.height/2)
		r.x = point.x; 
		r.y = point.y;
		S.addEventListener("stagemousemove", handleMouseMove);
		r.addTo(S);
		scrollWindow2.enabled = false; //trying to disable Window when I drag "r" and it works
		/*scrollWindow2.cancelCurrentDrag() //it was promising but not exactly what I want - doesn't respond on ScrollBar and MouseWheel */
	});	
}	
function handleMouseMove(e){
	r.pos(S.mouseX-r.width/2, S.mouseY-r.height/2);
}
function handleMouseUp(e){
	S.removeEventListener("stagemousemove",handleMouseMove);
	scrollWindow2.enabled = true; //when I enable Window again the Window is "out of focus". ScrollBar and MouseWheel do not work until I click inside Window container. But then damping doesn't seem to work.
	/*scrollWindow2.scrollEnabled  = true; //no luck with these values
	scrollWindow2.scrollBarDrag = true;
	scrollWindow2.scrollWheel  = true;*/
	scrollWindow2.update();
}

We will check on enabled false and true to see if we are missing something there.

Have you seen the dropTarget stuff in ZIM 017?

ZIM - Dropping - Code Creativity (note example 2 at bottom)

https://zimjs.com/017/canvas.html

https://codepen.io/zimjs/pen/gbOOaLd

Our test file works when setting enable = true then enable = false on a Window.

https://zimjs.com/test9/window3.html

Wonder if it is the version of CreateJS- we had the Animate version cause the List to scroll at the start but then work fine. Could not debug that. Which version of CreateJS are you using? In the ZIM SHIM there is a local folder - if you use the zimshim in that folder it points to local versions of ZIM and CreateJS. Just doing a test with those might tell us.

I think though, it sounds like you could use the List with the dropTarget parameters.

It turns out that "damp:.1" parameter is the culprit.

If you modify your example as below and add "damp:.1" to Window properties it would stop working (until you click inside Window container).

Without dump, even my previous example works. So maybe a bug?

Thank you for the ZIM 017 examples. I'll definitely check them out.

var rct = new Rectangle(100,100, red);
rct.on("pressdown", function(evt) {  //I know it works only for first rectangle but doesn't matter
	zog("pressdown");
	window.enabled = false;
})
rct.on("pressup", function(evt) { 
	zog("pressup");
	window.enabled = true;
})
	
const tile = new Tile(rct,2,20,20,20);

const window = new Window({
	scrollBarDrag:true,
	content:tile, 
	damp:.1 //--I got you
}).center()
1 Like

Yes - sounds like a bug. Heading out now, but will look at it later.

Okay - this has been fixed and patched in ZIM 018 - thanks! When the enabled false was set during damping, it did not record that swiping had finished. So the scrollbar remained disabled. So simple fix. What was more complicated is that we noticed with damping set and optimize true (default), you could scroll fast with the scrollbar and let go and the testContent that tests if the content is on the screen was not being called as it damped into location... leaving content missing. So we fixed that too. Woot. Do a hard refresh and it should be good.

Can try here: https://zimjs.com/test9/window3.html

With hard refresh...

Thank you for your hard work.
It works better but... :slight_smile:
When you use it with my example (pressdown / pressup):

now Window is working again but after pressup the damping (easing of scroll window) is not working anymore. And also ScrollBar and MouseWheel is "stuttering" or "moving slowly".
So it works but not like before was disabled.

One more thing - after enabling there is stuttering but if you click inside Window content everything is working again.
So the scenario is: enabled = false -> enbaled = true -> (don't click inside the content) -> easing not working on mouse wheel and scrollbar -> (click inside the content) -> working again.

What is it like for you on my example at https://zimjs.com/test9/window3.html

I have replaced the ZIM 018 in the local files in the ZIM SHIM zip - if our example does not stutter for you, perhaps you could try with the local ZIM and CreateJS. Or zip up a test version that has the problem and DM me and I can have a look.

Yes, I can replicate this behavior even with your example but it's tricky because you gave it only 1 second gap :slight_smile:
Here is what I do:

  1. After 2 seconds (during disable state) click on the first tile and drag the mouse out of the Window (you have to fit in between 2 and 3 seconds)
  2. Release mouse click outside the Window
  3. Mouse over Window and try mouse scroll and scrollbar - it's working differently
  4. Click on any Rectangle again and it works again.
    As if it loses mind when releasing mouse button outside the Window :slight_smile:

Edit: ^this is on online version directly on your example link

stutter

Okay - thanks. Just updated the example to have disable from 3 to 5 seconds and added a color change. I replicated the problem too... so will have a look now.

Yes, I've tested it and it turns out that you have to click and drag outside before 3 second, so before disable state. So I was wrong at 1. point.
Edit: And mouse wheel is working even in disable state (3 - 5) scrollbar is disable correctly

1 Like

Okay - that should be fixed now and patched to ZIM 018. Thanks. There was a stageUp function that needed to be run that normally runs on mouseup but not if disabled. Do a hard refresh.

Yes, your example is working fine now (minus active mousewheel even in disabled state).
But mine is still not working with "damp:.1". It's really strange.
Just pressdown and pressup on first rct is giving stuttering like before your latest fix.
But if you click on any other rectangle it is working fine again.

I see what you mean - same here. Let me see if I can debug what is going on.

The issue seems to be that the window is being disabled on mousedown of the window. This solves it:

rct.on("pressdown", function(evt) {  
	 timeout(.05, ()=>{window.enabled = false;});
})

Will give it some thought and see if there is something to do on our side to fix it.

Okay - just put the slight delay into the enabled=false and it seems to work fine. Tested it in three different cases including the list and all good.

So do a hard refresh and try your original with out the timeout.

Let us know.

Yes, your workaround seems to work but I discovered another "magic trick" that you can do.
It can be done with or without timeout on pressdown. Only with "damp:.1" present in Window options.
If you drag down first rectangle a little repeatedly, you can drag your content out of bounds :slight_smile:

goodbye-content

Yes. Oops. Will see what we can do about that. Going to a movie in a few minutes... so might be later on for a solution. Or drag the other one then press on the first. It is because the enabled=false cuts into the snapping back and the enabled=true does not test for that... so... probably would be best to just test for snapping back enabled=true. Might be able to update that now.

I need to go - eat some dinner too. Sorry - should be able to fix that when I get back later tonight. Cheers. Thanks again for all your help and patience.