Permalink
Browse files

Merge pull request #13 from iainx/autosized-segments

Autosized segments
  • Loading branch information...
2 parents 812606a + 0c949a9 commit bbdb4d5295fa7c98bcab7b7f52178608d017dfd5 @indragiek committed Sep 6, 2012
Showing with 34 additions and 19 deletions.
  1. +8 −0 SNRHUDKit/Classes/SNRHUDSegmentedCell.m
  2. +26 −19 SNRHUDKit/Classes/SNRHUDTextFieldCell.m
@@ -80,6 +80,14 @@ - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
CGFloat currentOrigin = 0.0;
for (NSInteger i = 0; i < segmentCount; i++) {
CGFloat width = [self widthForSegment:i];
+
+ // widthForSegment: returns 0 for autosized segments
+ // so we need to divide the width of the cell evenly between all the segments
+ // It will still break if one segment is much wider than the others
+ if (width == 0) {
+ width = (cellFrame.size.width - (SNRSegControlDivderWidth * (segmentCount - 1))) / segmentCount;
+ }
+
if (i != (segmentCount - 1)) {
width += SNRSegControlDivderWidth;
}
@@ -62,26 +62,33 @@ - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
}
NSRect backgroundRect = cellFrame;
backgroundRect.size.height -= 1.f;
+
NSBezierPath *backgroundPath = [NSBezierPath bezierPathWithRect:backgroundRect];
- [SNRTextFieldBackgroundColor set];
- [backgroundPath fill];
- NSShadow *innerGlow = [NSShadow new];
- [innerGlow setShadowColor:SNRTextFieldInnerGlowColor];
- [innerGlow setShadowOffset:SNRTextFieldInnerGlowOffset];
- [innerGlow setShadowBlurRadius:SNRTextFieldInnerGlowBlurRadius];
- [backgroundPath fillWithInnerShadow:innerGlow];
- NSRect innerShadowRect = NSInsetRect(backgroundRect, -2.f, 0.f);
- innerShadowRect.size.height *= 2.f;
- NSBezierPath *shadowPath = [NSBezierPath bezierPathWithRect:innerShadowRect];
- NSShadow *innerShadow = [NSShadow new];
- [innerShadow setShadowColor:SNRTextFieldInnerShadowColor];
- [innerShadow setShadowOffset:SNRTextFieldInnerShadowOffset];
- [innerShadow setShadowBlurRadius:SNRTextFieldInnerShadowBlurRadius];
- [shadowPath fillWithInnerShadow:innerShadow];
- NSRect dropShadowRect = backgroundRect;
- dropShadowRect.origin.y = NSMaxY(cellFrame) - 1.f;
- [SNRTextFieldDropShadowColor set];
- [NSBezierPath fillRect:dropShadowRect];
+
+ if ([self drawsBackground]) {
+ [SNRTextFieldBackgroundColor set];
+ [backgroundPath fill];
+ }
+
+ if ([self isBezeled]) {
+ NSShadow *innerGlow = [NSShadow new];
+ [innerGlow setShadowColor:SNRTextFieldInnerGlowColor];
+ [innerGlow setShadowOffset:SNRTextFieldInnerGlowOffset];
+ [innerGlow setShadowBlurRadius:SNRTextFieldInnerGlowBlurRadius];
+ [backgroundPath fillWithInnerShadow:innerGlow];
+ NSRect innerShadowRect = NSInsetRect(backgroundRect, -2.f, 0.f);
+ innerShadowRect.size.height *= 2.f;
+ NSBezierPath *shadowPath = [NSBezierPath bezierPathWithRect:innerShadowRect];
+ NSShadow *innerShadow = [NSShadow new];
+ [innerShadow setShadowColor:SNRTextFieldInnerShadowColor];
+ [innerShadow setShadowOffset:SNRTextFieldInnerShadowOffset];
+ [innerShadow setShadowBlurRadius:SNRTextFieldInnerShadowBlurRadius];
+ [shadowPath fillWithInnerShadow:innerShadow];
+ NSRect dropShadowRect = backgroundRect;
+ dropShadowRect.origin.y = NSMaxY(cellFrame) - 1.f;
+ [SNRTextFieldDropShadowColor set];
+ [NSBezierPath fillRect:dropShadowRect];
+ }
// Draw the text vertically centered
NSSize textSize = [self cellSizeForBounds:cellFrame];

0 comments on commit bbdb4d5

Please sign in to comment.