ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
CollectionView Struct Reference

CollectionViews display items in a grid. More...

#include <CollectionView.h>

Inheritance diagram for CollectionView:
Control View

Public Member Functions

Class * _CollectionView (void)
 The CollectionView archetype.
 
void deselectAll (CollectionView *self)
 Deselects all items in this CollectionView.
 
void deselectItemAtIndexPath (CollectionView *self, const IndexPath *indexPath)
 Deselects the item at the given index path.
 
void deselectItemsAtIndexPaths (CollectionView *self, const Array *indexPaths)
 Deselects the items at the given index paths.
 
IndexPath * indexPathForItem (const CollectionView *self, const CollectionItemView *item)
 
IndexPath * indexPathForItemAtPoint (const CollectionView *self, const SDL_Point *point)
 
CollectionView * init (CollectionView *self, const SDL_Rect *frame)
 Initializes this CollectionView with the specified frame and style.
 
CollectionView * initWithFrame (CollectionView *self, const SDL_Rect *frame)
 
CollectionItemView * itemAtIndexPath (const CollectionView *self, const IndexPath *indexPath)
 
SDL_Size naturalSize (const CollectionView *self)
 
void reloadData (CollectionView *self)
 Reloads this CollectionView's visible items.
 
void selectAll (CollectionView *self)
 Selects all items in this CollectionView.
 
Array * selectionIndexPaths (const CollectionView *self)
 
void selectItemAtIndexPath (CollectionView *self, const IndexPath *indexPath)
 Selects the item at the given index path.
 
void selectItemsAtIndexPaths (CollectionView *self, const Array *indexPaths)
 Selects the items at the given index paths.
 
- Public Member Functions inherited from Control
Class * _Control (void)
 The Control archetype.
 
bool captureEvent (Control *self, const SDL_Event *event)
 Captures a given event, potentially altering the state of this Control.
 
Control initWithFrame (Control *self, const SDL_Rect *frame)
 Initializes this Control with the specified frame and style.
 
bool isDisabled (const Control *self)
 
bool isFocused (const Control *self)
 
bool isHighlighted (const Control *self)
 
bool isSelected (const Control *self)
 
void stateDidChange (Control *self)
 Called when the state of this Control changes.
 
- Public Member Functions inherited from View
Class * _View (void)
 The View archetype.
 
bool acceptsKeyResponder (const View *self)
 
bool acceptsTouchResponder (const View *self)
 
void addClassName (View *self, const char *className)
 Adds the given class name to this View.
 
void addSubview (View *self, View *subview)
 Adds a subview to this view, to be drawn above its siblings.
 
void addSubviewRelativeTo (View *self, View *subview, View *other, ViewPosition position)
 Adds a subview to this view, positioned relatively to other.
 
 ancestorWithIdentifier (const View *self, const char *identifier)
 
void applyStyle (View *self, const Style *style)
 Applies the given Style to this View.
 
void applyTheme (View *self, const Theme *theme)
 Applies the given Theme to this View.
 
void applyThemeIfNeeded (View *self, const Theme *theme)
 Recursively applies the Theme to this View and its subviews.
 
void attachStylesheet (View *self, SDL_Window *window)
 Attaches this View's Stylesheet to the Theme associated with the given window.
 
void awakeWithCharacters (View *self, const char *chars)
 Wakes this View with the given null-terminated JSON C string.
 
void awakeWithData (View *self, const Data *data)
 Wakes this View with the specified JSON Data.
 
void awakeWithDictionary (View *, const Dictionary *)
 Wakes this View with the specified Dictionary.
 
void awakeWithResource (View *self, const Resource *resource)
 Wakes this View with the specified Resource.
 
void awakeWithResourceName (View *self, const char *name)
 Wakes this View with the Resource by the specified name.
 
void becomeKeyResponder (View *self)
 Become the key responder in the View hierarchy.
 
void becomeTouchResponder (View *self)
 Become the touch responder in the View hierarchy.
 
bool bind (View *self, const Inlet *inlets, const Dictionary *dictionary)
 Performs data binding for the Inlets described in dictionary.
 
SDL_Rect bounds (const View *self)
 
void bringSubviewToFront (View *self, View *subview)
 Brings the specified subview to the front.
 
void clearWarnings (const View *self, WarningType type)
 Clears this View's Warnings matching the given level.
 
