New: added the method setNeedsLayout:

This PR adds the possibility to layout or not a CPView.
Previously, once setNeedsLayout was called on a CPView, it wasn't possible to cancel the layout of the view.
Now we can as in cocoa. The method setNeedsLayout will still work (it calls the method setNeedsLayout: with YES).

UnitTests in Tests/AppKit/CPViewTest.j
This commit is contained in:
Alexandre Wilhelm
2015-02-20 14:36:27 -08:00
parent 2d474ccbda
commit f82b478a77
2 changed files with 79 additions and 1 deletions
+9 -1
View File
@@ -2608,8 +2608,16 @@ setBoundsOrigin:
- (void)setNeedsLayout
{
if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews))
[self setNeedsLayout:YES];
}
- (void)setNeedsLayout:(BOOL)needLayout
{
if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews) || !needLayout)
{
_needsLayout = NO;
return;
}
_needsLayout = YES;
+70
View File
@@ -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