Message Sent When Resizing a Widget?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
netdzynr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Sat Apr 08, 2006 6:04 am
Contact:

Message Sent When Resizing a Widget?

Post by netdzynr » Fri Mar 13, 2015 9:36 pm

During Kevin's Unconference presentation, I was almost positive he mentioned an resize message that was sent when changing the dimensions of a widget, but I can't seem to find any entry for this in the docs. Does OnPaint take care of this or is there specific resize message?

Related: How do I determine the center of a widget's canvas while it is being resized? There doesn't seem to be any "center" or "loc" property so do I have to continually test the width/height of the canvas during OnPaint or is there a better way?

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: Message Sent When Resizing a Widget?

Post by LCMark » Fri Mar 13, 2015 9:45 pm

@netdzynr: When a widget's rect changes you get an OnGeometryChanged event - you can handle that to recompute anything you need to based on the size.

The OnPaint event is only sent when the widget has asked to be redrawn - but since changing the rect of the widget implicitly causes a redraw at the moment you'll get one when the rect changes anyway. (Well, this isn't strictly true - I need to double-check - if you are running in accelerated rendering mode, in theory you'll only get an OnPaint when you've explicitly requested a redraw, and indeed, this is how it should be from the point of view 'always do the minimum work').

There isn't any 'center' or 'loc' property - so you need to calculate the center point yourself by using my width / 2 (or my height / 2). An important point to note here is that widget rendering is set up so that co-ordinates are always relative to the top-left of the widget rather than the card. This is important as it means we can (in the future) support a transform property for all widgets.

One thing to remember is that, depending on what you are doing, you might not need to do account for a 'center shift' throughout your rendering code. The canvas syntax supports the standard 'transformation matrix' stack you see in all 2D vector APIs. So, if you want to draw things around the center of your widget, you can just start off your OnPaint handler with:

Code: Select all

translate this canvas by [ my width / 2, my height / 2 ]
After this point all co-ordinates will be relative to the center of the widget - the center of the widget will have co-ordinates (0,0).

The clock widget makes a lot of use of the transformation stack to simply implement the rotation needed by the hands - it might be worth you taking a look at the source (you can get at it from within the extensions manager after installing it from the store).

netdzynr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Sat Apr 08, 2006 6:04 am
Contact:

Re: Message Sent When Resizing a Widget?

Post by netdzynr » Fri Mar 13, 2015 10:06 pm

Thanks for the insight @LCmark. I believe OnGeometryChanged was the message, and translate seems like it will save a lot of time.

Post Reply

Return to “LiveCode Builder”