Determining the size of rendered widgets
Added by Anonymous over 14 years ago
Hi All,
There is not provision to determine the actual rendered size of widgets and no server-side event emitted when widget's size changes. I have a situation where I really need to know the size of an image as rendered in a browser, but can not get this information - perhaps you can offer some advice as to how I might achieve the following.
I am using OpenGL to render a scene off-screen and then setting the result of rendering into a WImage (using a WResouce for the dynamically generated content). The size of the image is under user control as I use a WHBoxLayout with with draggable boarders. To clarify the layout, I've attached a screen shot - the triangle is rendered with OpenGL on the server side. Resizing the browser or dragging the border affect the rendered image size.
Ideally I would be able to determine the image size as displayed to the user and render the scene to a buffer of the same size on the server. However, I can not determine the actual size of the image.
Any suggestions? Is this something that could be added to Wt in the future? I would be happy at the moment with a WImage specific solution!
Cheers,
Dan
capture2.png (251 KB) capture2.png |
Replies (5)
RE: Determining the size of rendered widgets - Added by Koen Deforche over 14 years ago
Hey Dan,
I think the following methods do what you are looking for:
WWidget::setLayoutSizeAware()
WWidget::layoutSizeChanged()
Regards,
koen
RE: Determining the size of rendered widgets - Added by Anonymous over 14 years ago
Ahhh! I missed that in the doco. I was expecting to find a signal that was emitted when the size changes. Since I am subclassing the WImage anyway, a virtual function will get the job done.
Thanks!
Dan
RE: Determining the size of rendered widgets - Added by Anonymous over 14 years ago
I'm having a little trouble with IE8 (Firefox, Chrome and Opera are all being well behaved).
I have the following simple case:
class MyImage : public Wt::WImage
{
public:
MyImage(const std::string &imageRef, Wt::WContainerWidget *parent=0) : Wt::WImage( imageRef, parent )
{
setLayoutSizeAware( true );
}
virtual void layoutSizeChanged( int w, int h )
{
std::cout << "*** The image size changed to: " << w << ", " << h << "\n";
}
};
WApplication *app = new WApplication( appCspace_, env );
// use a VBox layout so that the app stretches to fill the window
Wt::WVBoxLayout *topLevelLayout = new Wt::WVBoxLayout(app->root());
topLevelLayout->setContentsMargins( 0, 0, 0, 0 );
// create my derived image that reports the size that it gets set to when laid out
Wt::WWidget* view = new MyImage( "http://www.google.com/images/logos/ps_logo2.png", app->root() );
// The resize( 100%, 100% ) was required to get the image to not maintain aspect ratio when resizing.
view->resize( Wt::WLength( 100.0, Wt::WLength::Percentage ), Wt::WLength( 100.0, Wt::WLength::Percentage ) );
topLevelLayout->addWidget( view, Wt::AlignTop | Wt::AlignLeft );
In IE8 there are two problems:
- If you change the browser window height only, the image does not resize. Changing the width makes it honor the height of the browser window.
- The image will not resize narrower than the actual image width - the browser clips the image instead and layoutSizeChanged() is not invoked.
I could live with (1) as a quirk, but (2) really stops me from being able to get the layout that I desire. Any suggestions? I'm using the git version of Wt.
Cheers,
Dan
RE: Determining the size of rendered widgets - Added by Koen Deforche over 14 years ago
Hey Dan,
(1) has been fixed in latest git.
for (2), you need to take the widget out of the CSS flow. I am starting to think that perhaps the layout managers could safely do this themselves, but until I have found an answer to that (by trial and error, as that is the start of the art of CSS :-) ), you can enable this for yourself using:
MyImage(const std::string &imageRef, Wt::WContainerWidget *parent=0) : Wt::WImage( imageRef, parent )
{
setPositionScheme(Absolute);
setLayoutSizeAware( true );
}
RE: Determining the size of rendered widgets - Added by Anonymous over 14 years ago
Hi Koen,
Calling setPositionScheme(Absolute) has fixed the IE8. I don't envy you trying to get this to work consistently across all the browsers!
Thanks,
Dan