mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-06 10:53:42 +00:00
Merge pull request #2316 from Dogild/MethodSetNeedsLayout
New: added the method setNeedsLayout:
This commit is contained in:
+14
-1
@@ -2608,14 +2608,27 @@ setBoundsOrigin:
|
||||
|
||||
- (void)setNeedsLayout
|
||||
{
|
||||
if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews))
|
||||
[self setNeedsLayout:YES];
|
||||
}
|
||||
|
||||
- (void)setNeedsLayout:(BOOL)needLayout
|
||||
{
|
||||
if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews) || !needLayout)
|
||||
{
|
||||
_needsLayout = NO;
|
||||
return;
|
||||
}
|
||||
|
||||
_needsLayout = YES;
|
||||
|
||||
_CPDisplayServerAddLayoutObject(self);
|
||||
}
|
||||
|
||||
- (BOOL)needsLayout
|
||||
{
|
||||
return _needsLayout;
|
||||
}
|
||||
|
||||
- (void)layoutIfNeeded
|
||||
{
|
||||
if (_needsLayout)
|
||||
|
||||
@@ -643,8 +643,78 @@ var methodCalled;
|
||||
[self assert:expectedRestult equals:methodCalled];
|
||||
}
|
||||
|
||||
- (void)testLayoutSubviews
|
||||
{
|
||||
var layoutView = [[CPLayoutView alloc] initWithFrame:CGRectMakeZero()];
|
||||
|
||||
[layoutView setIdentifier:@"layoutView"];
|
||||
|
||||
[[window contentView] addSubview:layoutView];
|
||||
[layoutView setNeedsLayout]
|
||||
|
||||
methodCalled = [];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
var expectedRestult = ["layoutSubivews_layoutView"];
|
||||
[self assert:expectedRestult equals:methodCalled];
|
||||
|
||||
|
||||
[layoutView setNeedsLayout]
|
||||
[layoutView setNeedsLayout]
|
||||
|
||||
methodCalled = [];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
expectedRestult = ["layoutSubivews_layoutView"];
|
||||
[self assert:expectedRestult equals:methodCalled];
|
||||
|
||||
|
||||
[layoutView setNeedsLayout:YES]
|
||||
|
||||
methodCalled = [];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
expectedRestult = ["layoutSubivews_layoutView"];
|
||||
[self assert:expectedRestult equals:methodCalled];
|
||||
|
||||
|
||||
[layoutView setNeedsLayout:YES];
|
||||
[layoutView setNeedsLayout:NO];
|
||||
|
||||
methodCalled = [];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
expectedRestult = [];
|
||||
[self assert:expectedRestult equals:methodCalled];
|
||||
|
||||
|
||||
[layoutView setNeedsLayout:YES];
|
||||
[layoutView setNeedsLayout:NO];
|
||||
[layoutView setNeedsLayout:YES];
|
||||
|
||||
methodCalled = [];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
expectedRestult = ["layoutSubivews_layoutView"];
|
||||
[self assert:expectedRestult equals:methodCalled];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPLayoutView : CPView
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
var string = @"layoutSubivews_" + [self identifier];
|
||||
[methodCalled addObject:string];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPResponderView : CPView
|
||||
|
||||
|
||||
Reference in New Issue
Block a user