ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions
TableView.c File Reference
#include <assert.h>
#include <string.h>
#include <Objectively/String.h>
#include "SoundStage.h"
#include "TableView.h"

Go to the source code of this file.

Macros

#define _Class   _TableView
 

Functions

Class * _TableView (void)
 
static void addColumn (TableView *self, TableColumn *column)
 
static void addColumnWithIdentifier (TableView *self, const char *identifier)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void awakeWithDictionary_columns (const Array *array, ident obj, ident data)
 ArrayEnumerator for awaking TableColumns. More...
 
static _Bool captureEvent (Control *self, const SDL_Event *event)
 
static TableColumncolumnAtPoint (const TableView *self, const SDL_Point *point)
 
static TableColumncolumnWithIdentifier (const TableView *self, const char *identifier)
 
static void dealloc (Object *self)
 
static void deselectAll (TableView *self)
 
static void deselectAll_enumerate (const Array *array, ident obj, ident data)
 ArrayEnumerator for all Row deselection. More...
 
static void deselectRowAtIndex (TableView *self, size_t index)
 
static void deselectRowsAtIndexes (TableView *self, const IndexSet *indexes)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static TableViewinitWithFrame (TableView *self, const SDL_Rect *frame)
 
static void layoutSubviews (View *self)
 
static SDL_Size naturalSize (const TableView *self)
 
static void reloadData (TableView *self)
 
static void reloadData_removeRows (const Array *array, ident obj, ident data)
 ArrayEnumerator to remove TableRowViews from the table's contentView. More...
 
static void removeColumn (TableView *self, TableColumn *column)
 
static ssize_t rowAtPoint (const TableView *self, const SDL_Point *point)
 
static void selectAll (TableView *self)
 
static void selectAll_enumerate (const Array *array, ident obj, ident data)
 ArrayEnumerator for all row selection. More...
 
static IndexSet * selectedRowIndexes (const TableView *self)
 
static void selectRowAtIndex (TableView *self, size_t index)
 
static void selectRowsAtIndexes (TableView *self, const IndexSet *indexes)
 
static void setSortColumn (TableView *self, TableColumn *column)
 
static SDL_Size sizeThatFits (const View *self)
 

Macro Definition Documentation

◆ _Class

#define _Class   _TableView

Definition at line 32 of file TableView.c.

Function Documentation

◆ _TableView()

Class * _TableView ( void  )

Definition at line 608 of file TableView.c.

608 {
609 static Class *clazz;
610 static Once once;
611
612 do_once(&once, {
613 clazz = _initialize(&(const ClassDef) {
614 .name = "TableView",
615 .superclass = _Control(),
616 .instanceSize = sizeof(TableView),
617 .interfaceOffset = offsetof(TableView, interface),
618 .interfaceSize = sizeof(TableViewInterface),
620 });
621 });
622
623 return clazz;
624}
static void initialize(Class *clazz)
Definition: TableView.c:574
Class * _Control(void)
The Control archetype.
Definition: Control.c:379
TableViews provide sortable, tabular presentations of data.
Definition: TableView.h:122

◆ addColumn()

static void addColumn ( TableView self,
TableColumn column 
)
static

Definition at line 214 of file TableView.c.

214 {
215
216 assert(column);
217
218 $(self->columns, addObject, column);
219
220 $((TableRowView *) self->headerView, addCell, (TableCellView *) column->headerCell);
221}
Each row in a TableView is comprised of TableCellViews.
Definition: TableCellView.h:41
TableHeaderCellView * headerCell
The header cell.
Definition: TableColumn.h:61
Rows for TableViews.
Definition: TableRowView.h:44
void addCell(TableRowView *self, TableCellView *cell)
Adds the specified cell to this row.
Definition: TableRowView.c:69
MutableArray * columns
The column definitions.
Definition: TableView.h:138
TableHeaderView * headerView
The header.
Definition: TableView.h:158

◆ addColumnWithIdentifier()

static void addColumnWithIdentifier ( TableView self,
const char *  identifier 
)
static

Definition at line 227 of file TableView.c.

227 {
228
229 TableColumn *column = $(alloc(TableColumn), initWithIdentifier, identifier);
230 assert(column);
231
232 $(self, addColumn, column);
233
234 release(column);
235}
Columns provide alignment, spacing and sorting hints for TableView instances.
Definition: TableColumn.h:45
TableColumn * initWithIdentifier(TableColumn *self, const char *identifier)
Initializes this TableColumn with the given identifier.
Definition: TableColumn.c:56
void addColumn(TableView *self, TableColumn *column)
Adds the specified column to this table.
Definition: TableView.c:214

◆ awakeWithDictionary()

static void awakeWithDictionary ( View self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 73 of file TableView.c.

73 {
74
75 super(View, self, awakeWithDictionary, dictionary);
76
77 const Array *columns = $(dictionary, objectForKeyPath, "columns");
78 if (columns) {
79 $(columns, enumerateObjects, awakeWithDictionary_columns, self);
80 }
81}
static void awakeWithDictionary_columns(const Array *array, ident obj, ident data)
ArrayEnumerator for awaking TableColumns.
Definition: TableView.c:57
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
Definition: Box.c:50

◆ awakeWithDictionary_columns()

static void awakeWithDictionary_columns ( const Array *  array,
ident  obj,
ident  data 
)
static

ArrayEnumerator for awaking TableColumns.

Definition at line 57 of file TableView.c.

57 {
58
59 const String *identifier = $((Dictionary *) obj, objectForKeyPath, "identifier");
60 assert(identifier);
61
62 TableColumn *column = $(alloc(TableColumn), initWithIdentifier, identifier->chars);
63 assert(column);
64
65 $((TableView *) data, addColumn, column);
66
67 release(column);
68}

◆ captureEvent()

static _Bool captureEvent ( Control self,
const SDL_Event *  event 
)
static
See also
Control::captureEvent(Control *, const SDL_Event *)

Definition at line 130 of file TableView.c.

130 {
131
132 TableView *this = (TableView *) self;
133
134 if (event->type == SDL_MOUSEBUTTONUP) {
135
136 if ($((View *) this->headerView, didReceiveEvent, event)) {
137
138 const SDL_Point point = {
139 .x = event->button.x,
140 .y = event->button.y
141 };
142
143 TableColumn *column = $(this, columnAtPoint, &point);
144 if (column) {
145 $(this, setSortColumn, column);
146 }
147
148 return true;
149 }
150
151 if ($((Control *) this->scrollView, isHighlighted) == false) {
152 if ($((View *) this->contentView, didReceiveEvent, event)) {
153
154 const SDL_Point point = {
155 .x = event->button.x,
156 .y = event->button.y
157 };
158
159 const ssize_t index = $(this, rowAtPoint, &point);
160
161 const Array *rows = (Array *) this->rows;
162 if (index > -1 && index < (ssize_t) rows->count) {
163
164 TableRowView *row = $(rows, objectAtIndex, index);
165
166 switch (this->control.selection) {
168 break;
170 if (row->isSelected == false) {
171 $(this, deselectAll);
172 $(this, selectRowAtIndex, index);
174 }
175 break;
177 if (SDL_GetModState() & (KMOD_CTRL | KMOD_GUI)) {
178 if (row->isSelected) {
179 $(this, deselectRowAtIndex, index);
180 } else {
181 $(this, selectRowAtIndex, index);
182 }
183 } else {
184 $(this, deselectAll);
185 $(this, selectRowAtIndex, index);
186 }
187 break;
188 }
189
190 if (this->delegate.didSelectRowsAtIndexes) {
191 IndexSet *selectedRowIndexes = $(this, selectedRowIndexes);
192
193 this->delegate.didSelectRowsAtIndexes(this, selectedRowIndexes);
194
195 release(selectedRowIndexes);
196 }
197 }
198
199 return true;
200 }
201 }
202 }
203
204 return super(Control, self, captureEvent, event);
205}
@ ControlSelectionMultiple
Definition: Control.h:58
@ ControlSelectionSingle
Definition: Control.h:57
@ ControlSelectionNone
Definition: Control.h:56
OBJECTIVELYMVC_EXPORT void MVC_PlaySound(const Sound *sound)
Plays the specified Sound through the current SoundStage (if any).
Definition: SoundStage.c:141
void deselectAll(CollectionView *self)
Deselects all items in this CollectionView.
Controls are Views which capture events and dispatch Actions.
Definition: Control.h:83
_Bool captureEvent(Control *self, const SDL_Event *event)
Captures a given event, potentially altering the state of this Control.
Definition: Button.c:76
_Bool isHighlighted(const Control *self)
Definition: Control.c:317
_Bool isSelected
True when this row is selected, false otherwise.
Definition: TableRowView.h:65
IndexSet * selectedRowIndexes(const TableView *self)
Definition: TableView.c:495
TableColumn * columnAtPoint(const TableView *self, const SDL_Point *point)
Definition: TableView.c:241
ssize_t rowAtPoint(const TableView *self, const SDL_Point *point)
Definition: TableView.c:458
void setSortColumn(TableView *self, TableColumn *column)
Sets the sort column for this table.
Definition: TableView.c:543
void selectRowAtIndex(TableView *self, size_t index)
Selects the row at the given index.
Definition: TableView.c:516
_Bool didReceiveEvent(const View *self, const SDL_Event *event)
Definition: View.c:546

◆ columnAtPoint()

static TableColumn * columnAtPoint ( const TableView self,
const SDL_Point *  point 
)
static

Definition at line 241 of file TableView.c.

241 {
242
243 const SDL_Rect frame = $((View *) self, renderFrame);
244 if (SDL_PointInRect(point, &frame)) {
245
246 const Array *cells = (Array *) self->headerView->tableRowView.cells;
247 const Array *columns = (Array *) self->columns;
248
249 assert(cells->count == columns->count);
250
251 for (size_t i = 0; i < cells->count; i++) {
252
253 const View *cell = $(cells, objectAtIndex, i);
254 const SDL_Rect renderFrame = $(cell, renderFrame);
255
256 if (renderFrame.x + renderFrame.w >= point->x) {
257 return $(columns, objectAtIndex, i);
258 }
259 }
260 }
261
262 return NULL;
263}
TableRowView tableRowView
The superclass.
MutableArray * cells
The cells.
Definition: TableRowView.h:60
SDL_Rect renderFrame(const View *self)
Definition: View.c:1275

◆ columnWithIdentifier()

static TableColumn * columnWithIdentifier ( const TableView self,
const char *  identifier 
)
static

Definition at line 269 of file TableView.c.

269 {
270
271 assert(identifier);
272
273 const Array *columns = (Array *) self->columns;
274 for (size_t i = 0; i < columns->count; i++) {
275
276 TableColumn *column = $(columns, objectAtIndex, i);
277 if (strcmp(identifier, column->identifier) == 0) {
278 return column;
279 }
280 }
281
282 return NULL;
283}
char * identifier
The identifier.
Definition: TableColumn.h:66

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 39 of file TableView.c.

39 {
40
41 TableView *this = (TableView *) self;
42
43 release(this->columns);
44 release(this->contentView);
45 release(this->headerView);
46 release(this->rows);
47 release(this->scrollView);
48
49 super(Object, self, dealloc);
50}
static void dealloc(Object *self)
Definition: TableView.c:39

◆ deselectAll()

static void deselectAll ( TableView self)
static

Definition at line 296 of file TableView.c.

296 {
297 $((Array *) self->rows, enumerateObjects, deselectAll_enumerate, NULL);
298}
static void deselectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all Row deselection.
Definition: TableView.c:288
MutableArray * rows
The rows.
Definition: TableView.h:163

◆ deselectAll_enumerate()

static void deselectAll_enumerate ( const Array *  array,
ident  obj,
ident  data 
)
static

ArrayEnumerator for all Row deselection.

Definition at line 288 of file TableView.c.

288 {
289 $((TableRowView *) obj, setSelected, false);
290}
void setSelected(CollectionItemView *self, _Bool isSelected)
Sets the selected state of this item.

◆ deselectRowAtIndex()

static void deselectRowAtIndex ( TableView self,
size_t  index 
)
static

Definition at line 304 of file TableView.c.

304 {
305
306 const Array *rows = (Array *) self->rows;
307 if (index < rows->count) {
308
309 TableRowView *row = $(rows, objectAtIndex, index);
310 $(row, setSelected, false);
311 }
312}

◆ deselectRowsAtIndexes()

static void deselectRowsAtIndexes ( TableView self,
const IndexSet *  indexes 
)
static

Definition at line 318 of file TableView.c.

318 {
319
320 if (indexes) {
321 for (size_t i = 0; i < indexes->count; i++) {
322 $(self, deselectRowAtIndex, indexes->indexes[i]);
323 }
324 }
325}
void deselectRowAtIndex(TableView *self, size_t index)
Deselects the row at the given index.
Definition: TableView.c:304

◆ init()

static View * init ( View self)
static
See also
View::init(View *)

Definition at line 86 of file TableView.c.

86 {
87 return (View *) $((TableView *) self, initWithFrame, NULL);
88}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 574 of file TableView.c.

574 {
575
576 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
577
578 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
579 ((ViewInterface *) clazz->interface)->init = init;
580 ((ViewInterface *) clazz->interface)->layoutSubviews = layoutSubviews;
581 ((ViewInterface *) clazz->interface)->sizeThatFits = sizeThatFits;
582
583 ((ControlInterface *) clazz->interface)->captureEvent = captureEvent;
584
585 ((TableViewInterface *) clazz->interface)->addColumn = addColumn;
586 ((TableViewInterface *) clazz->interface)->addColumnWithIdentifier = addColumnWithIdentifier;
587 ((TableViewInterface *) clazz->interface)->columnAtPoint = columnAtPoint;
588 ((TableViewInterface *) clazz->interface)->columnWithIdentifier = columnWithIdentifier;
589 ((TableViewInterface *) clazz->interface)->deselectAll = deselectAll;
590 ((TableViewInterface *) clazz->interface)->deselectRowAtIndex = deselectRowAtIndex;
591 ((TableViewInterface *) clazz->interface)->deselectRowsAtIndexes = deselectRowsAtIndexes;
592 ((TableViewInterface *) clazz->interface)->initWithFrame = initWithFrame;
593 ((TableViewInterface *) clazz->interface)->naturalSize = naturalSize;
594 ((TableViewInterface *) clazz->interface)->reloadData = reloadData;
595 ((TableViewInterface *) clazz->interface)->removeColumn = removeColumn;
596 ((TableViewInterface *) clazz->interface)->rowAtPoint = rowAtPoint;
597 ((TableViewInterface *) clazz->interface)->selectedRowIndexes = selectedRowIndexes;
598 ((TableViewInterface *) clazz->interface)->selectAll = selectAll;
599 ((TableViewInterface *) clazz->interface)->selectRowAtIndex = selectRowAtIndex;
600 ((TableViewInterface *) clazz->interface)->selectRowsAtIndexes = selectRowsAtIndexes;
601 ((TableViewInterface *) clazz->interface)->setSortColumn = setSortColumn;
602}
void reloadData(CollectionView *self)
Reloads this CollectionView's visible items.
SDL_Size naturalSize(const CollectionView *self)
void selectAll(CollectionView *self)
Selects all items in this CollectionView.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
void removeColumn(TableView *self, TableColumn *column)
Removes the specified column from this table.
Definition: TableView.c:440
void addColumnWithIdentifier(TableView *self, const char *identifier)
Adds a new TableColumn with the given identifier to this table.
Definition: TableView.c:227
void deselectRowsAtIndexes(TableView *self, const IndexSet *indexes)
Definition: TableView.c:318
TableColumn * columnWithIdentifier(const TableView *self, const char *identifier)
Definition: TableView.c:269
void selectRowsAtIndexes(TableView *self, const IndexSet *indexes)
Selects the rows at the given indexes.
Definition: TableView.c:530
void sizeThatFits(const View *self)
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
Definition: Box.c:74

◆ initWithFrame()

static TableView * initWithFrame ( TableView self,
const SDL_Rect *  frame 
)
static

Definition at line 331 of file TableView.c.

331 {
332
333 self = (TableView *) super(Control, self, initWithFrame, frame);
334 if (self) {
335 self->columns = $$(MutableArray, array);
336 assert(self->columns);
337
338 self->rows = $$(MutableArray, array);
339 assert(self->rows);
340
341 self->headerView = $(alloc(TableHeaderView), initWithTableView, self);
342 assert(self->headerView);
343
344 $((View *) self, addSubview, (View *) self->headerView);
345
346 self->contentView = $(alloc(StackView), initWithFrame, NULL);
347 assert(self->contentView);
348
349 $((View *) self->contentView, addClassName, "contentView");
350
351 self->scrollView = $(alloc(ScrollView), initWithFrame, NULL);
352 assert(self->scrollView);
353
354 $(self->scrollView, setContentView, (View *) self->contentView);
355
356 $((View *) self, addSubview, (View *) self->scrollView);
357 }
358
359 return self;
360}
ScrollViews allow users to pan their internal contents.
Definition: ScrollView.h:62
void setContentView(ScrollView *self, View *contentView)
Sets the content view of this ScrollView.
Definition: ScrollView.c:150
StackViews are containers that manage the arrangement of their subviews.
Definition: StackView.h:68
The header row is a specialized TableRow depicting the TableColumn handles.
TableHeaderView * initWithTableView(TableHeaderView *self, TableView *tableView)
Initializes this TableHeaderView with the give table.
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35
void addClassName(View *self, const char *className)
Adds the given class name to this View.
Definition: View.c:120

◆ layoutSubviews()

static void layoutSubviews ( View self)
static
See also
View::layoutSubviews(View *)

Definition at line 93 of file TableView.c.

93 {
94
95 super(View, self, layoutSubviews);
96
97 TableView *this = (TableView *) self;
98
99 View *scrollView = (View *) this->scrollView;
100 View *headerView = (View *) this->headerView;
101
102 SDL_Rect frame = $(self, bounds);
103
104 if (headerView->hidden == false) {
105
106 const SDL_Size size = $(headerView, sizeThatFits);
107
108 frame.y += size.h;
109 frame.h -= size.h;
110 }
111
112 scrollView->frame = frame;
113}
SDL_Size size(const Image *self)
Definition: Image.c:181
The SDL_Size type.
Definition: Types.h:62
int h
Definition: Types.h:63
SDL_Rect bounds(const View *self)
Definition: View.c:394
_Bool hidden
If true, this View is not drawn.
Definition: View.h:195
SDL_Rect frame
The frame, relative to the superview.
Definition: View.h:190

◆ naturalSize()

static SDL_Size naturalSize ( const TableView self)
static

Definition at line 366 of file TableView.c.

366 {
367
368 const SDL_Size headerSize = $((View *) self->headerView, sizeThatFits);
369 const SDL_Size contentSize = $((View *) self->contentView, sizeThatFits);
370
371 SDL_Size size = MakeSize(max(headerSize.w, contentSize.w), headerSize.h + contentSize.h);
372
373 View *this = (View *) self;
374
375 size.w += this->padding.left + this->padding.right;
376 size.h += this->padding.top + this->padding.bottom;
377
378 return size;
379}
#define MakeSize(w, h)
Creates an SDL_Size with the given dimensions.
Definition: Types.h:79
SDL_Size contentSize(const Panel *self)
Definition: Panel.c:166
int w
Definition: Types.h:63
StackView * contentView
The content View.
Definition: TableView.h:143

◆ reloadData()

static void reloadData ( TableView self)
static

Definition at line 392 of file TableView.c.

392 {
393
394 assert(self->dataSource.numberOfRows);
395 assert(self->delegate.cellForColumnAndRow);
396
397 $(self->rows, removeAllObjectsWithEnumerator, reloadData_removeRows, self->contentView);
398
399 TableRowView *headerView = (TableRowView *) self->headerView;
400 $(headerView, removeAllCells);
401
402 const Array *columns = (Array *) self->columns;
403 for (size_t i = 0; i < columns->count; i++) {
404
405 const TableColumn *column = $(columns, objectAtIndex, i);
406 $(headerView, addCell, (TableCellView *) column->headerCell);
407 }
408
409 const size_t numberOfRows = self->dataSource.numberOfRows(self);
410 for (size_t i = 0; i < numberOfRows; i++) {
411
412 TableRowView *row = $(alloc(TableRowView), initWithTableView, self);
413 assert(row);
414
415 for (size_t j = 0; j < columns->count; j++) {
416 const TableColumn *column = $(columns, objectAtIndex, j);
417
418 TableCellView *cell = self->delegate.cellForColumnAndRow(self, column, i);
419 assert(cell);
420
421 cell->view.identifier = strdup(column->identifier);
422
423 $(row, addCell, cell);
424 release(cell);
425 }
426
427 $(self->rows, addObject, row);
428 release(row);
429
430 $((View *) self->contentView, addSubview, (View *) row);
431 }
432
433 self->control.view.needsLayout = true;
434}
static void reloadData_removeRows(const Array *array, ident obj, ident data)
ArrayEnumerator to remove TableRowViews from the table's contentView.
Definition: TableView.c:384
View view
The superclass.
Definition: Control.h:88
View view
The superclass.
Definition: TableCellView.h:46
void removeAllCells(TableRowView *self)
Removes all cells from this row.
Definition: TableRowView.c:111
size_t(* numberOfRows)(const TableView *tableView)
Definition: TableView.h:67
TableCellView *(* cellForColumnAndRow)(const TableView *tableView, const TableColumn *column, size_t row)
Called by the TableView to instantiate cells.
Definition: TableView.h:97
Control control
The superclass.
Definition: TableView.h:127
TableViewDelegate delegate
The delegate.
Definition: TableView.h:153
TableViewDataSource dataSource
The data source.
Definition: TableView.h:148
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition: View.h:221
char * identifier
An optional identifier.
Definition: View.h:201

◆ reloadData_removeRows()

static void reloadData_removeRows ( const Array *  array,
ident  obj,
ident  data 
)
static

ArrayEnumerator to remove TableRowViews from the table's contentView.

Definition at line 384 of file TableView.c.

384 {
385 $((View *) data, removeSubview, (View *) obj);
386}
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition: PageView.c:58

◆ removeColumn()

static void removeColumn ( TableView self,
TableColumn column 
)
static

Definition at line 440 of file TableView.c.

440 {
441
442 assert(column);
443
444 if (self->sortColumn == column) {
445 self->sortColumn->order = OrderSame;
446 self->sortColumn = NULL;
447 }
448
449 $(self->columns, removeObject, column);
450
451 $((TableRowView *) self->headerView, removeCell, (TableCellView *) column->headerCell);
452}
Order order
The sort order.
Definition: TableColumn.h:71
void removeCell(TableRowView *self, TableCellView *cell)
Removes the specified cell from this row.
Definition: TableRowView.c:119
TableColumn * sortColumn
The column to sort by.
Definition: TableView.h:173

◆ rowAtPoint()

static ssize_t rowAtPoint ( const TableView self,
const SDL_Point *  point 
)
static

Definition at line 458 of file TableView.c.

458 {
459
460 const SDL_Rect scrollFrame = $((View *) self->scrollView, renderFrame);
461 if (SDL_PointInRect(point, &scrollFrame)) {
462
463 const Array *rows = (Array *) self->rows;
464 for (size_t i = 0; i < rows->count; i++) {
465
466 const View *row = $(rows, objectAtIndex, i);
467 if ($(row, containsPoint, point)) {
468 return i;
469 }
470 }
471 }
472
473 return -1;
474}
ScrollView * scrollView
The scroll view.
Definition: TableView.h:168
_Bool containsPoint(const View *self, const SDL_Point *point)
Definition: View.c:472

◆ selectAll()

static void selectAll ( TableView self)
static

Definition at line 487 of file TableView.c.

487 {
488 $((Array *) self->rows, enumerateObjects, selectAll_enumerate, NULL);
489}
static void selectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all row selection.
Definition: TableView.c:479

◆ selectAll_enumerate()

static void selectAll_enumerate ( const Array *  array,
ident  obj,
ident  data 
)
static

ArrayEnumerator for all row selection.

Definition at line 479 of file TableView.c.

479 {
480 $((TableRowView *) obj, setSelected, true);
481}

◆ selectedRowIndexes()

static IndexSet * selectedRowIndexes ( const TableView self)
static

Definition at line 495 of file TableView.c.

495 {
496
497 size_t indexes[self->rows->array.count];
498 size_t count = 0;
499
500 const Array *rows = (Array *) self->rows;
501 for (size_t i = 0; i < rows->count; i++) {
502
503 const TableRowView *row = $(rows, objectAtIndex, i);
504 if (row->isSelected) {
505 indexes[count++] = i;
506 }
507 }
508
509 return $(alloc(IndexSet), initWithIndexes, indexes, count);
510}

◆ selectRowAtIndex()

static void selectRowAtIndex ( TableView self,
size_t  index 
)
static

Definition at line 516 of file TableView.c.

516 {
517
518 const Array *rows = (Array *) self->rows;
519 if (index < rows->count) {
520
521 TableRowView *row = $(rows, objectAtIndex, index);
522 $(row, setSelected, true);
523 }
524}

◆ selectRowsAtIndexes()

static void selectRowsAtIndexes ( TableView self,
const IndexSet *  indexes 
)
static

Definition at line 530 of file TableView.c.

530 {
531
532 if (indexes) {
533 for (size_t i = 0; i < indexes->count; i++) {
534 $(self, selectRowAtIndex, indexes->indexes[i]);
535 }
536 }
537}

◆ setSortColumn()

static void setSortColumn ( TableView self,
TableColumn column 
)
static

Definition at line 543 of file TableView.c.

543 {
544
545 if (self->sortColumn != column) {
546
547 if (self->sortColumn) {
548 self->sortColumn->order = OrderSame;
549 self->sortColumn = NULL;
550 }
551
552 if (column) {
553 assert($((Array *) self->columns, containsObject, column));
554
555 self->sortColumn = column;
556 self->sortColumn->order = OrderAscending;
557 }
558 } else {
559 if (self->sortColumn) {
560 self->sortColumn->order = -self->sortColumn->order;
561 }
562 }
563
564 if (self->delegate.didSetSortColumn) {
565 self->delegate.didSetSortColumn(self);
566 }
567}
void(* didSetSortColumn)(TableView *tableView)
Called by the TableView when the sort column or order changes.
Definition: TableView.h:114

◆ sizeThatFits()

static SDL_Size sizeThatFits ( const View self)
static
See also
View::sizeThatFits(const View *)

Definition at line 118 of file TableView.c.

118 {
119
120 const TableView *this = (TableView *) self;
121
122 return $(this, naturalSize);
123}