Skip to content

Commit

Permalink
Handle autosized segments
Browse files Browse the repository at this point in the history
widthForSegment: returns 0 for autosized segments, so divide the width between all the segments
  • Loading branch information
iain committed Sep 5, 2012
1 parent 927d8db commit 0c949a9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SNRHUDKit/Classes/SNRHUDSegmentedCell.m
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0c949a9

Please sign in to comment.