ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
DebugViewController.c File Reference
#include <assert.h>
#include <Objectively/String.h>
#include "DebugViewController.h"
#include "WindowController.h"
#include "../Assets/debug.css.h"
#include "../Assets/debug.json.h"

Go to the source code of this file.

Macros

#define _Class   _DebugViewController
 

Functions

Class * _DebugViewController (void)
 
static TableCellViewcomputedStyle_cellForColumnAndRow (const TableView *tableView, const TableColumn *column, size_t row)
 
static size_t computedStyle_numberOfRows (const TableView *tableView)
 
static ident computedStyle_valueForColumnAndRow (const TableView *tableView, const TableColumn *column, size_t row)
 
static void debug (DebugViewController *self, const View *view, Renderer *renderer)
 
static void debugEnumerate (View *view, ident data)
 
static DebugViewControllerinit (DebugViewController *self)
 
static void initialize (Class *clazz)
 
static void loadView (ViewController *self)
 
static TableCellViewselectors_cellForColumnAndRow (const TableView *tableView, const TableColumn *column, size_t row)
 
static size_t selectors_numberOfRows (const TableView *tableView)
 
static ident selectors_valueForColumnAndRow (const TableView *tableView, const TableColumn *column, size_t row)
 
static TableCellViewwarnings_cellForColumnAndRow (const TableView *tableView, const TableColumn *column, size_t row)
 
static size_t warnings_numberOfRows (const TableView *tableView)
 
static ident warnings_valueForColumnAndRow (const TableView *tableView, const TableColumn *column, size_t row)
 

Macro Definition Documentation

◆ _Class

#define _Class   _DebugViewController

Definition at line 34 of file DebugViewController.c.

Function Documentation

◆ _DebugViewController()

Class * _DebugViewController ( void  )

Definition at line 341 of file DebugViewController.c.

341 {
342 static Class *clazz;
343 static Once once;
344
345 do_once(&once, {
346 clazz = _initialize(&(const ClassDef) {
347 .name = "DebugViewController",
348 .superclass = _ViewController(),
349 .instanceSize = sizeof(DebugViewController),
350 .interfaceOffset = offsetof(DebugViewController, interface),
351 .interfaceSize = sizeof(DebugViewControllerInterface),
353 });
354 });
355
356 return clazz;
357}
static void initialize(Class *clazz)
Class * _ViewController(void)
The DebugViewController type.

◆ computedStyle_cellForColumnAndRow()

static TableCellView * computedStyle_cellForColumnAndRow ( const TableView tableView,
const TableColumn column,
size_t  row 
)
static
See also
TableViewDelegate::cellForColumnAndRow(const TableView *, const TableColumn *, size_t)

Definition at line 120 of file DebugViewController.c.

120 {
121
122 ident value = tableView->dataSource.valueForColumnAndRow(tableView, column, row);
123 assert(value);
124
125 TableCellView *cell = $(alloc(TableCellView), initWithFrame, NULL);
126 String *description = $((Object *) value, description);
127 $(cell->text, setText, description->chars);
128 release(description);
129
130 return cell;
131}
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
Definition Box.c:92
static String * description(const Object *self)
Definition Label.c:47
static void setText(Text *self, const char *text)
Definition Text.c:532
Each row in a TableView is comprised of TableCellViews.
Text * text
The text.
ident(* valueForColumnAndRow)(const TableView *tableView, const TableColumn *column, size_t row)
Called by the TableView for the associated value of a cell.
Definition TableView.h:76
TableViewDataSource dataSource
The data source.
Definition TableView.h:148

◆ computedStyle_numberOfRows()

static size_t computedStyle_numberOfRows ( const TableView tableView)
static
See also
TableViewDataSource::numberOfRows(const TableView *)

Definition at line 83 of file DebugViewController.c.

83 {
84
85 const DebugViewController *this = tableView->dataSource.self;
86 if (this->debug) {
87 return this->debug->computedStyle->attributes->count;
88 } else {
89 return 0;
90 }
91}
static void debug(DebugViewController *self, const View *view, Renderer *renderer)
ident self
The data source self-reference.
Definition TableView.h:61

◆ computedStyle_valueForColumnAndRow()

static ident computedStyle_valueForColumnAndRow ( const TableView tableView,
const TableColumn column,
size_t  row 
)
static
See also
TableViewDataSource::valueForColumnAndRow(const TableView *, const TableColumn *, size_t)

Definition at line 96 of file DebugViewController.c.

96 {
97
98 ident value = NULL;
99
100 const DebugViewController *this = tableView->dataSource.self;
101 if (this->debug) {
102
103 Array *array;
104 if (strcmp("Attribute", column->identifier) == 0) {
105 array = $(this->debug->computedStyle->attributes, allKeys);
106 } else {
107 array = $(this->debug->computedStyle->attributes, allObjects);
108 }
109
110 value = $(array, objectAtIndex, row);
111 release(array);
112 }
113
114 return value;
115}
char * identifier
The identifier.
Definition TableColumn.h:66

◆ debug()

static void debug ( DebugViewController self,
const View view,
Renderer renderer 
)
static

Definition at line 264 of file DebugViewController.c.

264 {
265
266 if (view != self->debug) {
267 self->debug = view;
268
269 if (self->debug) {
270 self->root = self->debug;
271 while (self->root->superview) {
272 self->root = self->root->superview;
273 }
274
275 String *path = $(self->debug, path);
276 $(self->path, setText, path->chars);
277 release(path);
278
279 String *description = $((Object *) view, description);
280 $(self->description, setText, description->chars);
281 release(description);
282 } else {
283 $(self->path, setText, NULL);
284 $(self->description, setText, NULL);
285 }
286
287 $(self->selectors, reloadData);
288 $((View *) self->selectors, sizeToFit);
289
290 $(self->computedStyle, reloadData);
291 $((View *) self->computedStyle, sizeToFit);
292
293 $(self->warnings, reloadData);
294 $((View *) self->warnings, sizeToFit);
295 }
296
297 self->renderer = renderer;
298 assert(self->renderer);
299
300 self->visibleViews = 0;
301
302 if (self->root) {
303 $((View *) self->root, enumerate, debugEnumerate, self);
304 }
305
306 self->frames++;
307 if (SDL_GetTicks() - self->timestamp >= 1000) {
308
309 $(self->statistics, setTextWithFormat, "%d views, %dfps", self->visibleViews, self->frames);
310
311 self->timestamp = SDL_GetTicks();
312 self->frames = 0;
313 }
314}
static void reloadData(CollectionView *self)
static void debugEnumerate(View *view, ident data)
static void setTextWithFormat(Text *self, const char *fmt,...)
Definition Text.c:558
static String * path(const View *self)
Definition View.c:1277
static void enumerate(View *self, ViewEnumerator enumerator, ident data)
Definition View.c:749
static void sizeToFit(View *self)
Definition View.c:1767
TableView * selectors
The CSS selectors matching the View.
const View * debug
The View to debug.
TableView * computedStyle
The computed style of the View.
int visibleViews
The count of visibile Views.
Renderer * renderer
A weak referece to the current WindowController's renderer.
TableView * warnings
The warnings generated by the View.
Text * description
The View description.
const View * root
The root ancestor of the debug View.
Text * path
The path to the debug View.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134
View * superview
The super View.
Definition View.h:259

◆ debugEnumerate()

static void debugEnumerate ( View view,
ident  data 
)
static

Definition at line 227 of file DebugViewController.c.

