[haiku-commits] Re: r41772 - haiku/trunk/src/apps/showimage

  • From: "Ingo Weinhold" <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 27 May 2011 23:01:03 +0200

Axel Dörfler wrote:
> "Ingo Weinhold" <ingo_weinhold@xxxxxx> wrote:
> > axeld@xxxxxxxxxxxxxxxx wrote:
> > > + GetLayout()->Relayout(true);
> > > + // We need to manually relayout here, as the views would be 
> > > relayouted
> > > + // later, and FitToBounds() would still have the wrong size
> > >   fImageView->FitToBounds();
> > ... I suppose a view or window is resized and some descendant is 
> > assumed to
> > already have the newly laid out size. Since the relayout happens 
> > asynchronously
> > that assumption is incorrect. Layout invalidation and relayouting 
> > work analogously
> > to graphics invalidation and redrawing and for the same reasons.
> 
> A window is resized. And the same reasons are because of batching up 
> pending requests?

Yep.

> > BTW, BLayout::Relayout() is not supposed to be called directly. BView 
> > has
> > methods (Layout()/Relayout()) for that purpose, for the window those 
> > are
> > missing yet, though.
> 
> Should I add them, or rather call Layout()->View()->Relayout()?

Please add them, or at least a BWindow::Layout(bool force). Also have a look at 
the B_LAYOUT_WINDOW message handling -- that's what is supposed to happen for 
the force == false case, which is also what you would need in your use case.

> IIRC Relayout() didn't work, but Layout() did (I've tried them all, but 
> thought that calling it on the layout would be nicer, since you are not 
> really supposed to mess with the top view).

Since each view manages its layout state, calling those methods directly on the 
layout lets the state get out of sync. E.g. in your case the window will still 
do the asynchronous layout run, which should get things in sync again (though 
I'd rather avoid that in the first place).

> Would really be great to 
> have some documentation for this 8-)

Indeed. Ironically I always have to look at the source myself to understand 
what BView::Relayout() does. BView::Layout() is fairly straight-forward: It 
does the layout, if necessary, or always for force == true. Relayout(), 
however, does something only, when the layout is currently *valid* (it 
invalidates the layout and redoes the layout). This sounds rather weird, but 
seeing that it is used in several places in the interface kit, I guess I found 
it useful to have. The layout invalidation and recomputation needed a lot of 
tinkering to get it right (which I hope it is now), as several special cases 
reared their ugly heads and needed dealing with. This code should really be 
reviewed, understood, and documented before we declare the API public.

CU, Ingo

Other related posts: