Skip to content

Commit

Permalink
Fix for track no longer stretching in vertical sliders.
Browse files Browse the repository at this point in the history
Closes #8.

Reviewed by me.
  • Loading branch information
Francisco Tolmasky committed May 1, 2009
1 parent 08b4bda commit 586a1e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
38 changes: 29 additions & 9 deletions AppKit/CPSlider.j
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ CPCircularSlider = 1;
double _minValue;
double _maxValue;
double _altIncrementValue;

BOOL _isVertical;
}

+ (id)themedAttributes
Expand All @@ -54,6 +56,8 @@ CPCircularSlider = 1;
[self setObjectValue:50.0];

[self setContinuous:YES];

[self _recalculateIsVertical];
}

return self;
Expand Down Expand Up @@ -226,26 +230,40 @@ CPCircularSlider = 1;
return _altIncrementValue;
}

- (int)isVertical
- (void)setFrameSize:(CGSize)aSize
{
[super setFrameSize:aSize];
[self _recalculateIsVertical];
}

- (void)_recalculateIsVertical
{
// Recalculate isVertical.
var bounds = [self bounds],
width = CGRectGetWidth(bounds),
height = CGRectGetHeight(bounds);
width = _CGRectGetWidth(bounds),
height = _CGRectGetHeight(bounds);

return width < height ? 1 : (width > height ? 0 : -1);
_isVertical = width < height ? 1 : (width > height ? 0 : -1);

if (_isVertical === 1)
_controlState |= CPControlStateVertical;
else if (_isVertical === 0)
_controlState &= ~CPControlStateVertical;
}

- (int)isVertical
{
return _isVertical;
}

- (void)layoutSubviews
{
var trackView = [self layoutEphemeralSubviewNamed:@"track-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"knob-view"];

if (trackView)
if ([self isVertical])
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"track-color"]];
else
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"track-color"]];
[trackView setBackgroundColor:[self currentValueForThemedAttributeName:@"track-color"]];

var knobView = [self layoutEphemeralSubviewNamed:@"knob-view"
positioned:CPWindowAbove
Expand Down Expand Up @@ -385,6 +403,8 @@ var CPSliderMinValueKey = "CPSliderMinValueKey",

[self setContinuous:YES];

[self _recalculateIsVertical];

[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
Expand Down
2 changes: 1 addition & 1 deletion AppKit/Themes/Aristo/ThemeDescriptors.j
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
isVertical:YES]];

[slider setValue:5.0 forThemedAttributeName:@"track-width"];
[slider setValue:trackColor forThemedAttributeName:@"track-color"];
[slider setValue:trackColor forThemedAttributeName:@"track-color" inControlState:CPControlStateVertical];

var knobColor = [CPColor colorWithPatternImage:[_CPCibCustomResource imageResourceWithName:"knob.png" size:CGSizeMake(23.0, 24.0)]];
knobHighlightedColor = [CPColor colorWithPatternImage:[_CPCibCustomResource imageResourceWithName:"knob-highlighted.png" size:CGSizeMake(23.0, 24.0)]];
Expand Down

0 comments on commit 586a1e3

Please sign in to comment.