ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Public Member Functions | Data Fields | Protected Attributes
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. More...
 
void addColumn (TableView *self, TableColumn *column)
 Adds the specified column to this table. More...
 
void addColumnWithIdentifier (TableView *self, const char *identifier)
 Adds a new TableColumn with the given identifier to this table. More...
 
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. More...
 
void deselectItemsAtIndexSets (TableView *self, const IndexSet *indexSet)
 Deselects the rows at the given indexes. More...
 
void deselectRowAtIndex (TableView *self, size_t index)
 Deselects the row at the given index. More...
 
void deselectRowsAtIndexes (TableView *self, const IndexSet *indexes)
 
TableViewinitWithFrame (TableView *self, const SDL_Rect *frame)
 Initializes this TableView with the specified frame and style. More...
 
SDL_Size naturalSize (const TableView *self)
 
void reloadData (TableView *self)
 Reloads this TableView's visible rows. More...
 
void removeColumn (TableView *self, TableColumn *column)
 Removes the specified column from this table. More...
 
ssize_t rowAtPoint (const TableView *self, const SDL_Point *point)
 
void selectAll (TableView *self)
 Selects all rows in this TableView. More...
 
IndexSet * selectedRowIndexes (const TableView *self)
 
void selectRowAtIndex (TableView *self, size_t index)
 Selects the row at the given index. More...
 
void selectRowsAtIndexes (TableView *self, const IndexSet *indexes)
 Selects the rows at the given indexes. More...
 
void setSortColumn (TableView *self, TableColumn *column)
 Sets the sort column for this table. More...
 
- Public Member Functions inherited from Control
Class * _Control (void)
 The Control archetype. More...
 
Array * actionsForEvent (const Control *self, const SDL_Event *event)
 
void addActionForEventType (Control *self, SDL_EventType eventType, ActionFunction function, ident sender, ident data)
 Adds an Action for the given event type to this Control. More...
 
_Bool captureEvent (Control *self, const SDL_Event *event)
 Captures a given event, potentially altering the state of this Control. More...
 
Control initWithFrame (Control *self, const SDL_Rect *frame)
 Initializes this Control with the specified frame and style. More...
 
_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. More...
 
- Public Member Functions inherited from View
Class * _View (void)
 The View archetype. More...
 
_Bool acceptsFirstResponder (const View *self)
 
void addClassName (View *self, const char *className)
 Adds the given class name to this View. More...
 
void addSubview (View *self, View *subview)
 Adds a subview to this view, to be drawn above its siblings. More...
 
void addSubviewRelativeTo (View *self, View *subview, View *other, ViewPosition position)
 Adds a subview to this view, positioned relatively to other. More...
 
 ancestorWithIdentifier (const View *self, const char *identifier)
 
void applyStyle (View *self, const Style *style)
 Applies the given Style to this View. More...
 
void applyTheme (View *self, const Theme *theme)
 Applies the given Theme to this View. More...
 
void applyThemeIfNeeded (View *self, const Theme *theme)
 Recursively applies the Theme to this View and its subviews. More...
 
void attachStylesheet (View *self, SDL_Window *window)
 Attaches this View's Stylesheet to the Theme associated with the given window. More...
 
void awakeWithCharacters (View *self, const char *chars)
 Wakes this View with the given null-terminated JSON C string. More...
 
void awakeWithData (View *self, const Data *data)
 Wakes this View with the specified JSON Data. More...
 
void awakeWithDictionary (View *self, const Dictionary *dictionary)
 Wakes this View with the specified Dictionary. More...
 
void awakeWithResource (View *self, const Resource *resource)
 Wakes this View with the specified Resource. More...
 
void awakeWithResourceName (View *self, const char *name)
 Wakes this View with the Resource by the specified name. More...
 
void becomeFirstResponder (View *self)
 Become the first responder in the View hierarchy. More...
 
_Bool bind (View *self, const Inlet *inlets, const Dictionary *dictionary)
 Performs data binding for the Inlets described in dictionary. More...
 
SDL_Rect bounds (const View *self)
 
void bringSubviewToFront (View *self, View *subview)
 Brings the specified subview to the front. More...
 
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. More...
 
void didMoveToWindow (View *self, SDL_Window *window)
 Informs this View that it has been added to the View hierachy of the given window. More...
 
_Bool didReceiveEvent (const View *self, const SDL_Event *event)
 
void * draw (View *self, Renderer *renderer)
 Draws this View. More...
 
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. More...
 
void enumerateAdjacent (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates adjacent siblings of this View, applying enumerator to each. More...
 
void enumerateAncestors (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all ancestors of this View, applying enumerator to each. More...
 
void enumerateDescendants (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all descendants of this View, applying enumerator to each. More...
 
void enumerateSelection (View *self, const char *rule, ViewEnumerator enumerator, ident data)
 Enumerates all Views in the selection matched by rule, applying enumerator to each. More...
 
void enumerateSiblings (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all siblings of this View, applying enumerator to each. More...
 
void enumerateSubviews (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all subviews of this View, applying enumerator to each. More...
 
void enumerateSuperview (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates the superview of this View, if any, applying enumerator to it. More...
 
ViewfirstResponder (SDL_Window *window)
 
_Bool hasClassName (const View *self, cosnt char *className)
 
ViewhitTest (const View *self, const SDL_Point *point)
 Performs a hit test against this View and its descendants for the given point. More...
 
Viewinit (View *self)
 Initializes this View. More...
 
ViewinitWithFrame (View *self, const SDL_Rect *frame)
 Initializes this View with the specified frame. More...
 
void invalidateStyle (View *self)
 Invalidates the computed Style for this View and its descendants. More...
 
_Bool isContainer (const View *self)
 
_Bool isDescendantOfView (const View *self, const View *view)
 
_Bool isFirstResponder (const View *self)
 
_Bool isVisible (const View *self)
 
void layoutIfNeeded (View *self)
 Recursively updates the layout of this View and its subviews. More...
 
 layoutSubviews (View *self)
 Performs layout for this View's immediate subviews. More...
 
_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. More...
 
String * path (const View *self)
 
void removeAllClassNames (View *self)
 Removes all class names from this View. More...
 
void removeAllSubviews (View *self)
 Removes all subviews from this View. More...
 
void removeClassName (View *self, const char *className)
 Removes the given class name to this View. More...
 
void removeFromSuperview (View *self)
 Removes this View from its superview. More...
 
void removeSubview (View *self, View *subview)
 Removes the given subview from this View. More...
 
void render (View *self, Renderer *renderer)
 Renders this View using the given renderer. More...
 
void renderDeviceDidReset (View *self)
 Informs this View that the render device has reset. More...
 
void renderDeviceWillReset (View *self)
 Informs this View that the render device will reset. More...
 
SDL_Rect renderFrame (const View *self)
 
void replaceSubview (View *self, View *subview, View *replacement)
 Replaces the specified subview with the given replacement. More...
 
void resignFirstResponder (View *self)
 Resigns first responder priority. More...
 
void resize (View *self, const SDL_Size *size)
 Resizes this View to the specified size. More...
 
void resolve (View *self, Outlet *outlets)
 Resolves the given Outlets from this View's hierarchy. More...
 
void respondToEvent (View *self, const SDL_Event *event)
 Responds to the specified event. More...
 
Set * select (View *self, const char *rule)
 Resolves all descendants (including this View) that match the given Selector rule. More...
 
void setFirstResponder (SDL_Window *window, View *view)
 Sets the first responder for the given window. More...
 
SDL_Size size (const View *self)
 
SDL_Size sizeThatContains (const View *self)
 
void sizeThatFits (const View *self)
 
void sizeToContain (View *self)
 Resizes this View to contain its subviews. More...
 
void sizeToFit (View *self)
 Resizes this View to fit its subviews. More...
 
 subviewWithIdentifier (const View *self, const char *identifier)
 
void updateBindings (View *self)
 Updates data bindings, prompting the appropriate layout changes. More...
 
SDL_Rect viewport (const View *self)
 
ViewviewWithCharacters (const char *chars, Outlet *outlets)
 Instantiates a View initialized with the given null-terminated JSON C string. More...
 
ViewviewWithData (const Data *data, Outlet *outlets)
 Instantiates a View initialized with the contents of data. More...
 
ViewviewWithDictionary (const Dictionary *dictionary, Outlet *outlets)
 Instantiates a View initialized with the attributes described in dictionary. More...
 
ViewviewWithResource (const Resource *resource, Outlet *outlets)
 Instantiates a View initialized with the JSON data in resource. More...
 
ViewviewWithResourceName (const char *name, Outlet *outlets)
 Instantiates a View initialized with the JSON Resource with the specified name. More...
 
Array * visibleSubviews (const View *self)
 
void warn (View *self, const char *fmt,...)
 Appends a warning for this View. More...
 
void willMoveToWindow (View *self, SDL_Window *window)
 Informs this View that it will be added to the View hierarchy for the given window. More...
 

Data Fields

MutableArray * columns
 The column definitions. More...
 
StackViewcontentView
 The content View. More...
 
Control control
 The superclass. More...
 
TableViewDataSource dataSource
 The data source. More...
 
TableViewDelegate delegate
 The delegate. More...
 
TableHeaderViewheaderView
 The header. More...
 
MutableArray * rows
 The rows. More...
 
ScrollViewscrollView
 The scroll view. More...
 
TableColumnsortColumn
 The column to sort by. More...
 
- Data Fields inherited from Control
ControlBevel bevel
 The ControlBevel. More...
 
ControlSelection selection
 The ControlSelection. More...
 
unsigned int state
 The bit mask of ControlState. More...
 
View view
 The superclass. More...
 
- Data Fields inherited from View
ViewAlignment alignment
 The alignment. More...
 
int autoresizingMask
 The ViewAutoresizing bitmask. More...
 
SDL_Color backgroundColor
 The background color. More...
 
SDL_Color borderColor
 The border color. More...
 
int borderWidth
 The border width. More...
 
MutableSet * classNames
 The class names. More...
 
_Bool clipsSubviews
 If true, subviews will be clipped to this View's frame. More...
 
StylecomputedStyle
 The computed Style of this View. More...
 
SDL_Rect frame
 The frame, relative to the superview. More...
 
_Bool hidden
 If true, this View is not drawn. More...
 
char * identifier
 An optional identifier. More...
 
SDL_Size maxSize
 The maximum size this View may be resized to during layout. More...
 
SDL_Size minSize
 The minimum size this View may be resized to during layout. More...
 
_Bool needsApplyTheme
 If true, this View will apply the Theme before it is drawn. More...
 
_Bool needsLayout
 If true, this View will layout its subviews before it is drawn. More...
 
ViewnextResponder
 The next responder, or event handler, in the chain. More...
 
Object object
 The superclass. More...
 
ViewPadding padding
 The padding. More...
 
Stylestyle
 The element-level Style of this View. More...
 
Stylesheetstylesheet
 An optional Stylesheet. More...
 
MutableArray * subviews
 The immediate subviews. More...
 
Viewsuperview
 The super View. More...
 
ViewControllerviewController
 The ViewController. More...
 
MutableArray * warnings
 The warnings this View generated. More...
 
SDL_Window * window
 The window. More...
 

Protected Attributes

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

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 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
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 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}
static void addCell(TableRowView *self, TableCellView *cell)
Definition: TableRowView.c:69
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
MutableArray * 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 227 of file TableView.c.

227 {
228
230 assert(column);
231
232 $(self, addColumn, column);
233
234 release(column);
235}
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:214
char * identifier
An optional identifier.
Definition: View.h:201

◆ 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 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
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
SDL_Rect renderFrame(const View *self)
Definition: View.c:1275
SDL_Rect frame
The frame, relative to the superview.
Definition: View.h:190

◆ 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 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

◆ deselectAll()

void deselectAll ( TableView self)

Deselects all rows in this TableView.

Parameters
selfThe TableView.

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

◆ 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 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}
static void setSelected(CollectionItemView *self, _Bool isSelected)

◆ deselectRowsAtIndexes()

void deselectRowsAtIndexes ( TableView self,
const IndexSet *  indexes 
)

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

◆ 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 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}
static void setContentView(ScrollView *self, View *contentView)
Definition: ScrollView.c:150
static TableHeaderView * initWithTableView(TableHeaderView *self, TableView *tableView)
Controls are Views which capture events and dispatch Actions.
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:331
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

◆ 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 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}
static SDL_Size contentSize(const Panel *self)
Definition: Panel.c:166
#define MakeSize(w, h)
Creates an SDL_Size with the given dimensions.
Definition: Types.h:79
The SDL_Size type.
Definition: Types.h:62
int w
Definition: Types.h:63
int h
Definition: Types.h:63
StackView * contentView
The content View.
Definition: TableView.h:143
void sizeThatFits(const View *self)
SDL_Size size(const View *self)
Definition: View.c:1415
ViewPadding padding
The padding.
Definition: View.h:233
int top
Definition: View.h:100
int bottom
Definition: View.h:100
int right
Definition: View.h:100
int left
Definition: View.h:100

◆ 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 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
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);
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 removeAllCells(TableRowView *self)
Definition: TableRowView.c:111
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
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

◆ removeColumn()

void removeColumn ( TableView self,
TableColumn column 
)

Removes the specified column from this table.

Parameters
selfThe TableView.
columnThe column.

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}
static void removeCell(TableRowView *self, TableCellView *cell)
Definition: TableRowView.c:119
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 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()

void selectAll ( TableView self)

Selects all rows in this TableView.

Parameters
selfThe TableView.

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

◆ selectedRowIndexes()

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

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}
_Bool isSelected
True when this row is selected, false otherwise.
Definition: TableRowView.h:65

◆ 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 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()

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 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}
void selectRowAtIndex(TableView *self, size_t index)
Selects the row at the given index.
Definition: TableView.c:516

◆ setSortColumn()

void setSortColumn ( TableView self,
TableColumn column 
)

Sets the sort column for this table.

Parameters
selfThe TableView.
columnThe sort column.

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

Field Documentation

◆ columns

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

MutableArray* 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: