wxStaticText wrapping (was: Something for GSoC2008?)

ATS asteinarson at gmail.com
Fri Mar 7 15:03:43 PST 2008


> A> Using the function InformFirstDirection(...). All sizers call it when 
> A> the first size component has been determined. Based on discussions in 
> A> this list I also added this function to wxWindow.
> 
>  Ah, of course, sorry, I forgot about this method in wxWindow. So it looks
> like wxStaticText should just override this and cache the width passed to
> it and invalidate its best size if it's different from the old width. And
> its DoGetBestSize() should wrap words according to the cached width if it's
> valid. Right?

Yes, there will be the same CalcMinSize() and Layout() cycles for 
wxStaticText, only it doesn't use any sizer. 

But I have to emphasize that it wasn't easy to get the wxWrapSizer 
(at SF patch tracker) to operate well. 

wxWrapSizer::GetMinSize() means slightly different things depending 
on the context it's called in. Immediately after InformFirstDirection()
it will answer with a min size that tries to use as much as possible of 
the just determined first size component. 

Called under other circumstances, it answers based on it's current line
layout. 

Another (related) aspect is that it has to be able to 're-acquire' lines 
that it has previously given away (going from a few long lines to more 
short lines). A user may resize a dialog to be very wide or very high.


> A> wxStaticText::GetMinSize() cannot just return fixed cached values. It has
> A> to work together with InformFirstDirection(...) in a rather tight way.
> 
>  Do I still miss something that would make it more complicated than what is
> described above?

1 - I think the vertical case is rather important. Consider a layout with 
fix size image to the left:
|----------------------------------|
|   I    |   Text to be wrapped    |
|   M    |   next to an image with |
|   A    |   given vertical size   |
|   GE   |   in a horizontal sizer |
|----------------------------------|

So, We have vert height and really ask for what horz space it needs. 


2 - To get some decent default wrapping position in a piece of text
I think it's good to use some markup: 

   "This is is a long help text. <defaultwrap> Bla bla. More info..."

Otherwise, one can get quite strange layouts with one word per line. 


So I think something that is intuitively useful, reasonably efficient 
and that doesn't stumble on the first corner case, well there's 
some work in it. 


Regards
// ATS. 

> 
>  Thanks,
> VZ
> 








More information about the wx-dev mailing list