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

TableViews provide sortable, tabular presentations of data. More...

#include <TableView.h>

Inheritance diagram for TableView:
Control View

Public Member Functions

Class * _TableView (void)
 The TableView archetype.
 
void addColumn (TableView *self, TableColumn *column)
 Adds the specified column to this table.
 
void addColumnWithIdentifier (TableView *self, const char *identifier)
 Adds a new TableColumn with the given identifier to this table.
 
TableColumncolumnAtPoint (const TableView *self, const SDL_Point *point)
 
TableColumncolumnWithIdentifier (const TableView *self, const char *identifier)
 
void deselectAll (TableView *self)
 Deselects all rows in this TableView.
 
void deselectItemsAtIndexSets (TableView *self, const IndexSet *indexSet)
 Deselects the rows at the given indexes.
 
void deselectRowAtIndex (TableView *self, size_t index)
 Deselects the row at the given index.
 
void deselectRowsAtIndexes (TableView *self, const IndexSet *indexes)
 
TableViewinitWithFrame (TableView *self, const SDL_Rect *frame)
 Initializes this TableView with the specified frame and style.
 
SDL_Size naturalSize (const TableView *self)
 
void reloadData (TableView *self)
 Reloads this TableView's visible rows.
 
void removeColumn (TableView *self, TableColumn *column)
 Removes the specified column from this table.
 
ssize_t rowAtPoint (const TableView *self, const SDL_Point *point)
 
void selectAll (TableView *self)
 Selects all rows in this TableView.
 
IndexSet * selectedRowIndexes (const TableView *self)
 
void selectRowAtIndex (TableView *self, size_t index)
 Selects the row at the given index.
 
void selectRowsAtIndexes (TableView *self, const IndexSet *indexes)
 Selects the rows at the given indexes.
 
void setSortColumn (TableView *self, TableColumn *column)
 Sets the sort column for this table.
 
- 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

Array * columns
 The column definitions.
 
StackViewcontentView
 The content View.
 
Control control
 The superclass.
 
TableViewDataSource dataSource
 The data source.
 
TableViewDelegate delegate
 The delegate.
 
TableHeaderViewheaderView
 The header.
 
Array * rows
 The rows.
 
ScrollViewscrollView
 The scroll view.
 
TableColumnsortColumn
 The column to sort by.
 
- 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

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

Detailed Description

TableViews provide sortable, tabular presentations of data.

Definition at line 122 of file TableView.h.

Member Function Documentation

◆ _TableView()

Class * _TableView ( void  )

The TableView archetype.

Returns
The TableView Class.

Definition at line 614 of file TableView.c.

614 {
615 static Class *clazz;
616 static Once once;
617
618 do_once(&once, {
619 clazz = _initialize(&(const ClassDef) {
620 .name = "TableView",
621 .superclass = _Control(),
622 .instanceSize = sizeof(TableView),
623 .interfaceOffset = offsetof(TableView, interface),
624 .interfaceSize = sizeof(TableViewInterface),
626 });
627 });
628
629 return clazz;
630}
static void initialize(Class *clazz)
Definition Box.c:123
Class * _Control(void)
The Control archetype.
Definition Control.c:391
TableViews provide sortable, tabular presentations of data.
Definition TableView.h:122
TableViewInterface * interface
The interface.
Definition TableView.h:133

◆ addColumn()

void addColumn ( TableView self,
TableColumn column 
)

Adds the specified column to this table.

Parameters
selfThe TableView.
columnThe column.

Definition at line 218 of file TableView.c.

218 {
219
220 assert(column);
221
222 $(self->columns, addObject, column);
223
224 $((TableRowView *) self->headerView, addCell, (TableCellView *) column->headerCell);
225}
static void addCell(TableRowView *self, TableCellView *cell)
Each row in a TableView is comprised of TableCellViews.
TableHeaderCellView * headerCell
The header cell.
Definition TableColumn.h:61
Rows for TableViews.
Array * columns
The column definitions.
Definition TableView.h:138
TableHeaderView * headerView
The header.
Definition TableView.h:158

◆ addColumnWithIdentifier()

void addColumnWithIdentifier ( TableView self,
const char *  identifier 
)

Adds a new TableColumn with the given identifier to this table.

Parameters
selfThe TableView.
identifierThe column identifier.

Definition at line 231 of file TableView.c.

231 {
232
234 assert(column);
235
236 $(self, addColumn, column);
237
238 release(column);
239}
static TableColumn * initWithIdentifier(TableColumn *self, const char *identifier)
Definition TableColumn.c:56
Columns provide alignment, spacing and sorting hints for TableView instances.
Definition TableColumn.h:45
void addColumn(TableView *self, TableColumn *column)
Adds the specified column to this table.
Definition TableView.c:218
char * identifier
An optional identifier.
Definition View.h:202

◆ columnAtPoint()

TableColumn * columnAtPoint ( const TableView self,
const SDL_Point *  point 
)
Parameters
selfThe TableView.
pointA point in window coordinate space.
Returns
The column at the specified point.

Definition at line 245 of file TableView.c.

245 {
246
247 const SDL_Rect frame = $((View *) self, renderFrame);
248 if (SDL_PointInRect(point, &frame)) {
249
250 const Array *cells = (Array *) self->headerView->tableRowView.cells;
251 const Array *columns = (Array *) self->columns;
252
253 assert(cells->count == columns->count);
254
255 for (size_t i = 0; i < cells->count; i++) {
256
257 const View *cell = $(cells, objectAtIndex, i);
258 const SDL_Rect renderFrame = $(cell, renderFrame);
259
260 if (renderFrame.x + renderFrame.w >= point->x) {
261 return $(columns, objectAtIndex, i);
262 }
263 }
264 }
265
266 return NULL;
267}
TableRowView tableRowView
The superclass.
Array * cells
The cells.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134
SDL_Rect renderFrame(const View *self)
Definition View.c:1455
SDL_Rect frame
The frame, relative to the superview.
Definition View.h:191

◆ columnWithIdentifier()

TableColumn * columnWithIdentifier ( const TableView self,
const char *  identifier 
)
Parameters
selfThe TableView.
identifierThe column identifier.
Returns
The TableColumn with the specified identifier, or NULL if not found.

Definition at line 273 of file TableView.c.

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

◆ deselectAll()

void deselectAll ( TableView self)

Deselects all rows in this TableView.

Parameters
selfThe TableView.

Definition at line 300 of file TableView.c.

300 {
301 $((Array *) self->rows, enumerate, deselectAll_enumerate, NULL);
302}
static void deselectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all item deselection.
Array * rows
The rows.
Definition TableView.h:163
void enumerate(const View *self, ViewEnumerator enumerator, ident data)

◆ deselectItemsAtIndexSets()

void deselectItemsAtIndexSets ( TableView self,
const IndexSet *  indexSet 
)

Deselects the rows at the given indexes.

Parameters
selfThe TableView.
indexSetThe index set of the rows to deselect.

◆ deselectRowAtIndex()

void deselectRowAtIndex ( TableView self,
size_t  index 
)

Deselects the row at the given index.

Parameters
selfThe TableView.
indexThe index of the row to deselect.

Definition at line 308 of file TableView.c.

308 {
309
310 const Array *rows = (Array *) self->rows;
311 if (index < rows->count) {
312
313 TableRowView *row = $(rows, objectAtIndex, index);
314 $(row, setSelected, false);
315 }
316}
static void setSelected(CollectionItemView *self, bool isSelected)

◆ deselectRowsAtIndexes()

void deselectRowsAtIndexes ( TableView self,
const IndexSet *  indexes 
)

Definition at line 322 of file TableView.c.

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

◆ initWithFrame()

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

Initializes this TableView with the specified frame and style.

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

Definition at line 335 of file TableView.c.

335 {
336
337 self = (TableView *) super(Control, self, initWithFrame, frame);
338 if (self) {
339 self->columns = $$(Array, array);
340 assert(self->columns);
341
342 self->rows = $$(Array, array);
343 assert(self->rows);
344
345 self->headerView = $(alloc(TableHeaderView), initWithTableView, self);
346 assert(self->headerView);
347
348 $((View *) self, addSubview, (View *) self->headerView);
349
350 self->contentView = $(alloc(StackView), initWithFrame, NULL);
351 assert(self->contentView);
352
353 $((View *) self->contentView, addClassName, "contentView");
354
355 self->scrollView = $(alloc(ScrollView), initWithFrame, NULL);
356 assert(self->scrollView);
357
358 $(self->scrollView, setContentView, (View *) self->contentView);
359
360 $((View *) self, addSubview, (View *) self->scrollView);
361 }
362
363 return self;
364}
static void setContentView(ScrollView *self, View *contentView)
Definition ScrollView.c:148
static TableHeaderView * initWithTableView(TableHeaderView *self, TableView *tableView)
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
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.
TableView * initWithFrame(TableView *self, const SDL_Rect *frame)
Initializes this TableView with the specified frame and style.
Definition TableView.c:335
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

◆ naturalSize()

SDL_Size naturalSize ( const TableView self)
Parameters
selfThe TableView.
Returns
The natural size of this TableView, including all header and content rows.

Definition at line 370 of file TableView.c.

370 {
371
372 const SDL_Size headerSize = $((View *) self->headerView, sizeThatFits);
373 const SDL_Size contentSize = $((View *) self->contentView, sizeThatFits);
374
375 SDL_Size size = MakeSize(max(headerSize.w, contentSize.w), headerSize.h + contentSize.h);
376
377 View *this = (View *) self;
378
379 size.w += this->padding.left + this->padding.right;
380 size.h += this->padding.top + this->padding.bottom;
381
382 return size;
383}
static SDL_Size contentSize(const Panel *self)
Definition Panel.c:195
StackView * contentView
The content View.
Definition TableView.h:143
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
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 ( TableView self)

Reloads this TableView's visible rows.

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

Definition at line 396 of file TableView.c.

396 {
397
398 assert(self->dataSource.numberOfRows);
399 assert(self->delegate.cellForColumnAndRow);
400
401 $(self->rows, removeAllObjectsWithEnumerator, reloadData_removeRows, self->contentView);
402
405
406 const Array *columns = (Array *) self->columns;
407 for (size_t i = 0; i < columns->count; i++) {
408
409 const TableColumn *column = $(columns, objectAtIndex, i);
411 }
412
413 const size_t numberOfRows = self->dataSource.numberOfRows(self);
414 for (size_t i = 0; i < numberOfRows; i++) {
415
416 TableRowView *row = $(alloc(TableRowView), initWithTableView, self);
417 assert(row);
418
419 for (size_t j = 0; j < columns->count; j++) {
420 const TableColumn *column = $(columns, objectAtIndex, j);
421
422 TableCellView *cell = self->delegate.cellForColumnAndRow(self, column, i);
423 assert(cell);
424
425 cell->view.identifier = strdup(column->identifier);
426
427 $(row, addCell, cell);
428 release(cell);
429 }
430
431 $(self->rows, addObject, row);
432 release(row);
433
434 $((View *) self->contentView, addSubview, (View *) row);
435 }
436
437 self->control.view.needsLayout = true;
438}
static void removeAllCells(TableRowView *self)
static void reloadData_removeRows(const Array *array, ident obj, ident data)
ArrayEnumerator to remove TableRowViews from the table's contentView.
Definition TableView.c:388
View view
The superclass.
Definition Control.h:88
View view
The superclass.
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:222

◆ removeColumn()

void removeColumn ( TableView self,
TableColumn column 
)

Removes the specified column from this table.

Parameters
selfThe TableView.
columnThe column.

Definition at line 444 of file TableView.c.

444 {
445
446 assert(column);
447
448 if (self->sortColumn == column) {
449 self->sortColumn->order = OrderSame;
450 self->sortColumn = NULL;
451 }
452
453 $(self->columns, removeObject, column);
454
455 $((TableRowView *) self->headerView, removeCell, (TableCellView *) column->headerCell);
456}
static void removeCell(TableRowView *self, TableCellView *cell)
Order order
The sort order.
Definition TableColumn.h:71
TableColumn * sortColumn
The column to sort by.
Definition TableView.h:173

◆ rowAtPoint()

int rowAtPoint ( const TableView self,
const SDL_Point *  point 
)
Parameters
selfThe TableView.
pointA point in window coordinate space.
Returns
The row index at the specified point, or -1 if none.

Definition at line 462 of file TableView.c.

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

◆ selectAll()

void selectAll ( TableView self)

Selects all rows in this TableView.

Parameters
selfThe TableView.

Definition at line 491 of file TableView.c.

491 {
492 $((Array *) self->rows, enumerate, selectAll_enumerate, NULL);
493}
static void selectAll_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for all item selection.

◆ selectedRowIndexes()

Array * selectedRowIndexes ( const TableView self)
Parameters
selfThe TableView.
Returns
An IndexSet containing the indices of all selected rows.

Definition at line 499 of file TableView.c.

499 {
500
501 size_t indexes[self->rows->count];
502 size_t count = 0;
503
504 const Array *rows = (Array *) self->rows;
505 for (size_t i = 0; i < rows->count; i++) {
506
507 const TableRowView *row = $(rows, objectAtIndex, i);
508 if (row->isSelected) {
509 indexes[count++] = i;
510 }
511 }
512
513 return $(alloc(IndexSet), initWithIndexes, indexes, count);
514}
bool isSelected
True when this row is selected, false otherwise.

◆ selectRowAtIndex()

void selectRowAtIndex ( TableView self,
size_t  index 
)

Selects the row at the given index.

Parameters
selfThe TableView.
indexThe index of the row to select.

Definition at line 520 of file TableView.c.

520 {
521
522 const Array *rows = (Array *) self->rows;
523 if (index < rows->count) {
524
525 TableRowView *row = $(rows, objectAtIndex, index);
526 if (!row->isSelected) {
527 $(row, setSelected, true);
528 }
529 }
530}

◆ selectRowsAtIndexes()

void selectRowsAtIndexes ( TableView self,
const IndexSet *  indexes 
)

Selects the rows at the given indexes.

Parameters
indexesThe indexes of the rows to selec
selfThe TableView.t.

Definition at line 536 of file TableView.c.

536 {
537
538 if (indexes) {
539 for (size_t i = 0; i < indexes->count; i++) {
540 $(self, selectRowAtIndex, indexes->indexes[i]);
541 }
542 }
543}
void selectRowAtIndex(TableView *self, size_t index)
Selects the row at the given index.
Definition TableView.c:520

◆ setSortColumn()

void setSortColumn ( TableView self,
TableColumn column 
)

Sets the sort column for this table.

Parameters
selfThe TableView.
columnThe sort column.

Definition at line 549 of file TableView.c.

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

Field Documentation

◆ columns

Array* TableView::columns

The column definitions.

Definition at line 138 of file TableView.h.

◆ contentView

StackView* TableView::contentView

The content View.

Definition at line 143 of file TableView.h.

◆ control

Control TableView::control

The superclass.

Definition at line 127 of file TableView.h.

◆ dataSource

TableViewDataSource TableView::dataSource

The data source.

Definition at line 148 of file TableView.h.

◆ delegate

TableViewDelegate TableView::delegate

The delegate.

Definition at line 153 of file TableView.h.

◆ headerView

TableHeaderView* TableView::headerView

The header.

Definition at line 158 of file TableView.h.

◆ interface

TableViewInterface* TableView::interface
protected

The interface.

Definition at line 133 of file TableView.h.

◆ rows

Array* TableView::rows

The rows.

Definition at line 163 of file TableView.h.

◆ scrollView

ScrollView* TableView::scrollView

The scroll view.

Definition at line 168 of file TableView.h.

◆ sortColumn

TableColumn* TableView::sortColumn

The column to sort by.

Definition at line 173 of file TableView.h.


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