227 {
228
229 DebugViewController *this = data;
230
231 if (view == this->debug) {
232 const SDL_Rect frame = $(view, renderFrame);
233
234 $(this->renderer, setClippingFrame, NULL);
235 $(this->renderer, drawRectFilled, &frame, &MakeColor(0x22, 0x66, 0x99, 0x88));
236 }
237
238 if ($(view, isVisible)) {
239 this->visibleViews++;
240
241 // FIXME: This is a bit gaff. But hasOverflow produces false positives if called at the
242 // FIXME: end of layoutSubviews, because containers have not yet been resized to fill their
243 // FIXME: parent (e.g. autoresizing-mask: contain | width).
244 // FIXME: Ideally, warnings are accumulated during layoutSubviews and applyTheme, instead
245 // FIXME: of attempting to collect them here.
246
247 $(view, clearWarnings, (WarningType) 0xff);
248 $(view, hasOverflow);
249
250 const Array *warnings = (Array *) view->warnings;
251 if (warnings->count) {
252 const SDL_Rect frame = $(view, renderFrame);
253
254 $(this->renderer, setClippingFrame, NULL);
255 $(this->renderer, drawRect, &frame, &Colors.DarkGoldenRod);
256 }
257 }
258}
static void setClippingFrame(Renderer *self, const SDL_Rect *clippingFrame)
Definition Renderer.c:482
static void drawRectFilled(const Renderer *self, const SDL_Rect *rect, const SDL_Color *color)
Definition Renderer.c:188
static void drawRect(const Renderer *self, const SDL_Rect *rect, const SDL_Color *color)
Definition Renderer.c:169
static void clearWarnings(const View *self, WarningType type)
Definition View.c:538
static bool isVisible(const View *self)
Definition View.c:1093
static bool hasOverflow(const View *self)
Definition View.c:939
static SDL_Rect renderFrame(const View *self)
Definition View.c:1455
WarningType
Warning types.
Definition Warning.h:33
W3C Color constants.
Definition Colors.h:37
SDL_Color DarkGoldenRod
Definition Colors.h:63
Array * warnings
The Warnings this View generated.
Definition View.h:271

◆ init()

static DebugViewController * init ( DebugViewController self)
static

Definition at line 320 of file DebugViewController.c.

320 {
321 return (DebugViewController *) super(ViewController, self, init);
322}
static DebugViewController * init(DebugViewController *self)
A ViewController manages a View and its descendants.

◆ initialize()

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

Definition at line 329 of file DebugViewController.c.

329 {
330
331 ((ViewControllerInterface *) clazz->interface)->loadView = loadView;
332
333 ((DebugViewControllerInterface *) clazz->interface)->debug = debug;
334 ((DebugViewControllerInterface *) clazz->interface)->init = init;
335}
static void loadView(ViewController *self)

◆ loadView()

static void loadView ( ViewController self)
static
See also
ViewController::loadView(ViewController *)

Definition at line 182 of file DebugViewController.c.

182 {
183
184 super(ViewController, self, loadView);
185
187
188 Outlet outlets[] = MakeOutlets(
189 MakeOutlet("statistics", &this->statistics),
190 MakeOutlet("description", &this->description),
191 MakeOutlet("path", &this->path),
192 MakeOutlet("selectors", &this->selectors),
193 MakeOutlet("computedStyle", &this->computedStyle),
194 MakeOutlet("warnings", &this->warnings)
195 );
196
197 View *view = $$(View, viewWithCharacters, (char *) debug_json, outlets);
198 view->stylesheet = $$(Stylesheet, stylesheetWithCharacters, (char *) debug_css);
199
200 $(self, setView, view);
201 release(view);
202
203 this->selectors->dataSource.self = self;
204 this->selectors->dataSource.numberOfRows = selectors_numberOfRows;
205 this->selectors->dataSource.valueForColumnAndRow = selectors_valueForColumnAndRow;
206 this->selectors->delegate.self = self;
207 this->selectors->delegate.cellForColumnAndRow = selectors_cellForColumnAndRow;
208
209 this->computedStyle->dataSource.self = self;
210 this->computedStyle->dataSource.numberOfRows = computedStyle_numberOfRows;
211 this->computedStyle->dataSource.valueForColumnAndRow = computedStyle_valueForColumnAndRow;
212 this->computedStyle->delegate.self = self;
213 this->computedStyle->delegate.cellForColumnAndRow = computedStyle_cellForColumnAndRow;
214
215 this->warnings->dataSource.self = self;
216 this->warnings->dataSource.numberOfRows = warnings_numberOfRows;
217 this->warnings->dataSource.valueForColumnAndRow = warnings_valueForColumnAndRow;
218 this->warnings->delegate.self = self;
219 this->warnings->delegate.cellForColumnAndRow = warnings_cellForColumnAndRow;
220}
static TableCellView * selectors_cellForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static ident warnings_valueForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static ident computedStyle_valueForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static TableCellView * warnings_cellForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static size_t computedStyle_numberOfRows(const TableView *tableView)
static TableCellView * computedStyle_cellForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static size_t selectors_numberOfRows(const TableView *tableView)
static ident selectors_valueForColumnAndRow(const TableView *tableView, const TableColumn *column, size_t row)
static size_t warnings_numberOfRows(const TableView *tableView)
static Stylesheet * stylesheetWithCharacters(const char *chars)
Definition Stylesheet.c:206
#define MakeOutlet(identifier, view)
Creates an Outlet with the specified parameters.
Definition View+JSON.h:230
#define MakeOutlets(...)
Creates a NULL-termianted array of Outlets.
Definition View+JSON.h:235
static View * viewWithCharacters(const char *chars, Outlet *outlets)
Definition View.c:1829
static void setView(ViewController *self, View *view)
Outlets enable outbound data binding of Views through JSON.
Definition View+JSON.h:200
Stylesheets are comprised of Selectors and Styles.
Definition Stylesheet.h:44
Stylesheet * stylesheet
An optional Stylesheet.
Definition View.h:248

◆ selectors_cellForColumnAndRow()

static TableCellView * selectors_cellForColumnAndRow ( const TableView tableView,
const TableColumn column,
size_t  row 
)
static
See also
TableViewDelegate::cellForColumnAndRow(const TableView *, const TableColumn *, size_t)

Definition at line 67 of file DebugViewController.c.

67 {
68
69 const Selector *selector = tableView->dataSource.valueForColumnAndRow(tableView, column, row);
70 assert(selector);
71
72 TableCellView *cell = $(alloc(TableCellView), initWithFrame, NULL);
73 $(cell->text, setText, selector->rule);
74
75 return cell;
76}
Selectors are comprised of one or more SelectorSequences.
Definition Selector.h:49
char * rule
The rule, as provided by the user.
Definition Selector.h:70

◆ selectors_numberOfRows()

static size_t selectors_numberOfRows ( const TableView tableView)
static
See also
TableViewDataSource::numberOfRows(const TableView *)

Definition at line 41 of file DebugViewController.c.

41 {
42
43 const DebugViewController *this = tableView->dataSource.self;
44 if (this->debug) {
45 return this->debug->computedStyle->selectors->count;
46 } else {
47 return 0;
48 }
49}

◆ selectors_valueForColumnAndRow()

static ident selectors_valueForColumnAndRow ( const TableView tableView,
const TableColumn column,
size_t  row 
)
static
See also
TableViewDataSource::valueForColumnAndRow(const TableView *, const TableColumn *, size_t)

Definition at line 54 of file DebugViewController.c.

54 {
55
56 const DebugViewController *this = tableView->dataSource.self;
57 if (this->debug) {
58 return $(this->debug->computedStyle->selectors, objectAtIndex, row);
59 } else {
60 return NULL;
61 }
62}

◆ warnings_cellForColumnAndRow()

static TableCellView * warnings_cellForColumnAndRow ( const TableView tableView,
const TableColumn column,
size_t  row 
)
static
See also
TableViewDelegate::cellForColumnAndRow(const TableView *, const TableColumn *, size_t)

Definition at line 166 of file DebugViewController.c.

166 {
167
168 Warning *warning = tableView->dataSource.valueForColumnAndRow(tableView, column, row);
169 assert(warning);
170
171 TableCellView *cell = $(alloc(TableCellView), initWithFrame, NULL);
172 $(cell->text, setText, warning->message->chars);
173
174 return cell;
175}
The Warning type.
Definition Warning.h:50
String * message
The message.
Definition Warning.h:71

◆ warnings_numberOfRows()

static size_t warnings_numberOfRows ( const TableView tableView)
static
See also
TableViewDataSource::numberOfRows(const TableView *)

Definition at line 138 of file DebugViewController.c.

138 {
139
140 const DebugViewController *this = tableView->dataSource.self;
141 if (this->debug) {
142 return this->debug->warnings->count;
143 } else {
144 return 0;
145 }
146}

◆ warnings_valueForColumnAndRow()

static ident warnings_valueForColumnAndRow ( const TableView tableView,
const TableColumn column,
size_t  row 
)
static
See also
TableViewDataSource::valueForColumnAndRow(const TableView *, const TableColumn *, size_t)

Definition at line 151 of file DebugViewController.c.

151 {
152
153 ident value = NULL;
154
155 const DebugViewController *this = tableView->dataSource.self;
156 if (this->debug) {
157 value = $((Array *) this->debug->warnings, objectAtIndex, row);
158 }
159
160 return value;
161}