mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
Update implementation to calculate position of items for the flow layout. implementation of copyWithZone. Implementation of initWithCoder for flow layout
This commit is contained in:
parent
7fe30c6db2
commit
8948aecae5
4 changed files with 97 additions and 14 deletions
|
@ -95,6 +95,9 @@ NSCollectionViewSupplementaryElementKind NSCollectionElementKindInterItemGapIndi
|
|||
- (NSCollectionElementCategory) representedElementCategory;
|
||||
- (NSString *) representedElementKind;
|
||||
|
||||
- (NSInteger) zIndex;
|
||||
- (void) setZIndex: (NSInteger)zIndex;
|
||||
|
||||
@end
|
||||
|
||||
enum
|
||||
|
|
|
@ -1373,18 +1373,28 @@ static NSString *placeholderItem = nil;
|
|||
if (loaded)
|
||||
{
|
||||
NSView *v = [item view];
|
||||
NSCollectionViewLayoutAttributes *attrs =
|
||||
[_collectionViewLayout layoutAttributesForItemAtIndexPath: path];
|
||||
NSRect frame = [attrs frame];
|
||||
BOOL hidden = [attrs isHidden];
|
||||
CGFloat alpha = [attrs alpha];
|
||||
NSSize sz = [attrs size];
|
||||
|
||||
// set attributes of item based on currently selected layout...
|
||||
frame.size = sz;
|
||||
[v setFrame: frame];
|
||||
[v setHidden: hidden];
|
||||
[v setAlphaValue: alpha];
|
||||
if (_collectionViewLayout)
|
||||
{
|
||||
NSCollectionViewLayoutAttributes *attrs =
|
||||
[_collectionViewLayout layoutAttributesForItemAtIndexPath: path];
|
||||
NSRect frame = [attrs frame];
|
||||
BOOL hidden = [attrs isHidden];
|
||||
CGFloat alpha = [attrs alpha];
|
||||
NSSize sz = [attrs size];
|
||||
|
||||
// set attributes of item based on currently selected layout...
|
||||
frame.size = sz;
|
||||
[v setFrame: frame];
|
||||
[v setHidden: hidden];
|
||||
[v setAlphaValue: alpha];
|
||||
|
||||
// NSLog(@"v = %@, a = %@, l = %@", v, attrs, _collectionViewLayout);
|
||||
[self addSubview: v];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Layout view is not set");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSIndexPath.h>
|
||||
|
||||
#import "AppKit/NSCollectionViewFlowLayout.h"
|
||||
#import "AppKit/NSCollectionViewItem.h"
|
||||
|
||||
@implementation NSCollectionViewFlowLayoutInvalidationContext
|
||||
|
||||
|
@ -61,6 +64,27 @@
|
|||
|
||||
@implementation NSCollectionViewFlowLayout
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
self = [super initWithCoder: coder];
|
||||
if (self)
|
||||
{
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
_itemSize = [coder decodeSizeForKey: @"NSItemSize"];
|
||||
}
|
||||
else
|
||||
{
|
||||
_itemSize = [coder decodeSize];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
}
|
||||
|
||||
- (CGFloat) minimumLineSpacing
|
||||
{
|
||||
return _minimumLineSpacing;
|
||||
|
@ -187,8 +211,28 @@
|
|||
|
||||
- (NSCollectionViewLayoutAttributes *) layoutAttributesForItemAtIndexPath: (NSIndexPath *)indexPath
|
||||
{
|
||||
NSLog(@"Flow layout for index path = %@", indexPath);
|
||||
return nil;
|
||||
NSCollectionViewLayoutAttributes *attrs = [[NSCollectionViewLayoutAttributes alloc] init];
|
||||
NSSize sz = [self itemSize];
|
||||
NSInteger s = [indexPath section];
|
||||
NSInteger r = [indexPath item];
|
||||
CGFloat h = sz.height;
|
||||
CGFloat w = sz.width;
|
||||
NSRect f = NSMakeRect(r * w, s * h, h, w);
|
||||
|
||||
// NSLog(@"Flow layout for index path = %@", indexPath);
|
||||
|
||||
[attrs setFrame: f];
|
||||
[attrs setHidden: NO];
|
||||
[attrs setZIndex: 0];
|
||||
[attrs setSize: sz];
|
||||
|
||||
// NSLog(@"f = %@", NSStringFromRect(f));
|
||||
// NSLog(@"s = %@", NSStringFromSize(sz));
|
||||
// NSLog(@"self = %@", self);
|
||||
|
||||
AUTORELEASE(attrs);
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
- (NSCollectionViewLayoutAttributes *)
|
||||
|
|
|
@ -100,6 +100,16 @@
|
|||
_indexPath = indexPath;
|
||||
}
|
||||
|
||||
- (NSInteger) zIndex
|
||||
{
|
||||
return _zIndex;
|
||||
}
|
||||
|
||||
- (void) setZIndex: (NSInteger)zIndex
|
||||
{
|
||||
_zIndex = zIndex;
|
||||
}
|
||||
|
||||
- (NSCollectionElementCategory) representedElementCategory
|
||||
{
|
||||
return _representedElementCategory;
|
||||
|
@ -112,9 +122,25 @@
|
|||
|
||||
- (id) copyWithZone: (NSZone *)z
|
||||
{
|
||||
NSCollectionViewLayoutAttributes *a = [[NSCollectionViewLayoutAttributes allocWithZone: z] init];
|
||||
|
||||
[a setFrame: [self frame]];
|
||||
[a setSize: [self size]];
|
||||
[a setAlpha: [self alpha]];
|
||||
[a setHidden: [self isHidden]];
|
||||
[a setIndexPath: [self indexPath]];
|
||||
[a setZIndex: [self zIndex]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
- (NSString *) description
|
||||
{
|
||||
return [NSString stringWithFormat: @"%@ - f = %@, s = %@", [super description], NSStringFromRect(_frame), NSStringFromSize(_size)];
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSCollectionViewUpdateItem
|
||||
|
|
Loading…
Reference in a new issue