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)
 
CollectionViewinit (CollectionView *self, const SDL_Rect *frame)
 Initializes this CollectionView with the specified frame and style.
 
CollectionViewinitWithFrame (CollectionView *self, const SDL_Rect *frame)
 
CollectionItemViewitemAtIndexPath (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)
 
ViewhitTest (const View *self, const SDL_Point *point)
 Performs a hit test against this View and its descendants for the given point.
 
Viewinit (View *self)
 Initializes this View.
 
ViewinitWithFrame (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)
 Performs layout for this View's immediate subviews.
 
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.
 
ViewselectFirst (View *self, const char *rule)
 Resolves the first descendant View that matches the given Selector rule.
 
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)
 
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.
 
 subviewWithIdentifier (const View *self, const char *identifier)
 
void updateBindings (View *self)
 Updates data bindings, prompting the appropriate layout changes.
 
SDL_Rect viewport (const View *self)
 
ViewviewWithCharacters (const char *chars, Outlet *outlets)
 Instantiates a View initialized with the given null-terminated JSON C string.
 
ViewviewWithData (const Data *data, Outlet *outlets)
 Instantiates a View initialized with the contents of data.
 
ViewviewWithDictionary (const Dictionary *dictionary, Outlet *outlets)
 Instantiates a View initialized with the attributes described in dictionary.
 
ViewviewWithResource (const Resource *resource, Outlet *outlets)
 Instantiates a View initialized with the JSON data in resource.
 
