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.
 
TableColumn * columnAtPoint (const TableView *self, const SDL_Point *point)
 
TableColumn * columnWithIdentifier (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)
 
TableView * initWithFrame (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)
 
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

Array * columns
 The column definitions.
 
StackView * contentView
 The content View.
 
Control control
 The superclass.
 
TableViewDataSource dataSource
 The data source.
 
TableViewDelegate delegate
 The delegate.
 
TableHeaderView * headerView
 The header.
 
Array * rows
 The rows.
 
ScrollView * scrollView
 The scroll view.
 
TableColumn * sortColumn
 The column to sort by.
 
- 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

TableViewInterface * 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

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 618 of file TableView.c.

618 {
619 static Class *clazz;
620 static Once once;
621
622 do_once(&once, {
623 clazz = _initialize(&(const ClassDef) {
624 .name = "TableView",
625 .superclass = _Control(),
626 .instanceSize = sizeof(TableView),
627 .interfaceSize = sizeof(TableViewInterface),
628 .initialize = initialize,
629 });
630 });
631
632 return clazz;
633}
static void initialize(Class *clazz)
Definition AtlasImage.c:74
Class * _Control(void)
The Control archetype.
Definition Control.c:414
TableViews provide sortable, tabular presentations of data.
Definition TableView.h:122

◆ addColumn()

void addColumn ( TableView *  self,
TableColumn *  column 
)

Adds the specified column to this table.

Parameters
selfThe TableView.
columnThe column.

Definition at line 222 of file TableView.c.

222 {
223
224 assert(column);
225
226 $(self->columns, addObject, column);
227
228 $((TableRowView *) self->headerView, addCell, (TableCellView *) column->headerCell);
229}
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 235 of file TableView.c.

235 {
236
238 assert(column);
239
240 $(self, addColumn, column);
241
242 release(column);
243}
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:222
char * identifier
An optional identifier.
Definition View.h:333

◆ 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 249 of file TableView.c.

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

◆ 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 277 of file TableView.c.

277 {
278
279 assert(identifier);
280
281 const Array *columns = (Array *) self->columns;
282 for (size_t i = 0; i < columns->count; i++) {
283
284 TableColumn *column = $(columns, objectAtIndex, i);
285 if (strcmp(identifier, column->identifier) == 0) {
286 return column;
287 }
288 }
289
290 return NULL;
291}
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 304 of file TableView.c.

304 {
305 $((Array *) self->rows, enumerate, deselectAll_enumerate, NULL);
306}
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 312 of file TableView.c.

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

◆ deselectRowsAtIndexes()

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

Definition at line 326 of file TableView.c.

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

◆ 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 339 of file TableView.c.

339 {
340
341 self = (TableView *) super(Control, self, initWithFrame, frame);
342 if (self) {
343 self->columns = $$(Array, array);
344 assert(self->columns);
345
346 self->rows = $$(Array, array);
347 assert(self->rows);
348
349 self->headerView = $(alloc(TableHeaderView), initWithTableView, self);
350 assert(self->headerView);
351
352 $((View *) self, addSubview, (View *) self->headerView);
353
354 self->contentView = $(alloc(StackView), initWithFrame, NULL);
355 assert(self->contentView);
356
357 $((View *) self->contentView, addClassName, "contentView");
358
359 self->scrollView = $(alloc(ScrollView), initWithFrame, NULL);
360 assert(self->scrollView);
361
362 $(self->scrollView, setContentView, (View *) self->contentView);
363
364 $((View *) self, addSubview, (View *) self->scrollView);
365 }
366
367 return self;
368}
static void setContentView(ScrollView *self, View *contentView)
Definition ScrollView.c:231
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:61
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:339
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

◆ 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 374 of file TableView.c.

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

400 {
401
402 assert(self->dataSource.numberOfRows);
403 assert(self->delegate.cellForColumnAndRow);
404
405 $(self->rows, removeAllObjectsWithEnumerator, reloadData_removeRows, self->contentView);
406
409
410 const Array *columns = (Array *) self->columns;
411 for (size_t i = 0; i < columns->count; i++) {
412
413 const TableColumn *column = $(columns, objectAtIndex, i);
415 }
416
417 const size_t numberOfRows = self->dataSource.numberOfRows(self);
418 for (size_t i = 0; i < numberOfRows; i++) {
419
420 TableRowView *row = $(alloc(TableRowView), initWithTableView, self);
421 assert(row);
422
423 for (size_t j = 0; j < columns->count; j++) {
424 const TableColumn *column = $(columns, objectAtIndex, j);
425
426 TableCellView *cell = self->delegate.cellForColumnAndRow(self, column, i);
427 assert(cell);
428
429 cell->view.identifier = strdup(column->identifier);
430
431 $(row, addCell, cell);
432 release(cell);
433 }
434
435 $(self->rows, addObject, row);
436 release(row);
437
438 $((View *) self->contentView, addSubview, (View *) row);
439 }
440
441 $((View *) self, setNeedsLayout);
442}
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:392
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
TableViewDelegate delegate
The delegate.
Definition TableView.h:153
TableViewDataSource dataSource
The data source.
Definition TableView.h:148
void setNeedsLayout(View *self)
Marks this View as needing layout before it is next drawn.
Definition View.c:1865

◆ removeColumn()

void removeColumn ( TableView *  self,
TableColumn *  column 
)

Removes the specified column from this table.

Parameters
selfThe TableView.
columnThe column.

Definition at line 448 of file TableView.c.

448 {
449
450 assert(column);
451
452 if (self->sortColumn == column) {
453 self->sortColumn->order = OrderSame;
454 self->sortColumn = NULL;
455 }
456
457 $(self->columns, removeObject, column);
458
459 $((TableRowView *) self->headerView, removeCell, (TableCellView *) column->headerCell);
460}
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 466 of file TableView.c.

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

◆ selectAll()

void selectAll ( TableView *  self)

Selects all rows in this TableView.

Parameters
selfThe TableView.

Definition at line 495 of file TableView.c.

495 {
496 $((Array *) self->rows, enumerate, selectAll_enumerate, NULL);
497}
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 503 of file TableView.c.

503 {
504
505 size_t indexes[self->rows->count];
506 size_t count = 0;
507
508 const Array *rows = (Array *) self->rows;
509 for (size_t i = 0; i < rows->count; i++) {
510
511 const TableRowView *row = $(rows, objectAtIndex, i);
512 if (row->isSelected) {
513 indexes[count++] = i;
514 }
515 }
516
517 return $(alloc(IndexSet), initWithIndexes, indexes, count);
518}
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 524 of file TableView.c.

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

◆ 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 540 of file TableView.c.

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

◆ setSortColumn()

void setSortColumn ( TableView *  self,
TableColumn *  column 
)

Sets the sort column for this table.

Parameters
selfThe TableView.
columnThe sort column.

Definition at line 553 of file TableView.c.

553 {
554
555 if (self->sortColumn != column) {
556
557 if (self->sortColumn) {
558 self->sortColumn->order = OrderSame;
559 self->sortColumn = NULL;
560 }
561
562 if (column) {
563 assert($((Array *) self->columns, containsObject, column));
564
565 self->sortColumn = column;
566 self->sortColumn->order = OrderAscending;
567 }
568 } else {
569 if (self->sortColumn) {
570 self->sortColumn->order = (Order) -self->sortColumn->order;
571 }
572 }
573
574 if (self->delegate.didSetSortColumn) {
575 self->delegate.didSetSortColumn(self);
576 }
577}
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[0]
protected

The interface type.

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: