• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Programmatic "Size To Fit"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programmatic "Size To Fit"


  • Subject: Re: Programmatic "Size To Fit"
  • From: RICKY SHARP <email@hidden>
  • Date: Thu, 01 May 2008 11:53:04 -0700

 On Thursday, May 01, 2008, at 01:14PM, "John Stiles" <email@hidden> wrote:
>An NSView doesn't have an associated cell, so "size to fit" doesn't
>really have a meaningful answer. Size-to-fit works by asking the cell
>what size it should be.
>
>For a box, you could just enumerate the subviews and get the union of
>all the subview frames.
>
>Randall Meadows wrote:
>> On May 1, 2008, at 11:45 AM, Martin wrote:
>>> What about NSControl's sizeToFit method?
>>
>> I guess I didn't mean "controls" exclusively; I should have stuck with
>> "views", as (at least) one of the things I need to create is an NSBox
>> that contains multiple controls.  Which is why I was looking in NSView
>> for the right call.  But yeah, that'll work for the majority of things
>> I need to create.
>>
>> And now that I think about it....I don't really need (nor want) for
>> the box to have a border, so perhaps I can manipulate it just
>> encompass the sized-to-fit controls in it.  But still, is there no
>> such beast for NSViews?
>>
>> While I'm at it...is there no way to create an NSMatrix of
>> NSPopupButtons?  I can't seem to manage it in IB, and I'm not yet at
>> the point to try it in my code.
>>
>>> Martin
>>>
>>> On May 1, 2008, at 7:39 PM, Randall Meadows wrote:
>>>
>>>> I am creating a bunch of controls (at least NSTextfield,
>>>> NSPopupButton, NSSlider, and perhaps others) programmatically (that
>>>> will eventually be shown in an NSTableView), and would like to apply
>>>> the "Size To Fit" feature that IB provides.  However, there doesn't
>>>> seem to be any API that does that.
>>>>
>>>> Does IB simply brute-force the resizing for every type of view, or
>>>> am I missing the appropriate call in the NSView API?

Just to throw this out there to...

IB's size-to-fit function is still very much a mystery.  For all my IB palettes (IB 2.x) and plug-ins (IB 3.x), I added a custom mySizeToFit method for most of my controls.  Then, the inspector had a button that would invoke that method.  As much as possible, it would rely on framework routines such as cellSize to return an appropriate size for each cell.

Multi-cell controls would of course need to do a proper union and optionally space things out too.  At the end of the method, I would then do a setFrame (or was that setSize?)

Anyhow, I found it really weird that IB's size to fit menu never would invoke sizeToFit in code.  breakpoints and logging lines never were hit.  There's still a bit of IB magic going on where I think IB will only do work for specific classes.

The other nice thing of your own sizeToFit methods is that you could then add it to your view classes too.  I would recommend perhaps a protocol you could mix in to all your views/controls that needed such an API.  And, if you're doing IB palettes/plug-ins, you'd have something you could tap into as well.

--
Rick Sharp
Instant Interactive(tm)


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Programmatic "Size To Fit" (From: Randall Meadows <email@hidden>)
 >Re: Programmatic "Size To Fit" (From: Martin <email@hidden>)
 >Re: Programmatic "Size To Fit" (From: Randall Meadows <email@hidden>)
 >Re: Programmatic "Size To Fit" (From: John Stiles <email@hidden>)

  • Prev by Date: Re: trouble debugging input method remotely
  • Next by Date: Cocoa Developer Needed
  • Previous by thread: Re: Programmatic "Size To Fit"
  • Next by thread: Re: Programmatic "Size To Fit"
  • Index(es):
    • Date
    • Thread