Trying to create a slide up drawer in stack

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

Post Reply
andyt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Mon Mar 08, 2010 10:41 am

Trying to create a slide up drawer in stack

Post by andyt » Wed May 27, 2015 11:57 pm

I'm really struggling to achieve a simple panel that is the width of the parent stack and slides upwards 250 pixels say from the bottom of the stack on mouse hover and slides away almost fully when mouse out. It is always partially visible so that it can be called into play on a mouseover action.

This is a very common UI feature and I've tried every which way to achieve it with tabs, cards, substacks, all to no avail. There is on this forum a great example of an independent sliding stack which is detached from the main stack and is relative to the screen which isn't quite what I want. I've tried in vain to modify this to work within the main stack window.

http://forums.livecode.com/viewtopic.php?t=8206&p=39064

What is the best way to achieve this please?

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 154
Joined: Thu Jun 29, 2006 4:16 pm

Re: Trying to create a slide up drawer in stack

Post by Randy Hengst » Thu May 28, 2015 1:05 am

Try this to get started. Place a graphic along the bottom of a card. Then in the graphic use this code:

on mouseEnter
move me relative 0,-100 in 60 ticks
end mouseEnter

on mouseLeave
set the top of me to the (bottom of this card - 50)
end mouseLeave

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Trying to create a slide up drawer in stack

Post by MaxV » Fri May 29, 2015 2:54 pm

If you are working on two separette stack, use the screenloc property, you can manipulate it.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

fgr33n
Posts: 86
Joined: Wed Oct 15, 2014 3:14 pm

Re: Trying to create a slide up drawer in stack

Post by fgr33n » Fri May 29, 2015 4:00 pm

If you are doing a UI in the "drawer", group all your buttons and background graphic together. Then put Randy's script on the group.

andyt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Mon Mar 08, 2010 10:41 am

Re: Trying to create a slide up drawer in stack

Post by andyt » Sun May 31, 2015 11:49 pm

Well I've managed to build a sliding draw using a graphic - thanks for the tip, I didn't think of that option. BUT I've spent the last 6 hours trying to get the draw group to adapt to window resizing.

Why is this so hard? I've got a resizeStack handler that basically resizes the group as follows:

Code: Select all

set the rect of group "slideMenu" to 0, stackHeight-80, stackWidth, stackHeight+170
BUT it doesn't work reliably and on some occasions breaks the slide motion on mouseEnter after resizing the window.

Anyone got a simple demo of a graphic group that resizes with the window or any clues where I'm going wrong?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9855
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Trying to create a slide up drawer in stack

Post by FourthWorld » Mon Jun 01, 2015 12:04 am

Resizing groups can be tricky until you set the lockLoc of the group and each of its enclosed objects to true. Without that, the engine struggles to know how to place things in a context that's changing out from under it. But with lockLoc set, your script has control and leaves nothing to any automatic layout accommodations groups would otherwise provide.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 154
Joined: Thu Jun 29, 2006 4:16 pm

Re: Trying to create a slide up drawer in stack

Post by Randy Hengst » Mon Jun 01, 2015 12:16 am

changing the size of a group does not automatically change the relative sizes of the controls in the group. Best I know, you need to script the relative size changes for all the controls in the group.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9855
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Trying to create a slide up drawer in stack

Post by FourthWorld » Mon Jun 01, 2015 1:45 am

Randy Hengst wrote:changing the size of a group does not automatically change the relative sizes of the controls in the group.
True, but if they're unlocked it can change their position. And if their positions are changing within an unlocked group, this may cause unintended consequences for the group's ability to accommodate such changes on the fly, esp. with regard to the group's margins and any graphic effects or other properties not commonly taken into account when scripting positions.

So the easiest way to have complete control under script of how objects behave within a group that can be resized is to set the lockLoc of the group and its interior objects. In some cases it can also help to set the backSize of the group, but from what I understand of this layout that shouldn't be needed here.

Try it, and see if it doesn't make working with dynamically resized groups a little easier and more predictable.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

andyt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Mon Mar 08, 2010 10:41 am

Re: Trying to create a slide up drawer in stack

Post by andyt » Mon Jun 01, 2015 7:43 pm

Thanks everyone for your help on this. lockLoc worked a treat FourthWorld.

I've attached an example of what I've been trying to achieve for soooo long.
sliding_drawer.zip
(2.18 KiB) Downloaded 224 times
You'll notice that the drawer will re-open almost immediately even if the mouse leaves it during it transition South. However I tried to employ similar code to make it close if the mouse leaves mid transition North. It didn't work and if your mouse leaves the drawer as it is opening then it doesn't seem to be aware that the mouse has left and should close.

The other obvious flaw (if indeed it is one) is that if you resize quick enough while the draw is open or in transition the resize handler returns the drawer abruptly to its closed state. If anyone can improve on this then please feel free. Hopefully it will be useful for others.

PS. I'm now going to try and achieve the same thing using animationEngine.

andyt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 15
Joined: Mon Mar 08, 2010 10:41 am

Re: Trying to create a slide up drawer in stack

Post by andyt » Wed Jun 03, 2015 11:57 am

Okay, this isn't exactly working 100% of the time. I have successfully built a sliding draw now using animationEngine and I can create a static group and make it respond perfectly to stack resizing. The problem is when I combine the two.

After the window resizing has taken place sometimes the drawer group doesn't respond to the 'set rect' command in the resize handler or the mouse over stops working. Either can be fixed by making another resize attempt or two, or three often with the ugly effect that the drawer opens on mouse over and grows to the size set in the resize handler.

I'm using the glx framework and my code is as follows:

In the program stack:

Code: Select all

on PreOpenWindow pHasBeenOpened
   ## EQUIVALENT TO preOpenStack BUT WITH A PARAMETER LETTING YOU KNOW
   ## IF WINDOW HAS BEEN OPENED DURING THE APPLICATION SESSION.
   set the width of me to 900
   set the height of me to 600
   set the loc of me to the screenLoc
   put the width of this card into cardW
   put the height of this card into cardH
   set the rect of group "slideMenu" to 0, cardH-10, cardW, cardH+240
   set the width of graphic "slideMenuBkg" to cardW
   set the loc of graphic "slideMenuBkg" to the loc of group "slideMenu"
   set the lockLoc of group "slideMenu" to true
   set the lockLoc of graphic "slideMenuBkg" to true
   --initialize the slideMenu global to false
   put false into gExitingMenu
end PreOpenWindow


In the card script:

Code: Select all

on ResizeView pWidth, pHeight, pOldWidth, pOldHeight
   ## EQUIVALENT TO resizeStack BUT SENT WHENEVER RESIZING OF CONTROLS MIGHT
   ## BE NECESSARY SUCH AS WHEN NAVIGATING BETWEEN CARDS IN A STACK
   ## THAT IS ALREADY OPEN
   set the rect of group "slideMenu" to 0, pHeight-10, pWidth, pHeight+240
   set the width of graphic "slideMenuBkg" to the width of group "slideMenu"
end ResizeView
It is as if the resizeView handler isn't always triggering but I can't explain the mouse over breaking.

Any clues anyone?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”