Professional Web Applications Themes

Centering view in NSScrollview - Mac Programming

Hello, is there meanwhile an easy solution to center a NSView in a NSScrollview? I do not like it that the view is always in the lower left corner of the NSScrollview. Bye Robert....

  1. #1

    Default Centering view in NSScrollview

    Hello,

    is there meanwhile an easy solution to center a NSView in a
    NSScrollview?

    I do not like it that the view is always in the lower left corner of the
    NSScrollview.

    Bye Robert.
    Robert Guest

  2. #2

    Default Re: Centering view in NSScrollview

    Robert W. Kuhn wrote: 

    i suspect you're asking the wrong question. the target NSView should
    always be the same size as its scroll view, minus the space taken by the
    scrollbars. you should have set the target NSView to follow all sides,
    and then make it the same size as the scroll view before you put it in
    there.
    Jhnny Guest

  3. #3

    Default Re: Centering view in NSScrollview

    Jhnny Fvrt wrote:

    First thank you for your answer.
     
    >
    > i suspect you're asking the wrong question.[/ref]

    Maybe.
     

    Then I have a lack of understandig.

    I want to programm an imageview. I cannot use the NSImageView 'cause I
    want to know over which pixel of the image the mouse cursor is.

    Now I want to see the right lower edge of the image if I scroll to right
    lower corner of the view. So I have to set the size of the (in the
    NSScrollview embedded) NSView to the size of the image. Do I? I do not see
    an other solution.

    I cannot find a function like SetScrollSizes in the NSScrollView class.

    Bye - Robert.
    Robert Guest

  4. #4

    Default Re: Centering view in NSScrollview

    In article <404484de$0$12935$arcor-online.net>,
    "Robert W. Kuhn" <de> wrote:
     

    I think I'm doing something like this in my UKDistributedView class.
    Basically, what I do is: If the enclosing scroller's content rectangle
    is bigger than the image size, I make my view as large as the content
    rect. If it is smaller, I pick the image size (separately for each
    direction, of course).

    Then, in my custom view itself, I calculate the rectangle to draw in so
    it is the upper left corner of my view (in the case of
    UKDistributedView, I flip the Y axis of my items' coordinates, but in
    the case of an image you'd just move the rect in the Y direction by the
    difference in heights of content and image rect, which would be easier).

    That should give you the desired result. A more generic approach would
    probably be to create some sort of container view that takes care of all
    this, in which you embed your actual image view. That way, you can later
    re-use it for other views by simply using a different subview.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de <-- get UKDistributedView here
    Uli Guest

  5. #5

    Default Re: Centering view in NSScrollview

    Uli Kusterer <de> wrote:
     

    Okay.
     

    Okay, that's the way I will do it.

    But if this common problem is so difficult to solve then NSScrollview is
    quite useless I think.
    Robert Guest

  6. #6

    Default Re: Centering view in NSScrollview

    Robert W. Kuhn wrote: 

    depends on what you're putting in there. i've only used them to
    surround NSTextViews, and for that it's pretty close to perfect, since
    text views already have all the bells and whistles necessary to make
    them scrollable.

    you've got a situation where you have to do some of the work yourself,
    but i bet there will be hooks that make it fairly painless, if you read
    enough of the docs. one thing you can't fault cocoa for: all its
    constituent parts play nicely together.

    one place to start: read the docs for NSClipView. it's an abstraction
    that interfaces an NSScrollView with its scrolled target.
    Jhnny Guest

  7. #7

    Default Re: Centering view in NSScrollview

    dans l'article 1ga1bw6.n40a8szuwywcN%de, Robert W. Kuhn
    de a crit le 2/03/04 19:12:
     
    >
    > Okay.

    >
    > Okay, that's the way I will do it.
    >
    > But if this common problem is so difficult to solve then NSScrollview is
    > quite useless I think.[/ref]

    First your scrolled view should return true on isFlipped. This solves the
    top to bottom issue.

    As far as centering is concerned, this is not, IMHO, a common problem,
    because most people simply want their content on the top left corners.
    There are 2 ways to work around this:
    - create, as suggested, an embedding view, that has always, at least, the
    size of the scrollable area. In that view, center the NSImageView
    - override the "tile" method of the NSScrollView, so that NSClipView and
    the NSDoentView have the proper size

    Good luck,

    Eric

    Eric Guest

  8. #8

    Default Re: Centering view in NSScrollview

    Eric VERGNAUD <fr> wrote:
     

    But resizing a view so the the scrollers reflect the size of the View is
    IMHO very common.

    Or is this a windows-programmer-way of thinking? There I can set the
    scrollsizes. This makes things very easy.

    One example. A view, an image and a zoom factor.
    You only have to set the scrollsizes to image.width*zoom and
    image.height*zoom.

    Then you draw the image in the rect image.width*zoom and
    image.height*zoom. Easy, isn't it?
    Robert Guest

  9. #9

    Default Re: Centering view in NSScrollview

    dans l'article 1ga1ij4.1kyn2zg1dw8kjkN%de, Robert W. Kuhn
    de a crit le 2/03/04 21:36:
     
    >
    > But resizing a view so the the scrollers reflect the size of the View is
    > IMHO very common.
    >
    > Or is this a windows-programmer-way of thinking? There I can set the
    > scrollsizes. This makes things very easy.
    >
    > One example. A view, an image and a zoom factor.
    > You only have to set the scrollsizes to image.width*zoom and
    > image.height*zoom.
    >
    > Then you draw the image in the rect image.width*zoom and
    > image.height*zoom. Easy, isn't it?[/ref]

    Well that's exactly how you do it with NSScrollView too. You call
    [NSView setFrame] on your doent view
    [[NSScrollView contentView]scrollToPoint:point] on the scroll view (only
    if required)
    [NSScrollView reflectScrolledClipView:[NSScrollView contentView]];


    Eric

    Eric Guest

Similar Threads

  1. Centering
    By analog@logwell.com in forum Web Design
    Replies: 4
    Last Post: June 26th, 03:12 AM
  2. Best way to resize an image in a NSScrollView
    By Loic in forum Mac Programming
    Replies: 5
    Last Post: October 10th, 03:50 PM
  3. Scrolling a NSScrollView to the bottom
    By matt neuburg in forum Mac Programming
    Replies: 3
    Last Post: August 10th, 02:00 PM
  4. NSScrollView for NSTextView scrolls then snaps back
    By Harry Mahoney in forum Mac Programming
    Replies: 0
    Last Post: July 16th, 09:19 PM
  5. Wierd error when going to Design View from HTML view
    By VB Programmer in forum ASP.NET General
    Replies: 1
    Last Post: July 10th, 03:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139