measure text relative to object command

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

Locked
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

measure text relative to object command

Post by monte » Tue Aug 13, 2013 4:08 am

I like the idea of a measure text command like I see in the widget code. Are you happy for me to expose this? What it would mean is we wouldn't need to put text into fields to find out the size it needs so I think it would be good for long list and tree management. What I'm proposing is we use relative to object to get the effective font attributes from the object:

Code: Select all

measure [unicode] text theText relative to objectReference
it would be set to a width,height size.

Any thoughts?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: measure text relative to object command

Post by LCMark » Tue Aug 13, 2013 1:11 pm

I think something along these lines would be useful - although I do perhaps think it should be a function in the current syntax (the reason its a command in the widgets branch is because the mechanism the widget commands I added use cannot do functions!). How about:

Code: Select all

   measureText(<text>, <object>, [ <mode> ])
   measureUnicodeText(<text>, <object>, [ <mode> ])
Here I propose <mode> to be:
  • width - the default if not specified - returns just the width of the text
  • size - returns the "width of text,ascent+descent"
  • bounds - returns "0,-ascent,width of text,descent"
The reason for the 'mode' is that in some cases all you need is the width, in others the width and height but there are cases where you also need the ascent / descent (if you wish to align text of different fonts and sizes next to each other).

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: measure text relative to object command

Post by monte » Tue Aug 13, 2013 9:30 pm

OK, I'll take a look at it.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: measure text relative to object command

Post by monte » Wed Aug 14, 2013 9:56 pm

I'm just about done with this... just writing up some docs now but wanted to check if there's any times other than the object not being open where the fontref will be nil? I'm throwing an object not open error if it's nil.

Also I wanted to point out that the practice of including a number in the error definition means that whoever is doing the merges will always need to check both error files to ensure those numbers remain sequential even if it merges cleanly... ah... merges and sequential numbers... reminds me of something ;-)

If the comments on each error are parsed then included in the IDE then the comments on each error become redundant. Or perhaps the error description should be included in the engine so we can implement error handling in standalones better?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: measure text relative to object command

Post by monte » Wed Aug 14, 2013 11:00 pm

OK here's the pull request if anyone's interested:
https://github.com/runrev/livecode/pull/129

It appears the comments on the errors are already being parsed so I think it's just the numbers that should be dropped because they are redundant.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: measure text relative to object command

Post by LCMark » Thu Aug 15, 2013 11:59 am

Also I wanted to point out that the practice of including a number in the error definition means that whoever is doing the merges will always need to check both error files to ensure those numbers remain sequential even if it merges cleanly... ah... merges and sequential numbers... reminds me of something ;-)
Yup - it does.
It appears the comments on the errors are already being parsed so I think it's just the numbers that should be dropped because they are redundant.
They aren't redundant - an error once defined has a unique number which cannot change (some error codes are checked in the IDE, for example) in the current model of error handling. The reason for including them in the error's file is so that there is a direct reference for which error number is which error, and also to ensure that it isn't possible to accidentally change the error numbers.

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

Re: measure text relative to object command

Post by LCMark » Wed Sep 11, 2013 2:15 pm

@monte: I merged in this into develop a while ago - it will appear in 6.5-dp-1 which we're hoping to get out asap.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: measure text relative to object command

Post by monte » Thu Sep 12, 2013 12:49 am

OK, would be good if we knew version numbers for the next release branch off develop for feature contributions so you didn't need to change our docs. Given the big jump can I assume it includes the graphics stuff?
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Locked

Return to “Engine Contributors”