Clipping/cropping a group

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Clipping/cropping a group

Post by Klaus » Fri Oct 11, 2024 2:45 pm

Hi friends,

I want to clip a group by script but cannot get it to work!?
I want the content of the group to be clipped at the top and bottom.
See attached image, it shows what I want to achieve.

No problem when resizing manually but no dice by script so far.
I tried many variations of boundingrect, rect, clipstorect, lockloc, height and whatnot.

Any hints very welcome! :-)

Best

Klaus
Attachments
group_clipping.png

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Clipping/cropping a group

Post by dunbarx » Fri Oct 11, 2024 2:53 pm

Klaus.

If I make a group and set its height property to a value smaller than the original, the top of the group stays put, and the bottom is truncated, so that is half the battle. If I then play with the scroll of the group, I can control the visible portion.

Craig

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Clipping/cropping a group

Post by Klaus » Fri Oct 11, 2024 2:56 pm

Yes, but I don't want to "play with the scroll" I want to script it precisely. :D
But thank you, gives me food for thought!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Clipping/cropping a group

Post by dunbarx » Fri Oct 11, 2024 3:00 pm

Klaus.

I only "played" with setting the scroll to see if that property worked as I thought it might. I am sure you can figure out the numerical values of the scroll to make your group look the way you want.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10115
Joined: Fri Feb 19, 2010 10:17 am

Re: Clipping/cropping a group

Post by richmond62 » Fri Oct 11, 2024 4:36 pm

Your problem is that you do NOT really want to JUST resize the group: but you want to resize the group AND centre its contents.

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Clipping/cropping a group

Post by Klaus » Fri Oct 11, 2024 5:19 pm

How did you know? :D

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10115
Joined: Fri Feb 19, 2010 10:17 am

Re: Clipping/cropping a group

Post by richmond62 » Fri Oct 11, 2024 5:45 pm

Because I just spent an hour getting FFFFed trying to get the thing to work:

Tried: crop

Tried: set the rectangle of group

Tried: a glass of whisky on the balcony . . .

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10115
Joined: Fri Feb 19, 2010 10:17 am

Re: Clipping/cropping a group

Post by richmond62 » Fri Oct 11, 2024 5:50 pm

Something tells me (probably the whisky) that you need a group inside another group and you have to shift the inner group UP before you resize the outer group.

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Clipping/cropping a group

Post by Klaus » Fri Oct 11, 2024 6:06 pm

I will either set the TOP and BOTTOM MARGINS of that group to negative values or, as Craig proposed,
just resize the group and set the scroll accordingly.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Clipping/cropping a group

Post by dunbarx » Fri Oct 11, 2024 6:51 pm

All good stuff.

To center a group the scroll way, simply determine the amount of total "crop" you want in pixels. Subtract half that value from the height of the group . Then set the scroll to that same value.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Clipping/cropping a group

Post by dunbarx » Fri Oct 11, 2024 6:57 pm

How would one do the same sort of thing horizontally?
There you really need to set the margins to a string of positive and negative values.

Playing with it, actually, I like the margin method best...

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Clipping/cropping a group

Post by bn » Fri Oct 11, 2024 7:56 pm

I tried to do what Klaus seems to be aiming at.

I tried this and think that gathering the location of the controls of the group before resizing the group (which is locLocked) and then setting the location of the controls to their prior location after the resize of the group seems to do the trick.

Maybe this helps or I do not quite understand what Klaus wants.

Kind regards
Bernd

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Clipping/cropping a group

Post by Klaus » Fri Oct 11, 2024 8:03 pm

Hi Bernd,

sounds good, will try this tomorrow!
I think you understood what I'm after. :-)

Best

Klaus

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Clipping/cropping a group

Post by Klaus » Sat Oct 12, 2024 3:21 pm

Hi Bernd,

tried that, but didn't work, since setting the height will not change the topleft of the group.


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Clipping/cropping a group

Post by dunbarx » Sat Oct 12, 2024 3:34 pm

Now I am confused.

1- What do the locs of the child controls have to do with cropping the group as a whole?

2- Isn't the margins property the best way to crop, since all four sides can be independently adjusted?

My first foray into this was based on Klaus' initial post, where only the top and bottom were adjusted. I assumed that the controls within did not matter. But my solution is not nearly as elegant and simple as using margins.

Craig

Post Reply