Best way to slide stack into view

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 4:19 am

I am trying to create a menu that will be permanently docked on the left side of the screen. Thanks to some help I am understanding how to do this
but now I am trying to figure out the best method for displaying the stack in a smooth manner.

I want to slide the stack into view. It will start out just wide enough so the user knows its a menu box basically. then the user
clicks on a logo on the stack and the menu will slide out. this is the code i am in the mouseup right now but am sure there is
probably a better way.

Code: Select all

repeat for 40 times
   set the width of this stack to the width of this stack + 10
   wait 5
end repeat
edit: i know my code is not the best because wait locks up the whole application. there must be a better way.
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Best way to slide stack into view

Post by dglass » Fri Jun 24, 2011 5:27 am

That Panel example I provided in the Summer Academy forum would be a good place to start. :|

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 5:42 am

You mean the panel splitter example? I see that let's
Me resize panels but I'm not sure how to show
And hide a stack into or out of view.
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Best way to slide stack into view

Post by dglass » Fri Jun 24, 2011 5:45 am

No, I mean the example I put together to show you how to mimic a drawer.

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 6:13 am

got it. only problem is that wait locks the screen up. is there any other way to do with out locking up the screen during the sliding of the stack out?
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Best way to slide stack into view

Post by dglass » Fri Jun 24, 2011 6:24 am

put a 'with messages' at the end of the 'wait' call.

I commented that bit out in the example stack, so it's there ... waiting.

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 6:49 am

Thanks. One more question I got it working using the below code in stack code
For hidePanel I would like to give the user a grace period before the menu panel
hides. Basically if the user re-enters the panel with their mouse before 20 miliseconds it should keep from running hidePanel. Any idea how to do that?
BTW: Does my code seem to make sense did i do everything correctly.

What happens is there is always 30 pixels wide of the panel showing when the mouse click in the panel it slides out. when the mouse leaves
the panel it slides in basically sliding the panel off screen and leaving just 30 pixels.

Code: Select all

on mouseleave
hidePanel
end mouseleave

on mousedown
 showPanel
end mousedown

on hidePanel

   repeat while the left of this stack > -150
      lock screen
      set the left of this stack to the left of this stack - 1
      go to this stack
      unlock screen
      wait 10 milliseconds with messages
   end repeat
end hidePanel
on showPanel
 set the width of this stack to 180
set the height of this stack to item 4 of the screenrect - item 2 of the screenrect
set the left of this stack to -165
set the top of this stack to 0

   repeat while the left of this stack < 0
      lock screen
      set the left of this stack to the left of this stack + 1
      go to this stack
      unlock screen
      wait 10 milliseconds with messages
   end repeat
end showPanel
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Best way to slide stack into view

Post by dglass » Fri Jun 24, 2011 7:00 am

You probably don't need the 'go to this stack' calls. I had that in the drawer example in an attempt to keep the parent stack in front of the 'drawer' stack.

I would try something like...

Code: Select all

on mouseleave
put true into sExitingMenu
send "hidePanel" to me in 20 milliseconds
end mouseleave

on hidePanel
if sExitingMenu is true then
...do stuff to hide the stack
end if
end hidePanel

on mouseEnter
put false into sExitingMenu
...other stuff
end mouseEnter

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 4:26 pm

works great. i got that all set up just one problem i cant seem to figure out. When I mouseenter the stack it calls my showPanel command,
and when i mouseleave it calls hidePanel but if i hover my mouse back oveer the stack before 2 seconds it doesn't stop the hidepanel it still
hides the panel. What do I need to do to make it stop performing hidePanel and go back to showPanel. I thought checking the mousestack
against the shortname would work but it didnt. any ideas?


this my stack code:

Code: Select all

on preopenstack
    set the width of this stack to 170
set the height of this stack to item 4 of the screenrect - item 2 of the screenrect
set the left of this stack to -155
set the top of this stack to 0
end preopenstack
   

global sExitingmenu

on mouseleave
   put true into sExitingmenu
   if the mousestack is not the short name of me then
      send "hidePanel" to me in 2000 milliseconds
      end if
end mouseleave

on mouseenter
   if the mousestack is the short name of me then
      showPanel
      end if
end mouseenter

on hidePanel
   answer "should hide"
   answer sExitingmenu
    if sExitingmenu is true then
   repeat while the left of this stack > -150
      lock screen
      set the left of this stack to the left of this stack - 1
      go to this stack
      unlock screen
      wait 5 milliseconds with messages
   end repeat
   end if
end hidePanel

on showPanel
   repeat while the left of this stack < 0
      lock screen
      set the left of this stack to the left of this stack + 1
      go to this stack
      unlock screen
      wait 5 milliseconds with messages
   end repeat
end showPanel
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Best way to slide stack into view

Post by dglass » Fri Jun 24, 2011 4:30 pm

In your 'mouseenter' handler you aren't setting sExitingMenu to false. If you add that what happens?

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 4:57 pm

It seems like that feature is "sticky". If I mouse over the stack it shows the slide. If I mouse out and then back in
the slide doesn't go away but if i mouse out again its confused by that point i guess and doesn't do anything unless i
mouse click on the stack. I have attached the source file and also added a field status that shows enter, and leaving
the the stack to see that it does not work sometimes. is this just the way things work or is there a fix?
Attachments
PanelTest.zip
(1.91 KiB) Downloaded 328 times
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Best way to slide stack into view

Post by dglass » Fri Jun 24, 2011 5:40 pm

The attached seems to do what you want.

a) because you have mouse handlers in your card script you need to 'pass' them along if you have them in any of the objects on that card.
b) I added a check of sExitingMenu within the hiding loop in case the value changes while it is hiding.
c) I added setting the sExitingMenu in the mousemove if the mousestack is the right stack. This should ensure the value is always correct.
Attachments
GroupTest - Copy.livecode.zip
fixed sliding stack
(2.54 KiB) Downloaded 349 times

jesse
Posts: 205
Joined: Thu Nov 11, 2010 6:32 pm

Re: Best way to slide stack into view

Post by jesse » Fri Jun 24, 2011 8:29 pm

Brilliant. Exactly what I needed. Thank you so much. I see how it works now and why it wasn't working completely for me. :)
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392

catalinanesia
Posts: 83
Joined: Sun Feb 16, 2014 10:08 pm

Re: Best way to slide stack into view

Post by catalinanesia » Fri May 29, 2015 8:26 pm

Uau,
Thanks for this share, I do have a strange or not behavior with this ...
I opened the stack in LiveCode Comunity V6.6.2 under Windows XP,
the LC is in EDIT mode and the stack it is nicely positioned on the left side of the screen
almost hidden and with the mouse over it is nicely and smoothly sliding on the screen
and when i click of the stack it slides back, uau but: LC is in Edit mode so how come the stack is active?
if this is a feature of LC then sorry for my lack of knowledge ... (is it the preopenCard handler who does that?)
when I switch LC in RUN mode the movement it is very very lagging (it is not smooth anymore)
Nice stack any way!
Thanks to the creator.
Catalin

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Best way to slide stack into view

Post by Simon » Fri May 29, 2015 9:26 pm

Hi Catalin,
Look at the changes here;

Code: Select all

on showPanel
   --repeat while the left of this stack < 0
   if the left of this stack <0 then 
      lock screen
      set the left of this stack to the left of this stack + 5
      unlock screen
      --wait 5 milliseconds with messages
      --end repeat
      send "showPanel" to me in 25 millisecs
   end if
end showPanel
That send in time works much better.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply