Your Digital Media Has Never Looked So Good

 
User avatar
OG_OTT
Topic Author
Posts: 13
Joined: Mon Jul 30, 2018 3:52 pm

Get Poster/image dimensions

Thu Aug 02, 2018 10:48 pm

I have created my own component by extending "group".  I have an image that I put into this group, and I want my brs to capture the width/height of that element so I can start to calculate where to place other components (like Labels) around it... but when I try to do this, I always get widths/heights of '0'.    

As such, I have found that if I set an observer on the "loadStatus" and wait until it is ready, I can get the bitmap dimensions.  This sounds like a great idea!  Now, once I know the image size I can make all the adjustments I need (at least for my situation).

Question:  Is this typical or the 'correct' pattern I should be following?  Or in RSG, is there an alternative way to set 'relative layout' around an image?
 
joetesta
Posts: 762
Joined: Wed Apr 20, 2011 11:48 am

Re: Get Poster/image dimensions

Fri Aug 03, 2018 7:26 am

One way to get the on-screen dimensions of a node is to use https://sdkdocs.roku.com/display/sdkdoc/ifSGNodeBoundingRect#ifSGNodeBoundingRect-boundingRect() node.boundingRect().width and node.boundingRect().height
aspiring
 
User avatar
OG_OTT
Topic Author
Posts: 13
Joined: Mon Jul 30, 2018 3:52 pm

Re: Get Poster/image dimensions

Sun Aug 05, 2018 11:06 am

Hmm, I'd have to test it, BUT, I think I already tried that.  The problem being, and I have seen multiple instances of this, when setting up an initial screen and the components haven't been rendered or scaled, the heigh/width is coming back as 0, and I THINK (again, I'd have to explicitly test) the boundingRect() is also coming back as either 0's OR it has the raw dimensions (because it hasn't been scaled yet).  As such, because things have not been rendered and I don't know the final values, I defaulted to the "loadStatus" observer.  

So to be clear, 100% acknowledge your recommendation, and I'll test it out to be 100% certain it does or doesn't work, but this is on screen init() and BEFORE anything is visible to the user/rendered, so I don't think the values (from what I remember when I wrote this a few days ago) were accurately set/ready for me to consume.  

I hope that makes sense - what are your thoughts?

Thanks again JoeTesta - you've been really helpful in answering all of my beginner questions!  You'll be happy to know that I have been more carefully reading the docs - especially those yellow CTA's =P. 
 
joetesta
Posts: 762
Joined: Wed Apr 20, 2011 11:48 am

Re: Get Poster/image dimensions

Sun Aug 05, 2018 5:25 pm

As long as the component is defined in xml, boundingRect() works correctly in the component's init()
cheers,
Joe
aspiring

Who is online

Users browsing this forum: No registered users and 4 guests