Sizing window question

  • I'm just learning the cocoa api's and have a couple of newbie
    questions that I did not readily find in the docs:

    Question 1:
      - I have a window, with a custom view.  I get the window from a nib
    and can draw into the view, all good so far.  The question is this,
    it's not until runtime that I know the size of the content.  I figured
    out that I can resize the window with [aWindow frame], but I'm not
    sure how to properly calculate the window size, so that the view fits
    my content.

    i.e. Let's say I get the window, open my data file and I see I need a
    view area of 120x120.  The custom view needs to be 120x120.  How do
    you figure out the appropriate window size?

    Question 2:
    - When I'm resizing the window, how do you figure out the desktop
    size, so that you don't make a window that is too big and goes
    offscreen.

    Thanks for your time,

    -john
  • Hi there my name is Phil,

    I am a newbie myself so I know how you feel. I can't answer your
    first question but I can help on the second one.

    Open the Documentation and search for NSScreen. It has a method that
    returns the size of the screen in dpi or by the point system so that
    you can obtain it for your app. It doesn't get the information until
    it runs, (obviously), so you can use your app on any size screen.

    I hope this helps.

    Phil

    On 20 Jan 2008, at 16:47, John Newlin wrote:

    > I'm just learning the cocoa api's and have a couple of newbie
    > questions that I did not readily find in the docs:
    >
    >
    > Question 1:
    > - I have a window, with a custom view.  I get the window from a
    > nib and can draw into the view, all good so far.  The question is
    > this, it's not until runtime that I know the size of the content.
    > I figured out that I can resize the window with [aWindow frame],
    > but I'm not sure how to properly calculate the window size, so that
    > the view fits my content.
    >
    > i.e. Let's say I get the window, open my data file and I see I need
    > a view area of 120x120.  The custom view needs to be 120x120.  How
    > do you figure out the appropriate window size?
    >
    >
    > Question 2:
    > - When I'm resizing the window, how do you figure out the desktop
    > size, so that you don't make a window that is too big and goes
    > offscreen.
    >
    > Thanks for your time,
    >
    > -john
  • Hey John -

    I think you're looking for -[NSWindow frameRectForContentRect:].

    Good Luck -
    Jon Hess

    On Jan 20, 2008, at 8:47 AM, John Newlin wrote:

    > I'm just learning the cocoa api's and have a couple of newbie
    > questions that I did not readily find in the docs:
    >
    >
    > Question 1:
    > - I have a window, with a custom view.  I get the window from a nib
    > and can draw into the view, all good so far.  The question is this,
    > it's not until runtime that I know the size of the content.  I
    > figured out that I can resize the window with [aWindow frame], but
    > I'm not sure how to properly calculate the window size, so that the
    > view fits my content.
    >
    > i.e. Let's say I get the window, open my data file and I see I need
    > a view area of 120x120.  The custom view needs to be 120x120.  How
    > do you figure out the appropriate window size?
    >
    >
    > Question 2:
    > - When I'm resizing the window, how do you figure out the desktop
    > size, so that you don't make a window that is too big and goes
    > offscreen.
    >
    > Thanks for your time,
    >
    > -john
  • Hi John,

    On 20.01.2008, at 17:47, John Newlin wrote:

    > I'm just learning the cocoa api's and have a couple of newbie
    > questions that I did not readily find in the docs:
    >
    >
    > Question 1:
    > - I have a window, with a custom view.  I get the window from a nib
    > and can draw into the view, all good so far.  The question is this,
    > it's not until runtime that I know the size of the content.

    if you started with an cocoa application project, use "awakeFromNib“
    to get informed after the nib was loaded, if you started from a
    document-based project use "windowControllerDidLoadNib".

    > I figured out that I can resize the window with [aWindow frame],

    thats wrong. this method is a getter. use "setFrame:display:" or
    "setFrame:display:animate:" to set a new size and origin.

    > but I'm not sure how to properly calculate the window size, so that
    > the view fits my content.

    NSMakeRect(...)

    > i.e. Let's say I get the window, open my data file and I see I need
    > a view area of 120x120.  The custom view needs to be 120x120.  How
    > do you figure out the appropriate window size?
    >
    >
    > Question 2:
    > - When I'm resizing the window, how do you figure out the desktop
    > size, so that you don't make a window that is too big and goes
    > offscreen.

    every NSWindow object has a "screen“ getter, that returns the NSScreen
    object representing the screen it is drawn on.

    >
    > Thanks for your time,

    i suggest: read the documentation.

    >
    > -john
    >
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today