ViewviewWithResourceName (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.
 
ViewcontentView
 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.
 
ScrollViewscrollView
 The scroll view.
 
- Data Fields inherited from Control
ControlBevel bevel
 The ControlBevel.
 
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.
 
SDL_Color borderColor
 The border color.
 
int borderWidth
 The border width.
 
Set * classNames
 The class names.
 
bool clipsSubviews
 If true, subviews will be clipped to this View's frame.
 
StylecomputedStyle
 The computed Style of this View.
 
SDL_Rect frame
 The frame, relative to the superview.
 
bool hidden
 If true, this View is not drawn.
 
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.
 
ViewnextResponder
 The next responder, or event handler, in the chain.
 
Object object
 The superclass.
 
ViewPadding padding
 The padding.
 
Stylestyle
 The element-level Style of this View.
 
Stylesheetstylesheet
 An optional Stylesheet.
 
Array * subviews
 The immediate subviews.
 
Viewsuperview
 The super View.
 
ViewControllerviewController
 The ViewController.
 
Array * warnings
 The Warnings this View generated.
 
SDL_Window * window
 The window.
 

Protected Attributes

CollectionViewInterface * interface
 The interface.
 
- Protected Attributes inherited from Control
ControlInterface * interface
 The interface.
 
- Protected Attributes inherited from View
ViewInterface * interface
 The interface.
 

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 542 of file CollectionView.c.

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

◆ deselectAll()

void deselectAll ( CollectionView self)

Deselects all items in this CollectionView.

Parameters
selfThe CollectionView.

Definition at line 202 of file CollectionView.c.

202 {
203 $((Array *) self->items, enumerate, deselectAll_enumerate, NULL);
204}
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 210 of file CollectionView.c.

210 {
211
212 if (indexPath) {
213 CollectionItemView *item = $(self, itemAtIndexPath, indexPath);
214 if (item) {
215 $(item, setSelected, false);
217 }
218 }
219}
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:1033

◆ 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 232 of file CollectionView.c.

232 {
233
234 if (indexPaths) {
236 }
237}
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 283 of file CollectionView.c.

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

◆ 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 243 of file CollectionView.c.

243 {
244
245 if (self->itemSize.w && self->itemSize.h) {
246
247 const SDL_Rect frame = $(self->contentView, renderFrame);
248
249 const int itemWidth = self->itemSize.w + self->itemSpacing.w;
250 const int itemHeight = self->itemSize.h + self->itemSpacing.h;
251
252 const int rows = max(1, frame.h / itemHeight);
253 const int cols = max(1, frame.w / itemWidth);
254
255 const int x = point->x - frame.x;
256 const int y = point->y - frame.y;
257
258 const int row = y / itemHeight;
259 const int col = x / itemWidth;
260
261 int index;
262 switch (self->axis) {
264 index = row * cols + col;
265 break;
267 index = col * rows + row;
268 break;
269 }
270
271 if (index < (int) self->items->count) {
272 return $(alloc(IndexPath), initWithIndex, index);
273 }
274 }
275
276 return NULL;
277}
@ 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:1455
SDL_Rect frame
The frame, relative to the superview.
Definition View.h:191

◆ 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 297 of file CollectionView.c.

297 {
298
299 self = (CollectionView *) super(Control, self, initWithFrame, frame);
300 if (self) {
301 self->items = $$(Array, array);
302 assert(self->items);
303
304 self->contentView = $(alloc(View), initWithFrame, NULL);
305 assert(self->contentView);
306
307 $(self->contentView, addClassName, "contentView");
308 $(self->contentView, addClassName, "container");
309
310 self->scrollView = $(alloc(ScrollView), initWithFrame, NULL);
311 assert(self->scrollView);
312
313 $(self->scrollView, setContentView, self->contentView);
314 $((View *) self, addSubview, (View *) self->scrollView);
315 }
316
317 return self;
318}
static void setContentView(ScrollView *self, View *contentView)
Definition ScrollView.c:148
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:62
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134
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:159

◆ 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 324 of file CollectionView.c.

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

◆ 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 342 of file CollectionView.c.

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

◆ 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 410 of file CollectionView.c.

410 {
411
412 assert(self->dataSource.numberOfItems);
414
415 $((Array *) self->items, enumerate, reloadData_removeItems, self->contentView);
416 $(self->items, removeAllObjects);
417
418 const size_t numberOfItems = self->dataSource.numberOfItems(self);
419 for (size_t i = 0; i < numberOfItems; i++) {
420
421 IndexPath *indexPath = $(alloc(IndexPath), initWithIndex, i);
422
423 CollectionItemView *item = self->delegate.itemForObjectAtIndexPath(self, indexPath);
424 assert(item);
425
426 $(self->items, addObject, item);
427 $(self->contentView, addSubview, (View *) item);
428
429 release(item);
430 release(indexPath);
431 }
432
433 ((View *) self)->needsLayout = true;
434}
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.

◆ selectAll()

void selectAll ( CollectionView self)

Selects all items in this CollectionView.

Parameters
selfThe CollectionView.

Definition at line 447 of file CollectionView.c.

447 {
448 $((Array *) self->items, enumerate, selectAll_enumerate, NULL);
449}
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 455 of file CollectionView.c.

455 {
456
457 Array *array = $$(Array, array);
458
459 const Array *items = (Array *) self->items;
460 for (size_t i = 0; i < items->count; i++) {
461
462 const CollectionItemView *item = $(items, objectAtIndex, i);
463 if (item->isSelected) {
464
465 IndexPath *indexPath = $(self, indexPathForItem, item);
466 $(array, addObject, indexPath);
467
468 release(indexPath);
469 }
470 }
471
472 return (Array *) array;
473}
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 479 of file CollectionView.c.

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

◆ 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 501 of file CollectionView.c.

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

Field Documentation

◆ axis

CollectionViewAxis CollectionView::axis

The layout axis.

Definition at line 134 of file CollectionView.h.

◆ contentView

View* CollectionView::contentView

The content view.

Definition at line 139 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 144 of file CollectionView.h.

◆ delegate

CollectionViewDelegate CollectionView::delegate

The delegate.

Definition at line 149 of file CollectionView.h.

◆ interface

CollectionViewInterface* CollectionView::interface
protected

The interface.

Definition at line 129 of file CollectionView.h.

◆ items

Array* CollectionView::items

The items.

Definition at line 154 of file CollectionView.h.

◆ itemSize

SDL_Size CollectionView::itemSize

The item size.

Definition at line 159 of file CollectionView.h.

◆ itemSpacing

SDL_Size CollectionView::itemSpacing

The item spacing.

Definition at line 164 of file CollectionView.h.

◆ scrollView

ScrollView* CollectionView::scrollView

The scroll view.

Definition at line 169 of file CollectionView.h.


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