SDL_Rect clippingFrame (const View *self)
 
bool containsPoint (const View *self, const SDL_Point *point)
 
int depth (const View *self)
 
 descendantWithIdentifier (const View *self, const char *identifier)
 
void detachStylesheet (View *self, SDL_Window *window)
 Detaches this View's Stylesheet from the Theme associated with the given window.
 
void didMoveToWindow (View *self, SDL_Window *window)
 Informs this View that it has been added to the View hierachy of the given window.
 
bool didReceiveEvent (const View *self, const SDL_Event *event)
 
void draw (View *self, Renderer *renderer)
 Draws this View.
 
void emitViewEvent (View *self, ViewEvent code, ident data)
 Emits a ViewEvent originating from this View.
 
void enumerate (const View *self, ViewEnumerator enumerator, ident data)
 
void enumerate (View *self, ViewEnumerator enumerator, ident data)
 Enumerates this View and its descendants, applying enumerator to each.
 
void enumerateAdjacent (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates adjacent siblings of this View, applying enumerator to each.
 
void enumerateAncestors (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all ancestors of this View, applying enumerator to each.
 
void enumerateDescendants (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all descendants of this View, applying enumerator to each.
 
void enumerateSelection (View *self, const char *rule, ViewEnumerator enumerator, ident data)
 Enumerates all Views in the selection matched by rule, applying enumerator to each.
 
void enumerateSiblings (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all siblings of this View, applying enumerator to each.
 
void enumerateSubviews (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all subviews of this View, applying enumerator to each.
 
void enumerateSuperview (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates the superview of this View, if any, applying enumerator to it.
 
void enumerateVisible (const View *self, ViewEnumerator enumerator, ident data)
 
void enumerateVisible (View *self, ViewEnumerator enumerator, ident data)
 Enumerates this View and its visible descendants, applying enumerator to each.
 
bool hasClassName (const View *self, cosnt char *className)
 
bool hasOverflow (const View *self)
 
View * hitTest (const View *self, const SDL_Point *point)
 Performs a hit test against this View and its descendants for the given point.
 
View * init (View *self)
 Initializes this View.
 
View * initWithFrame (View *self, const SDL_Rect *frame)
 Initializes this View with the specified frame.
 
void invalidateStyle (View *self)
 Invalidates the computed Style for this View and its descendants.
 
bool isContainer (const View *self)
 
bool isDescendantOfView (const View *self, const View *view)
 
bool isKeyResponder (const View *self)
 
bool isTouchResponder (const View *self)
 
bool isVisible (const View *self)
 
void layoutIfNeeded (View *self)
 Recursively updates the layout of this View and its subviews.
 
 layoutSubviews (View *self)
 Arranges this View's immediate subviews within its (already final) frame.
 
void layoutWithConstraint (View *self, ViewConstraint width, ViewConstraint height)
 Resolves this View's size against the given ViewConstraints, then arranges it.
 
void layoutWithSize (View *self, const SDL_Size *size)
 Resizes this View to the given size, then arranges it.
 
bool matchesSelector (const View *self, const SimpleSelector *simpleSelector)
 
void moveToWindow (View *self, SDL_Window *window)
 Moves this View to the View hierarchy of the given window.
 
String * path (const View *self)
 
void removeAllClassNames (View *self)
 Removes all class names from this View.
 
void removeAllSubviews (View *self)
 Removes all subviews from this View.
 
void removeClassName (View *self, const char *className)
 Removes the given class name to this View.
 
void removeFromSuperview (View *self)
 Removes this View from its superview.
 
void removeSubview (View *self, View *subview)
 Removes the given subview from this View.
 
void render (View *self, Renderer *renderer)
 Renders this View using the given renderer.
 
void renderDeviceDidReset (View *self)
 Informs this View that the render device has reset.
 
void renderDeviceWillReset (View *self)
 Informs this View that the render device will reset.
 
SDL_Rect renderFrame (const View *self)
 
void replaceSubview (View *self, View *subview, View *replacement)
 Replaces the specified subview with the given replacement.
 
void resignKeyResponder (View *self)
 Resigns key responder priority.
 
void resignTouchResponder (View *self)
 Resigns touch responder priority.
 
void resize (View *self, const SDL_Size *size)
 Resizes this View to the specified size.
 
void resolve (View *self, Outlet *outlets)
 Resolves the given Outlets from this View's hierarchy.
 
void respondToEvent (View *self, const SDL_Event *event)
 Responds to the specified event.
 
Set * select (View *self, const char *rule)
 Resolves all descendants (including this View) that match the given Selector rule.
 
View * selectFirst (View *self, const char *rule)
 Resolves the first descendant View that matches the given Selector rule.
 
void setNeedsApplyTheme (View *self)
 Marks this View as needing Theme application before it is next drawn.
 
void setNeedsLayout (View *self)
 Marks this View as needing layout before it is next drawn.
 
void setVisibility (View *self, ViewVisibility visibility)
 Sets this View's visibility.
 
SDL_Size size (const View *self)
 
SDL_Size sizeThastFills (const View *self)
 
SDL_Size sizeThatContains (const View *self)
 
SDL_Size sizeThatFills (const View *self)
 
void sizeThatFits (const View *self)
 
SDL_Size sizeThatSatisfies (View *self, ViewConstraint width, ViewConstraint height)
 Resolves the size this View wants to be, within the offered ViewConstraints.
 
void sizeToContain (View *self)
 Resizes this View to contain its subviews.
 
void sizeToFill (View *self)
 Resizes this View to fill its superview.
 
void sizeToFit (View *self)
 Resizes this View to fit its subviews.
 
void sizeToSatisfy (View *self, ViewConstraint width, ViewConstraint height)
 Resizes this View to satisfy the given ViewConstraints.
 
 subviewWithIdentifier (const View *self, const char *identifier)
 
void updateBindings (View *self, ident data)
 Updates data bindings, prompting the appropriate layout changes.
 
SDL_Rect viewport (const View *self)
 
View * viewWithCharacters (const char *chars, Outlet *outlets)
 Instantiates a View initialized with the given null-terminated JSON C string.
 
View * viewWithData (const Data *data, Outlet *outlets)
 Instantiates a View initialized with the contents of data.
 
View * viewWithDictionary (const Dictionary *dictionary, Outlet *outlets)
 Instantiates a View initialized with the attributes described in dictionary.
 
View * viewWithResource (const Resource *resource, Outlet *outlets)
 Instantiates a View initialized with the JSON data in resource.
 
View * viewWithResourceName (const char *name, Outlet *outlets)
 Instantiates a View initialized with the JSON Resource with the specified name.
 
Array * visibleSubviews (const View *self)
 
void warn (View *self, ViewWarningType type, const char *fmt,...)
 
void warn (View *self, WarningType level, const char *fmt,...)
 Appends a warning for this View.
 
void willMoveToWindow (View *self, SDL_Window *window)
 Informs this View that it will be added to the View hierarchy for the given window.
 

Data Fields

CollectionViewAxis axis
 The layout axis.
 
View * contentView
 The content view.
 
Control control
 The superclass.
 
CollectionViewDataSource dataSource
 The data source.
 
CollectionViewDelegate delegate
 The delegate.
 
Array * items
 The items.
 
SDL_Size itemSize
 The item size.
 
SDL_Size itemSpacing
 The item spacing.
 
ScrollView * scrollView
 The scroll view.
 
- Data Fields inherited from Control
ControlBevel bevel
 The ControlBevel.
 
SDL_Color bevelDarkColor
 The bevel color for the shadowed edges.
 
SDL_Color bevelLightColor
 The bevel color for the lit edges.
 
ControlSelection selection
 The ControlSelection.
 
unsigned int state
 The bit mask of ControlState.
 
View view
 The superclass.
 
- Data Fields inherited from View
ViewAlignment alignment
 The alignment.
 
int autoresizingMask
 The ViewAutoresizing bitmask.
 
SDL_Color backgroundColor
 The background color.
 
int backgroundGradientAngle
 The angle of the background gradient, in degrees, clockwise from south: 0 (the default) fills downwards, 90 to the right, 180 upwards.
 
SDL_Color backgroundGradientColor
 The far color of the background gradient, which runs from View::backgroundColor.
 
SDL_Color borderColor
 The border color.
 
int borderRadius
 The corner radius applied to the background, border and bevel.
 
int borderWidth
 The border width.
 
Set * classNames
 The class names.
 
bool clipsSubviews
 If true, subviews will be clipped to this View's frame.
 
Style * computedStyle
 The computed Style of this View.
 
ViewCornerCut cornerCut
 The horizontal inset of each corner of the background and border.
 
char * identifier
 An optional identifier.
 
SDL_Size maxSize
 The maximum size this View may be resized to during layout.
 
SDL_Size minSize
 The minimum size this View may be resized to during layout.
 
bool needsApplyTheme
 If true, this View will apply the Theme before it is drawn.
 
bool needsLayout
 If true, this View will layout its subviews before it is drawn.
 
View * nextResponder
 The next responder, or event handler, in the chain.
 
Object object
 The superclass.
 
ViewPadding padding
 The padding.
 
ViewPointerEvents pointerEvents
 Whether this View is the result of a hit test; its subviews always are.
 
bool stretch
 Whether this View takes a share of the space its StackView leaves along its axis.
 
Style * style
 The element-level Style of this View.
 
Stylesheet * stylesheet
 An optional Stylesheet.
 
Array * subviews
 The immediate subviews.
 
View * superview
 The super View.
 
ViewController * viewController
 The ViewController.
 
ViewVisibility visibility
 Whether this View is drawn, and contributes to its superview's size.
 
Array * warnings
 The Warnings this View generated.
 
SDL_Window * window
 The window.
 

Protected Attributes

CollectionViewInterface * interface [0]
 The interface type.
 
- Protected Attributes inherited from Control
ControlInterface * interface [0]
 The interface type.
 
- Protected Attributes inherited from View
ViewInterface * interface [0]
 The interface type.
 

Detailed Description

CollectionViews display items in a grid.

Definition at line 118 of file CollectionView.h.

Member Function Documentation

◆ _CollectionView()

Class * _CollectionView ( void  )

The CollectionView archetype.

Returns
The CollectionView Class.

Definition at line 541 of file CollectionView.c.

541 {
542 static Class *clazz;
543 static Once once;
544
545 do_once(&once, {
546 clazz = _initialize(&(const ClassDef) {
547 .name = "CollectionView",
548 .superclass = _Control(),
549 .instanceSize = sizeof(CollectionView),
550 .interfaceSize = sizeof(CollectionViewInterface),
551 .initialize = initialize,
552 });
553 });
554
555 return clazz;
556}
static void initialize(Class *clazz)
Definition AtlasImage.c:74
CollectionViews display items in a grid.
Class * _Control(void)
The Control archetype.
Definition Control.c:414

◆ deselectAll()

void deselectAll ( CollectionView *  self)

Deselects all items in this CollectionView.

Parameters
selfThe CollectionView.

Definition at line 201 of file CollectionView.c.

201 {
202 $((Array *) self->items, enumerate, deselectAll_enumerate, NULL);
203}
static void deselectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all item deselection.
Array * items
The items.
void enumerate(const View *self, ViewEnumerator enumerator, ident data)

◆ deselectItemAtIndexPath()

void deselectItemAtIndexPath ( CollectionView *  self,
const IndexPath *  indexPath 
)

Deselects the item at the given index path.

Parameters
selfThe CollectionView.
indexPathThe index path of the item to deselect.

Definition at line 209 of file CollectionView.c.

209 {
210
211 if (indexPath) {
212 CollectionItemView *item = $(self, itemAtIndexPath, indexPath);
213 if (item) {
214 $(item, setSelected, false);
216 }
217 }
218}
static void setSelected(CollectionItemView *self, bool isSelected)
CollectionViewItems are a visual representation of an item within a CollectionView.
CollectionItemView * itemAtIndexPath(const CollectionView *self, const IndexPath *indexPath)
View * contentView
The content view.
void invalidateStyle(View *self)
Invalidates the computed Style for this View and its descendants.
Definition View.c:1092

◆ deselectItemsAtIndexPaths()

void deselectItemsAtIndexPaths ( CollectionView *  self,
const Array *  indexPaths 
)

Deselects the items at the given index paths.

Parameters
selfThe CollectionView.
indexPathsThe index paths of the items to deselect.

Definition at line 231 of file CollectionView.c.

231 {
232
233 if (indexPaths) {
235 }
236}
static void deselectItemsAtIndexPaths_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for item deselection.

◆ indexPathForItem()

IndexPath * indexPathForItem ( const CollectionView *  self,
const CollectionItemView *  item 
)
Parameters
selfThe CollectionView.
itemThe item.
Returns
The index path of item, or NULL if not found.

Definition at line 282 of file CollectionView.c.

282 {
283
284 const ssize_t index = $((Array *) self->items, indexOfObject, (ident) item);
285 if (index > -1) {
286 return $(alloc(IndexPath), initWithIndex, index);
287 }
288
289 return NULL;
290}

◆ indexPathForItemAtPoint()

IndexPath indexPathForItemAtPoint ( const CollectionView *  self,
const SDL_Point *  point 
)
Parameters
selfThe CollectionView.
pointA point in window coordinate space.
Returns
The index path of the item at the specified point, or NULL.

Definition at line 242 of file CollectionView.c.

242 {
243
244 if (self->itemSize.w && self->itemSize.h) {
245
246 const SDL_Rect frame = $(self->contentView, renderFrame);
247
248 const int itemWidth = self->itemSize.w + self->itemSpacing.w;
249 const int itemHeight = self->itemSize.h + self->itemSpacing.h;
250
251 const int rows = max(1, frame.h / itemHeight);
252 const int cols = max(1, frame.w / itemWidth);
253
254 const int x = point->x - frame.x;
255 const int y = point->y - frame.y;
256
257 const int row = y / itemHeight;
258 const int col = x / itemWidth;
259
260 int index;
261 switch (self->axis) {
263 index = row * cols + col;
264 break;
266 index = col * rows + row;
267 break;
268 }
269
270 if (index < (int) self->items->count) {
271 return $(alloc(IndexPath), initWithIndex, index);
272 }
273 }
274
275 return NULL;
276}
@ CollectionViewAxisHorizontal
@ CollectionViewAxisVertical
SDL_Size itemSize
The item size.
CollectionViewAxis axis
The layout axis.
SDL_Size itemSpacing
The item spacing.
SDL_Rect renderFrame(const View *self)
Definition View.c:1629
SDL_Rect frame
The frame, relative to the superview.
Definition View.h:301

◆ init()

CollectionView * init ( CollectionView *  self,
const SDL_Rect *  frame 
)

Initializes this CollectionView with the specified frame and style.

Parameters
selfThe CollectionView.
frameThe frame.
Returns
The initialized CollectionView, or NULL on error.

◆ initWithFrame()

CollectionView * initWithFrame ( CollectionView *  self,
const SDL_Rect *  frame 
)

Definition at line 296 of file CollectionView.c.

296 {
297
298 self = (CollectionView *) super(Control, self, initWithFrame, frame);
299 if (self) {
300 self->items = $$(Array, array);
301 assert(self->items);
302
303 self->contentView = $(alloc(View), initWithFrame, NULL);
304 assert(self->contentView);
305
306 $(self->contentView, addClassName, "contentView");
307 $(self->contentView, addClassName, "container");
308
309 self->scrollView = $(alloc(ScrollView), initWithFrame, NULL);
310 assert(self->scrollView);
311
312 $(self->scrollView, setContentView, self->contentView);
313 $((View *) self, addSubview, (View *) self->scrollView);
314 }
315
316 return self;
317}
static void setContentView(ScrollView *self, View *contentView)
Definition ScrollView.c:231
CollectionView * initWithFrame(CollectionView *self, const SDL_Rect *frame)
ScrollView * scrollView
The scroll view.
Controls are Views which capture and respond to events.
Definition Control.h:83
ScrollViews allow users to pan their internal contents.
Definition ScrollView.h:61
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:225
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition PageView.c:49
void addClassName(View *self, const char *className)
Adds the given class name to this View.
Definition View.c:183

◆ itemAtIndexPath()

CollectionItemView * itemAtIndexPath ( const CollectionView *  self,
const IndexPath *  indexPath 
)
Parameters
selfThe CollectionView.
indexPathAn index path.
Returns
The item at the specified index path, or NULL.

Definition at line 323 of file CollectionView.c.

323 {
324
325 if (indexPath) {
326 const Array *items = (Array *) self->items;
327 const size_t index = $(indexPath, indexAtPosition, 0);
328
329 if (index < items->count) {
330 return $(items, objectAtIndex, index);
331 }
332 }
333
334 return NULL;
335}

◆ naturalSize()

SDL_Size naturalSize ( const CollectionView *  self)
Parameters
selfThe CollectionView.
Returns
The natural size of this CollectionView, placing all items in a single column or row.

Definition at line 341 of file CollectionView.c.

341 {
342
343 ViewPadding padding = MakePadding(0, 0, 0, 0);
344 padding = AddPadding(padding, ((View *) self)->padding);
345 padding = AddPadding(padding, ((View *) self->scrollView)->padding);
346 padding = AddPadding(padding, ((View *) self->contentView)->padding);
347
348 SDL_Size size = MakeSize(padding.left + padding.right, padding.top + padding.bottom);
349
350 View *scrollView = (View *) self->scrollView;
351 SDL_Size scrollViewSize;
353 scrollViewSize = $(scrollView, sizeThatContains);
355 scrollViewSize = $(scrollView, sizeThatFits);
356 } else {
357 scrollViewSize = $(scrollView, size);
358 }
359
360 switch (self->axis) {
362 int itemsPerRow = 1;
363 int w = scrollViewSize.w;
364 while (w > 0) {
365 w -= self->itemSize.w;
366 itemsPerRow++;
367 if (w - self->itemSpacing.w < 0) {
368 break;
369 }
370 w -= self->itemSpacing.w;
371 }
372 const int rows = ceilf(self->items->count / (float) itemsPerRow);
373 size.w += max(self->itemSize.w, scrollViewSize.w);
374 size.h += rows * (self->itemSize.h + self->itemSpacing.h);
375 }
376 break;
378 int itemsPerCol = 1;
379 int h = scrollViewSize.h;
380 while (h > 0) {
381 h -= self->itemSize.h;
382 itemsPerCol++;
383 if (h - self->itemSpacing.h < 0) {
384 break;
385 }
386 h -= self->itemSpacing.h;
387 }
388 const int cols = ceilf(self->items->count / (float) itemsPerCol);
389 size.w += cols * (self->itemSize.w + self->itemSpacing.w);
390 size.h += max(self->itemSize.h, scrollViewSize.h);
391 }
392 break;
393 }
394
395 return size;
396}
#define MakePadding(top, right, bottom, left)
Creates a ViewPadding with the given dimensions.
Definition View.h:176
#define AddPadding(a, b)
Definition View.h:182
@ ViewAutoresizingContain
Definition View.h:95
@ ViewAutoresizingFit
Definition View.h:94
int autoresizingMask
The ViewAutoresizing bitmask.
Definition View.h:248
void sizeThatFits(const View *self)
Definition Select.c:113
SDL_Size size(const View *self)
Definition View.c:1878
ViewPadding padding
The padding.
Definition View.h:398
SDL_Size sizeThatContains(const View *self)
Definition View.c:1886
Spacing applied to the inside of a View's frame.
Definition View.h:169
int top
Definition View.h:170
int bottom
Definition View.h:170
int right
Definition View.h:170
int left
Definition View.h:170

◆ reloadData()

void reloadData ( CollectionView *  self)

Reloads this CollectionView's visible items.

Parameters
selfThe CollectionView.
Remarks
This method must be called after changes to the data source or delegate. Failure to call this method after such changes leads to undefined behavior.

Definition at line 409 of file CollectionView.c.

409 {
410
411 assert(self->dataSource.numberOfItems);
413
414 $((Array *) self->items, enumerate, reloadData_removeItems, self->contentView);
415 $(self->items, removeAllObjects);
416
417 const size_t numberOfItems = self->dataSource.numberOfItems(self);
418 for (size_t i = 0; i < numberOfItems; i++) {
419
420 IndexPath *indexPath = $(alloc(IndexPath), initWithIndex, i);
421
422 CollectionItemView *item = self->delegate.itemForObjectAtIndexPath(self, indexPath);
423 assert(item);
424
425 $(self->items, addObject, item);
426 $(self->contentView, addSubview, (View *) item);
427
428 release(item);
429 release(indexPath);
430 }
431
432 $((View *) self, setNeedsLayout);
433}
static void reloadData_removeItems(const Array *array, ident obj, ident data)
ArrayEnumerator to remove CollectionItemViews from the collection's contentView.
size_t(* numberOfItems)(const CollectionView *collectionView)
CollectionItemView *(* itemForObjectAtIndexPath)(const CollectionView *collectionView, const IndexPath *indexPath)
Called by the CollectionView to instantiate items.
CollectionViewDelegate delegate
The delegate.
CollectionViewDataSource dataSource
The data source.
void setNeedsLayout(View *self)
Marks this View as needing layout before it is next drawn.
Definition View.c:1865

◆ selectAll()

void selectAll ( CollectionView *  self)

Selects all items in this CollectionView.

Parameters
selfThe CollectionView.

Definition at line 446 of file CollectionView.c.

446 {
447 $((Array *) self->items, enumerate, selectAll_enumerate, NULL);
448}
static void selectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all item selection.

◆ selectionIndexPaths()

Array * selectionIndexPaths ( const CollectionView *  self)
Parameters
selfThe CollectionView.
Returns
An Array containing the index paths of all selected items.

Definition at line 454 of file CollectionView.c.

454 {
455
456 Array *array = $$(Array, array);
457
458 const Array *items = (Array *) self->items;
459 for (size_t i = 0; i < items->count; i++) {
460
461 const CollectionItemView *item = $(items, objectAtIndex, i);
462 if (item->isSelected) {
463
464 IndexPath *indexPath = $(self, indexPathForItem, item);
465 $(array, addObject, indexPath);
466
467 release(indexPath);
468 }
469 }
470
471 return (Array *) array;
472}
bool isSelected
True when this item is selected, false otherwise.
IndexPath * indexPathForItem(const CollectionView *self, const CollectionItemView *item)

◆ selectItemAtIndexPath()

void selectItemAtIndexPath ( CollectionView *  self,
const IndexPath *  indexPath 
)

Selects the item at the given index path.

Parameters
selfThe CollectionView.
indexPathThe index path of the item to select.

Definition at line 478 of file CollectionView.c.

478 {
479
480 if (indexPath) {
481 CollectionItemView *item = $(self, itemAtIndexPath, indexPath);
482 if (item) {
483 $(item, setSelected, true);
485 }
486 }
487}

◆ selectItemsAtIndexPaths()

void selectItemsAtIndexPaths ( CollectionView *  self,
const Array *  indexPaths 
)

Selects the items at the given index paths.

Parameters
selfThe CollectionView.
indexPathsThe index paths of the items to select.

Definition at line 500 of file CollectionView.c.

500 {
501
502 if (indexPaths) {
503 $(indexPaths, enumerate, selectItemsAtIndexPaths_enumerate, self);
504 }
505}
static void selectItemsAtIndexPaths_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for item selection.

Field Documentation

◆ axis

CollectionViewAxis CollectionView::axis

The layout axis.

Remarks
Styled. Set from a Style, and overwritten by the next one applied. Assign View::style, or a stylesheet rule, rather than this field.

Definition at line 135 of file CollectionView.h.

◆ contentView

View* CollectionView::contentView

The content view.

Definition at line 140 of file CollectionView.h.

◆ control

Control CollectionView::control

The superclass.

Definition at line 123 of file CollectionView.h.

◆ dataSource

CollectionViewDataSource CollectionView::dataSource

The data source.

Definition at line 145 of file CollectionView.h.

◆ delegate

CollectionViewDelegate CollectionView::delegate

The delegate.

Definition at line 150 of file CollectionView.h.

◆ interface

CollectionViewInterface* CollectionView::interface[0]
protected

The interface type.

Definition at line 129 of file CollectionView.h.

◆ items

Array* CollectionView::items

The items.

Definition at line 155 of file CollectionView.h.

◆ itemSize

SDL_Size CollectionView::itemSize

The item size.

Remarks
Styled. Set from a Style, and overwritten by the next one applied. Assign View::style, or a stylesheet rule, rather than this field.

Definition at line 161 of file CollectionView.h.

◆ itemSpacing

SDL_Size CollectionView::itemSpacing

The item spacing.

Remarks
Styled. Set from a Style, and overwritten by the next one applied. Assign View::style, or a stylesheet rule, rather than this field.

Definition at line 167 of file CollectionView.h.

◆ scrollView

ScrollView* CollectionView::scrollView

The scroll view.

Definition at line 172 of file CollectionView.h.


The documentation for this struct was generated from the following files: