Files
cappuccino/Tests/Manual/CPCollectionViewNibTest/AppController.j
T
cacaodev 4c1ebfbdd4 -setItemPrototype:
Do not cache removed items in -reloadContent when the item prototype changes.

maxItemSize:
    Interpreted as horiz/vertic expandable when zero size and the proto view has a CPViewWidth|HeightSizable. (per cocoa but not documented).
    maxItemSize height support.

Fixed: incorrect position when num items < numberOfColumns.

Rewrote layout engine. Splitted the computation of size, columns count, rows count from the actual layout where we set the frame.
This will help when/if we support insertion/mutation of  -content or view animations.
We can also be more lazy when the computation results stay the same.

Added shared -init. Whitespace cleaning.

CPCollectionviewCibTest:
    Add ability to set the 2 kinds of prototypes, one loading its view from a cib, the other with a view outlet in the same cib.
    Loaded protoype: the bound textfield can commit its value to the model.
    UI for setting maxNumberOfColumns|Rows min|maxItemSize
2012-12-06 19:42:03 +01:00

157 lines
3.5 KiB
Plaintext

/*
* AppController.j
* CPCollectionViewNibTest
*
* Created by You on November 28, 2012.
* Copyright 2012, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
CPLogRegister(CPLogConsole);
@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
@outlet CPCollectionView collectionView @accessors;
@outlet InternalProtoypeItem prototypeItemInternal;
@outlet CPCollectionViewItem prototypeItemExternal;
CPArray content @accessors;
}
- (id)init
{
self = [super init];
content = [CPArray array];
for (var i = 0; i < 8; i++)
[content addObject:[CPDictionary dictionaryWithObject:(String.fromCharCode(65 +i)) forKey:@"value"]]
return self;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
}
- (void)awakeFromCib
{
[self willChangeValueForKey:@"minItemWidth"];
[self willChangeValueForKey:@"minItemHeight"];
[collectionView setMinItemSize:CGSizeMake(100, 100)];
[self didChangeValueForKey:@"minItemWidth"];
[self didChangeValueForKey:@"minItemHeight"];
[self willChangeValueForKey:@"maxItemWidth"];
[self willChangeValueForKey:@"maxItemHeight"];
[collectionView setMaxItemSize:CGSizeMake(200, 150)];
[self didChangeValueForKey:@"maxItemWidth"];
[self didChangeValueForKey:@"maxItemHeight"];
//[theWindow setFullPlatformWindow:YES];
}
- (IBAction)setPrototypeItem:(id)sender
{
var prototypeItem = [[sender selectedItem] tag] ? prototypeItemExternal : prototypeItemInternal;
[collectionView setItemPrototype:prototypeItem];
}
- (void)setMinItemWidth:(CPInteger)aWidth
{
var size = CGSizeMakeCopy([collectionView minItemSize]);
size.width = aWidth;
[collectionView setMinItemSize:size];
}
- (CPInteger)minItemWidth
{
return [collectionView minItemSize].width;
}
- (void)setMinItemHeight:(CPInteger)aHeight
{
var size = CGSizeMakeCopy([collectionView minItemSize]);
size.height = aHeight;
[collectionView setMinItemSize:size];
}
- (CPInteger)minItemHeight
{
return [collectionView minItemSize].height;
}
- (void)setMaxItemWidth:(CPInteger)aWidth
{
var size = CGSizeMakeCopy([collectionView maxItemSize]);
size.width = aWidth;
[collectionView setMaxItemSize:size];
}
- (CPInteger)maxItemWidth
{
return [collectionView maxItemSize].width;
}
- (void)setMaxItemHeight:(CPInteger)aHeight
{
var size = CGSizeMakeCopy([collectionView maxItemSize]);
size.height = aHeight;
[collectionView setMaxItemSize:size];
}
- (CPInteger)maxItemHeight
{
return [collectionView maxItemSize].height;
}
@end
@implementation InternalProtoypeItem: CPCollectionViewItem
{
@outlet CPTextField textField;
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
textField = [aCoder decodeObjectForKey:@"TextField"];
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeConditionalObject:textField forKey:@"TextField"];
}
- (void)setRepresentedObject:(id)anObject
{
[super setRepresentedObject:anObject];
[textField setStringValue:[anObject objectForKey:@"value"]];
}
@end
@implementation RandomColorView : CPView
{
CPColor color;
}
- (void)drawRect:(CGRect)aRect
{
if (!color)
color = [CPColor randomColor];
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, color);
CGContextFillRect(context, aRect);
}
@end