From 586a1e347da01288ca44b5cff2d3a75698583f98 Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Fri, 1 May 2009 02:00:50 -0700 Subject: [PATCH] Fix for track no longer stretching in vertical sliders. Closes #8. Reviewed by me. --- AppKit/CPSlider.j | 40 ++++++++++++++++++------- AppKit/Themes/Aristo/ThemeDescriptors.j | 2 +- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/AppKit/CPSlider.j b/AppKit/CPSlider.j index 2f46aab78..1f64c28c0 100644 --- a/AppKit/CPSlider.j +++ b/AppKit/CPSlider.j @@ -34,6 +34,8 @@ CPCircularSlider = 1; double _minValue; double _maxValue; double _altIncrementValue; + + BOOL _isVertical; } + (id)themedAttributes @@ -54,6 +56,8 @@ CPCircularSlider = 1; [self setObjectValue:50.0]; [self setContinuous:YES]; + + [self _recalculateIsVertical]; } return self; @@ -226,13 +230,30 @@ CPCircularSlider = 1; return _altIncrementValue; } +- (void)setFrameSize:(CGSize)aSize +{ + [super setFrameSize:aSize]; + [self _recalculateIsVertical]; +} + +- (void)_recalculateIsVertical +{ + // Recalculate isVertical. + var bounds = [self bounds], + width = _CGRectGetWidth(bounds), + height = _CGRectGetHeight(bounds); + + _isVertical = width < height ? 1 : (width > height ? 0 : -1); + + if (_isVertical === 1) + _controlState |= CPControlStateVertical; + else if (_isVertical === 0) + _controlState &= ~CPControlStateVertical; +} + - (int)isVertical { - var bounds = [self bounds], - width = CGRectGetWidth(bounds), - height = CGRectGetHeight(bounds); - - return width < height ? 1 : (width > height ? 0 : -1); + return _isVertical; } - (void)layoutSubviews @@ -240,12 +261,9 @@ CPCircularSlider = 1; 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 @@ -385,6 +403,8 @@ var CPSliderMinValueKey = "CPSliderMinValueKey", [self setContinuous:YES]; + [self _recalculateIsVertical]; + [self setNeedsLayout]; [self setNeedsDisplay:YES]; } diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index 648c13180..5003ee5cb 100644 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -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)]];