• 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: Gap at top when subclassing NSScroller? (cheat)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Gap at top when subclassing NSScroller? (cheat)


  • Subject: RE: Gap at top when subclassing NSScroller? (cheat)
  • From: Keith Blount <email@hidden>
  • Date: Sat, 26 Feb 2005 10:12:14 -0800 (PST)
  • Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys

Hmm, the only way I can find of getting around this at
the moment is to place my text view in a custom view
that leaves a 5 pixel gap at the top, and then make my
custom view the document view of the scroll view with
my custom scroller - that way, no one knows there is a
5 pixel gap at the top of the scroller, as there is
equal dead space in the document view. As this is for
a full screen mode, this looks fine (as in it's
unnoticable).

It's not ideal though, as it's a hack and uses a
custom view that I shouldn't need. If anyone does have
any suggestions of how I can get rid of the 5 pixel
unusable gap at the top of NSScroller so that I can
draw the scroll knob all the way to the top, I would
be very grateful. I've tried overriding rectForPart:,
drawKnob: and drawRect: in my NSScroller subclass, but
all of them cause very weird drawing problems unless I
stick to super's rectForPart definitions....
(Frustrating, because I know it can be done, as
MacJournal uses a custom scroller in its fullscreen
mode.)

Thanks and all the best,
Keith


--- Original message ---

Hello,

I am attempting to subclass NSScroller for use in a
fullscreen textview/scrollview window, and I want an
old-school square look to it - just a simple black
background with a coloured rectangular knob and the
arrows, the whole thing with no more than two colours
(eg. black background with yellow knob and arrows).

On testing this out, I have achieved exactly what I
want for the most part, except that there is a gap of
a few pixels at the top of the scroller. The
rectangular scroll bar will simply not go all the way
to the top of the scroll slot - it stops a few pixels
short. This is probably to be expected, as if you look
at the defalt OS X NSScroller, there is a gap at the
top that is drawn as a silver "slot" that the blue
curved knob fits snugly into.

My question is, how do I get rid of this gap? It does
not look right when using a rectangular bar instead of
one with rounded ends... I cannot find any methods
that control this - I have tried overriding
rectForPart: to no avail.

Here is my test NSScroller subclass so far:

@implementation MyScroller

// Colour the knob slot black
- (void)drawRect:(NSRect)rect
{
   [[NSColor blackColor] set];
   [NSBezierPath fillRect:[self
rectForPart:NSScrollerKnobSlot]]; //rect];
   [self drawKnob];
   [self drawArrow:NSScrollerIncrementArrow
highlight:NO];
}

// Draws a square green knob
- (void)drawKnob
{
   NSRect knobRect = [self
rectForPart:NSScrollerKnob];
   [[NSColor greenColor] set];
   [NSBezierPath fillRect:knobRect];
}

// Draws two yellow and black boxes where the arrows
should be
- (void)drawArrow:(NSScrollerArrow)arrow
highlight:(BOOL)flag
{
   NSRect arrowRect = [self
rectForPart:NSScrollerIncrementLine];
   [[NSColor yellowColor] set];
   [NSBezierPath fillRect:arrowRect];

   arrowRect.origin.x += 1.0;
   arrowRect.size.width -= 2.0;
   arrowRect.origin.y += 2.0;
   arrowRect.size.height -= 3.0;
   [[NSColor blackColor] set];
   [NSBezierPath fillRect:arrowRect];

   arrowRect = [self
rectForPart:NSScrollerDecrementLine];
   [[NSColor yellowColor] set];
   [NSBezierPath fillRect:arrowRect];

   arrowRect.origin.x += 1.0;
   arrowRect.size.width -= 2.0;
   arrowRect.origin.y += 1.0;
   arrowRect.size.height -= 1.0;
   [[NSColor blackColor] set];
   [NSBezierPath fillRect:arrowRect];
}

@end

Many thanks for any help or suggestions,
Keith



__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: NSTableView opacity problem
  • Next by Date: unicode character for action pull-down
  • Previous by thread: Re: NSTableView opacity problem
  • Next by thread: unicode character for action pull-down
  • Index(es):
    • Date
    • Thread