get label text width/height

BlitzMax Forums/MaxGUI Module/get label text width/height

skn3(Posted 2011) [#1]
[updated 10/11/2011]
I have made a small piece of code to allow exact sizing of gadgets based on the string dimensions. For example if you needed to figure out the proper dimensions for a label gadget width and height then the code below would let you determine what dimensions you should use.

Here is a screenshot of it working in the app Objecty I am writing ( http://www.skn3.com/apps/objecty ). The two label gadgets you see are dynamically created. You will notice that the labels/gadgets are all neatly centred in the dialogue window. HOORAH!



Just to point out, the function does not return the exact size of just the text. It will return the size it thinks the gadget itself should be.

[update - 10/11/2011]
Fixed issue jsp reported that the dimensions produced were a bit funky on his copy of winxp. This is resolved, and have also added in a special case dimension checking for buttons (windows only). It should take into account the buttons picture as well.

Here is the code you will need:
mods/skn3.mod/gadgetstringdimensions.mod/gadgetstringdimensions.bmx


mods/skn3.mod/gadgetstringdimensions.mod/gadgetstringdimensions.h (mac)


mods/skn3.mod/gadgetstringdimensions.mod/gadgetstringdimensions.m (mac)


Here is an example of the code working


Last edited 2011


skn3(Posted 2011) [#2]
update, see first post

Last edited 2011


shinkiro1(Posted 2011) [#3]
Hey thanks, that's a feature I often wanted to use. Would be great if it has a mac version too.


skn3(Posted 2011) [#4]
Having a look at this today for mac. Fingers crossed it goes well!


skn3(Posted 2011) [#5]
Well I got a mac version running :D (See first post for the files needed)

This was my first blitz -> osx module, an exciting little project.

Last edited 2011


jsp(Posted 2011) [#6]
Tested this on XP and the space between the Label and the Button is growing the longer the string displayed gets. Somehow the offset seems a bit too big.
Nevertheless this is really useful, didn't know it exist!
Thanks.


skn3(Posted 2011) [#7]
I'll get XP installed on a vm and fix it tomorrow :D thanks for testing!


skn3(Posted 2011) [#8]
Hey jsp, I got xp installed today (thanks btw I had been meaning to do it) and tested the example from the first post. I wasn't able to get any size issues with the label gadget. They seemed to fit the exact size in normal and xpmanifest modes!

Is there anything special with your xp installation? Would it be possible to take a screenshot? Thanks


jsp(Posted 2011) [#9]
See below what I mean. The more lines the bigger the distance between the label and the button.
It looks a bit like a wrong fontsize calculation, but I saw you retrieve the font from the control. Not sure what goes wrong here.
My XP is quite standard, but is running in a VMWare to be more flexible, never had a problem with that. The biggest difference is that it uses GL instead of DX, but that should have no effect for the GUI.




skn3(Posted 2011) [#10]
Hey Jsp,

Thats really weird. I tried again on my XP (also running on vmware) and it doesn't exhibit the same behaviour.

Could you try this new version for me please?
Changed:
- I renamed the function as it didnt really make sense.
- I added in more code for correctly determining button dimensions (including images) in windows.
- I added a DT_NOCLIP flag to the text calc for "other" gadgets
- I changed the hwnd to be QUERY_HWND instead of QUERY_HWND_CLIENT



Last edited 2011


jsp(Posted 2011) [#11]
Cool, that did the trick, works perfect now!
Thanks


skn3(Posted 2011) [#12]
W00t! thanks for the help in testing. I have now updated the topic.