mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-18 22:41:18 +00:00
Added setNeedsLayout and layoutSubviews. Changed CPSlider to use them.
Reviewed by me.
This commit is contained in:
1 parent
9ec781fb41
commit
e35c4b1461
3 files changed
+111
-29
No files matched your search
+67
-27
@@ -89,6 +89,7 @@
|
||||
{
|
||||
[super setObjectValue:aValue];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -99,6 +100,7 @@
|
||||
|
||||
_horizontalTrackColor = aColor;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -114,6 +116,7 @@
|
||||
|
||||
_verticalTrackColor = aColor;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -129,6 +132,7 @@
|
||||
|
||||
_trackWidth = aTrackWidth;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -178,6 +182,7 @@
|
||||
|
||||
_knobSize = aKnobSize ? _CGSizeMakeCopy(aKnobSize) : nil;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -188,6 +193,7 @@
|
||||
|
||||
_knobColor = aColor;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -231,30 +237,55 @@
|
||||
return width < height ? 1 : (width > height ? 0 : -1);
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
- (CPView)createTrackView
|
||||
{
|
||||
var trackView = [[CPView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
|
||||
[trackView setHitTests:NO];
|
||||
|
||||
return trackView;
|
||||
}
|
||||
|
||||
- (CPView)createKnobView
|
||||
{
|
||||
var knobView = [[CPView alloc] initWithFrame:_CGRectMakeZero()];
|
||||
|
||||
[knobView setHitTests:NO];
|
||||
|
||||
return knobView;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
var bounds = [self bounds],
|
||||
isVertical = [self isVertical],
|
||||
trackRect = nil;
|
||||
|
||||
if ((isVertical && _verticalTrackColor || !isVertical && _horizontalTrackColor) &&
|
||||
(trackRect = [self trackRectForBounds:_CGRectMakeCopy(bounds)]) && !_CGRectIsEmpty(trackRect))
|
||||
if ((trackRect = [self trackRectForBounds:_CGRectMakeCopy(bounds)]) && !_CGRectIsEmpty(trackRect))
|
||||
{
|
||||
if (!_trackView)
|
||||
{
|
||||
_trackView = [[CPView alloc] initWithFrame:trackRect];
|
||||
_trackView = [self createTrackView]
|
||||
|
||||
[_trackView setHitTests:NO];
|
||||
|
||||
[self addSubview:_trackView positioned:CPWindowBelow relativeTo:_knobView];
|
||||
if (_trackView)
|
||||
[self addSubview:_trackView positioned:CPWindowBelow relativeTo:_knobView];
|
||||
}
|
||||
else
|
||||
[_trackView setFrame:trackRect];
|
||||
|
||||
if (_trackView)
|
||||
{
|
||||
[_trackView setFrame:trackRect];
|
||||
|
||||
if ([self isVertical])
|
||||
[_trackView setBackgroundColor:_verticalTrackColor];
|
||||
else
|
||||
[_trackView setBackgroundColor:_horizontalTrackColor];
|
||||
if ([self isVertical])
|
||||
{
|
||||
if (_verticalTrackColor)
|
||||
[_trackView setBackgroundColor:_verticalTrackColor];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_horizontalTrackColor)
|
||||
[_trackView setBackgroundColor:_horizontalTrackColor];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_trackView)
|
||||
{
|
||||
@@ -265,26 +296,28 @@
|
||||
|
||||
var knobRect = nil;
|
||||
|
||||
if (_knobColor && (knobRect = [self knobRectForBounds:bounds]) && !_CGRectIsEmpty(knobRect))
|
||||
if ((knobRect = [self knobRectForBounds:bounds]) && !_CGRectIsEmpty(knobRect))
|
||||
{
|
||||
if (!_knobView)
|
||||
{
|
||||
_knobView = [[CPView alloc] initWithFrame:knobRect];
|
||||
_knobView = [self createKnobView];
|
||||
|
||||
[_knobView setHitTests:NO];
|
||||
|
||||
[self addSubview:_knobView positioned:CPWindowAbove relativeTo:_trackView];
|
||||
if (_knobView)
|
||||
[self addSubview:_knobView positioned:CPWindowAbove relativeTo:_trackView];
|
||||
}
|
||||
else
|
||||
|
||||
if (_knobView)
|
||||
{
|
||||
[_knobView setFrame:knobRect];
|
||||
|
||||
if (_isHighlighted)
|
||||
{
|
||||
if (_highlightedKnobColor)
|
||||
[_knobView setBackgroundColor:_highlightedKnobColor];
|
||||
|
||||
if (_isHighlighted)
|
||||
{
|
||||
if (_highlightedKnobColor)
|
||||
[_knobView setBackgroundColor:_highlightedKnobColor];
|
||||
}
|
||||
else if (_knobColor)
|
||||
[_knobView setBackgroundColor:_knobColor];
|
||||
}
|
||||
else
|
||||
[_knobView setBackgroundColor:_knobColor];
|
||||
}
|
||||
else if (_knobView)
|
||||
{
|
||||
@@ -352,6 +385,8 @@
|
||||
}
|
||||
|
||||
_isHighlighted = YES;
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
return YES;
|
||||
@@ -371,6 +406,7 @@
|
||||
if ([_target respondsToSelector:@selector(sliderDidFinish:)])
|
||||
[_target sliderDidFinish:self];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -407,6 +443,7 @@
|
||||
[self setHorizontalTrackColor:[theme valueForKey:@"horizontal-track-color"]];
|
||||
[self setVerticalTrackColor:[theme valueForKey:@"vertical-track-color"]];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -443,7 +480,10 @@ var CPSliderMinValueKey = "CPSliderMinValueKey",
|
||||
_altIncrementValue = [aCoder decodeDoubleForKey:CPSliderAltIncrValueKey];
|
||||
|
||||
[self setContinuous:YES];
|
||||
|
||||
|
||||
[self setTheme:[CPTheme defaultTheme]];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
|
||||
+43
-2
@@ -98,7 +98,8 @@ var DOMElementPrototype = nil,
|
||||
BackgroundHorizontalThreePartImage = 2,
|
||||
BackgroundNinePartImage = 3,
|
||||
|
||||
CustomDrawRectViews = {};
|
||||
CustomDrawRectViews = {},
|
||||
CustomLayoutSubviewsViews = {};
|
||||
#endif
|
||||
|
||||
/*! @class CPView
|
||||
@@ -154,6 +155,7 @@ var DOMElementPrototype = nil,
|
||||
#endif
|
||||
|
||||
CGRect _dirtyRect;
|
||||
BOOL _needsLayout;
|
||||
|
||||
float _opacity;
|
||||
CPColor _backgroundColor;
|
||||
@@ -624,7 +626,8 @@ var DOMElementPrototype = nil,
|
||||
|
||||
if (_autoresizesSubviews)
|
||||
[self resizeSubviewsWithOldSize:oldSize];
|
||||
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
@@ -1525,6 +1528,44 @@ setBoundsOrigin:
|
||||
[CPGraphicsContext setCurrentContext:nil];
|
||||
}
|
||||
|
||||
- (void)setNeedsLayout
|
||||
{
|
||||
_needsLayout = YES;
|
||||
|
||||
#if PLATFORM(DOM)
|
||||
var hash = [[self class] hash],
|
||||
hasCustomLayoutSubviews = CustomLayoutSubviewsViews[hash];
|
||||
|
||||
if (hasCustomLayoutSubviews === undefined)
|
||||
{
|
||||
hasCustomLayoutSubviews = [self methodForSelector:@selector(layoutSubviews)] != [CPView instanceMethodForSelector:@selector(layoutSubviews)];
|
||||
CustomLayoutSubviewsViews[hash] = hasCustomLayoutSubviews;
|
||||
}
|
||||
|
||||
if (!hasCustomLayoutSubviews)
|
||||
return;
|
||||
|
||||
if (_needsLayout)
|
||||
{
|
||||
CPDOMDisplayServerAddView(self);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)layoutIfNeeded
|
||||
{
|
||||
if (_needsLayout)
|
||||
{
|
||||
_needsLayout = NO;
|
||||
|
||||
[self layoutSubviews];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns whether the receiver is completely opaque. By default, returns <code>NO</code>.
|
||||
*/
|
||||
|
||||
@@ -152,6 +152,7 @@ CPDOMDisplayServerViewsContext = {};
|
||||
|
||||
delete CPDOMDisplayServerViewsContext[[view hash]];
|
||||
|
||||
[view layoutIfNeeded];
|
||||
[view displayIfNeeded];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user