discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaissance: bad layout with dynamic title


From: Michael Ash
Subject: Re: Renaissance: bad layout with dynamic title
Date: Sat, 29 Mar 2008 07:59:30 -0500
User-agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE-p20 (i386))

Nicola Pero <nicola.pero@meta-innovation.com> wrote:
> Yes - the title gets set when the connections are done, which is  
> after all objects
> have been created, autosized and put in place.  So I'd expect that  
> the title does
> get changed, but the button's size is still the same as the one it  
> had before the
> title was set - the new title would then fall outside the frame and  
> be clipped,
> so you don't see it. ;-)
> 
> You can easily confirm it by hardcoding the width of the button:
> 
>  <button ... width="200" />
> 
> and you should see now the title appearing ;-)

Right, I tried something similar and assumed that was the problem.

>> I've tried many variations on this theme. I've tried setting the  
>> title to
>> a placeholder, then dynamically updating the title in code (result:
>> everything is sized for the original title), I've tried calling
>> sizeToFitContent on the vbox and the button (result: no change),  
>> removing
>> and re-adding the button to its superview (result: no change), I've  
>> tried
>> using an hbox (no change), an NSBox (naked checkbox in the middle of a
>> reasonably wide box), and nothing seems to get the result I want.
>> It seems like the layout is getting somehow baked into the view  
>> hierarchy
>> early on, and I need to prod it into updating but I don't know how  
>> to do
>> that.
> 
> Yes - you would need to redo the layout "bottom-to-top".  I have various
> unfinished experiments with designing a good API for that.
> 
> But you can already do it programmatically using the stable API for  
> autolayout
> and the boxes.
> 
> Here's how you can do it:
> 
>  [* change the button title]
> 
>  * call -sizeToFitContent on the button
> 
>  * get the new button's size
> 
>  * call -setMinimumSize:forView: on the vbox to tell it that the  
> button has a new minimum size
> 
>  * call -sizeToFitContent on the vbox
> 
> I added on Renaissance's subversion trunk the worked out code as an  
> example - you find it
> in Examples/Special/AutoLayoutUpdate. :-)

Excellent. I just tried this and it works as promised. It was the 
-setMinimumSize:forView: step which I was missing; I had assumed that 
-sizeToFitContent on the vbox would see the new button size automatically, 
but obviously that's not how it actually works.

As for the API, take these with an enormous grain of salt since I'm new to 
Renaissance and I could just be crazy:

- Some sort of -updateLayout method which just calls -sizeToFitContent and 
-setMinimumSize:forView: recursively would make the solution fairly 
obvious.

- If layout can be delayed until after connections are made then it will 
at least solve this one problem, although not the general problem of 
redoing layout after things change.

- The insane solution: have all views whose size depends on subviews watch 
those subviews for frame-changed notifications and automatically relayout 
when they happen. Maybe it could be optional.

Anyway, these are just some ideas. Your solution works great for me and is 
all I need for now. Thanks so much for your help.

-- 
Michael Ash
Rogue Amoeba Software


reply via email to

[Prev in Thread] Current Thread [Next in Thread]