Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

why would text.contentHeight differ from text.height?
Started by sieler2 Oct 04 2018 04:40 PM

6 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Enthusiast

  • 87 posts
  • Corona SDK

Hi,

 

I'm doing:

 

    tdummy = display.newText ("Edit", 100, 100, native.systemFont, 40)

 

    print (tdummy.contentHeight, tdummy.height)

 

and am seeing tdummy.contentHeight is 48, and tdummy.height is 48.009376525879

 

 

...and am wondering why the difference!

 

thanks,

 

Stan (still desperately wanting a modern Lua in Corona) Sieler



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,969 posts
  • Corona Staff

It's explained in the documentation: http://docs.coronalabs.com/api/type/DisplayObject/contentHeight.html

 

"This is similar to object.height except that its value is affected by y scaling and rotation."

 

Rob



[TOPIC: post.html]
#3

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Enthusiast

  • 87 posts
  • Corona SDK

thanks. 

 

I wish the documentation made it clear which value corresponded to the values one would provide back to Corona via some API call.  

 

I.e., if I'm trying to create some object of the same on-screen/visible height, do I get the info from .height or .contentHeight?  Since the values differ, the answer is clearly one or the other (or, possibly, "neither, use <somethingelse>" :)

 

The entire question arose because a prior post (someone else) asked about determining the size of a widget.newButton,

and the answer was to use .height or .contentHeight of a temporary text object with the same font size  ...  had such buttons

possessed the same x/y/height attributes as display objects, the question wouldn't have arisen, I suspect.

 

thanks.

 

Stan



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,363 posts
  • Corona SDK

Best Practice: I use obj.contentHeight and obj.contentWidth almost exclusively.


  • sieler2 likes this

[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,969 posts
  • Corona Staff

widget.newButton()s are not directly display objects. They are an object that contains a display.newGroup that holds a display.newRect and some other display objects. I don't believe that widget.newButton has a direct .height or .width property 

 

In most cases, I think .height and .contentHeight are going to be the same or very close unless you've been scaling or rotating the object. I would personally use .height in most cases.

 

Rob


  • sieler2 likes this

[TOPIC: post.html]
#6

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Enthusiast

  • 87 posts
  • Corona SDK

Thanks, Rob.

 

I figured something like that (nested stuff), but decided against looking inside one to get to the nested objects ... not enough reason to get dirty like that for this minor problem.

 

I'm currently using the min of the two, rounded to an integer value.

 

thanks again,

 

Stan (sure wish we had modern Lua with "//" integer division) Sieler



[TOPIC: post.html]
#7

sieler2

[GLOBAL: userInfoPane.html]
sieler2
  • Enthusiast

  • 87 posts
  • Corona SDK

@roaminggamer thanks ... given the one you suggest is an integer (in my test case), it seems reasonable to think it's closer to the pixel values I want.

 

SS




[topic_controls]
[/topic_controls]