ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
View.h
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <Objectively/Data.h>
27#include <Objectively/Enum.h>
28#include <Objectively/MutableDictionary.h>
29#include <Objectively/MutableArray.h>
30#include <Objectively/MutableSet.h>
31#include <Objectively/Resource.h>
32
37
43#define ViewAlignmentMaskTop 0x1
44#define ViewAlignmentMaskMiddle 0x2
45#define ViewAlignmentMaskBottom 0x4
46#define ViewAlignmentMaskLeft 0x8
47#define ViewAlignmentMaskCenter 0x10
48#define ViewAlignmentMaskRight 0x20
49#define ViewAlignmentMaskInternal 0x100
50
51#define ViewAlignmentMaskVertical \
52 (ViewAlignmentMaskTop | ViewAlignmentMaskMiddle | ViewAlignmentMaskBottom)
53
54#define ViewAlignmentMaskHorizontal \
55 (ViewAlignmentMaskLeft | ViewAlignmentMaskCenter | ViewAlignmentMaskRight)
56
60typedef enum {
79
81
85typedef enum {
93
95
99typedef struct {
100 int top, right, bottom, left;
102
106#define MakePadding(top, right, bottom, left) \
107 (ViewPadding) { (top), (right), (bottom), (left) }
108
112#define AddPadding(a, b) \
113 MakePadding(a.top + b.top, a.right + b.right, a.bottom + b.bottom, a.left + b.left)
114
118typedef enum {
122
123typedef struct ViewInterface ViewInterface;
124
133struct View {
134
138 Object object;
139
144 ViewInterface *interface;
145
150
155
160
164 SDL_Color borderColor;
165
170
175 MutableSet *classNames;
176
181
186
190 SDL_Rect frame;
191
195 _Bool hidden;
196
202
207
212
217
222
229
234
241
248
252 MutableArray *subviews;
253
259
265
270 MutableArray *warnings;
271
276 SDL_Window *window;
277};
278
282struct ViewInterface {
283
287 ObjectInterface parentInterface;
288
295 _Bool (*acceptsFirstResponder)(const View *self);
296
304 void (*addClassName)(View *self, const char *className);
305
314 void (*addSubview)(View *self, View *subview);
315
325 void (*addSubviewRelativeTo)(View *self, View *subview, View *other, ViewPosition position);
326
334 View *(*ancestorWithIdentifier)(const View *self, const char *identifier);
335
343 void (*applyStyle)(View *self, const Style *style);
344
352 void (*applyTheme)(View *self, const Theme *theme);
353
361 void (*applyThemeIfNeeded)(View *self, const Theme *theme);
362
370 void (*attachStylesheet)(View *self, SDL_Window *window);
371
380 void (*awakeWithCharacters)(View *self, const char *chars);
381
390 void (*awakeWithData)(View *self, const Data *data);
391
401 void (*awakeWithDictionary)(View *self, const Dictionary *dictionary);
402
410 void (*awakeWithResource)(View *self, const Resource *resource);
411
419 void (*awakeWithResourceName)(View *self, const char *name);
420
428 void (*becomeFirstResponder)(View *self);
429
440 _Bool (*bind)(View *self, const Inlet *inlets, const Dictionary *dictionary);
441
448 SDL_Rect (*bounds)(const View *self);
449
457 void (*bringSubviewToFront)(View *self, View *subview);
458
467 SDL_Rect (*clippingFrame)(const View *self);
468
476 _Bool (*containsPoint)(const View *self, const SDL_Point *point);
477
484 int (*depth)(const View *self);
485
493 View *(*descendantWithIdentifier)(const View *self, const char *identifier);
494
502 void (*detachStylesheet)(View *self, SDL_Window *window);
503
511 void (*didMoveToWindow)(View *self, SDL_Window *window);
512
520 _Bool (*didReceiveEvent)(const View *self, const SDL_Event *event);
521
532 void (*draw)(View *self, Renderer *renderer);
533
542 void (*enumerate)(View *self, ViewEnumerator enumerator, ident data);
543
552 void (*enumerateAdjacent)(const View *self, ViewEnumerator enumerator, ident data);
553
562 void (*enumerateAncestors)(const View *self, ViewEnumerator enumerator, ident data);
563
572 void (*enumerateDescendants)(const View *self, ViewEnumerator enumerator, ident data);
573
583 void (*enumerateSelection)(View *self, const char *rule, ViewEnumerator enumerator, ident data);
584
593 void (*enumerateSiblings)(const View *self, ViewEnumerator enumerator, ident data);
594
603 void (*enumerateSubviews)(const View *self, ViewEnumerator enumerator, ident data);
604
613 void (*enumerateSuperview)(const View *self, ViewEnumerator enumerator, ident data);
614
622 View *(*firstResponder)(SDL_Window *window);
623
631 _Bool (*hasClassName)(const View *self, const char *className);
632
641 View *(*hitTest)(const View *self, const SDL_Point *point);
642
653 View *(*init)(View *self);
654
664 View *(*initWithFrame)(View *self, const SDL_Rect *frame);
665
672 void (*invalidateStyle)(View *self);
673
680 _Bool (*isContainer)(const View *self);
681
689 _Bool (*isDescendantOfView)(const View *self, const View *view);
690
697 _Bool (*isFirstResponder)(const View *self);
698
705 _Bool (*isVisible)(const View *self);
706
713 void (*layoutIfNeeded)(View *self);
714
723 void (*layoutSubviews)(View *self);
724
732 _Bool (*matchesSelector)(const View *self, const SimpleSelector *simpleSelector);
733
741 void (*moveToWindow)(View *self, SDL_Window *window);
742
749 String *(*path)(const View *self);
750
757 void (*removeAllClassNames)(View *self);
758
765 void (*removeAllSubviews)(View *self);
766
774 void (*removeClassName)(View *self, const char *className);
775
782 void (*removeFromSuperview)(View *self);
783
791 void (*removeSubview)(View *self, View *subview);
792
802 void (*render)(View *self, Renderer *renderer);
803
811 void (*renderDeviceDidReset)(View *self);
812
820 void (*renderDeviceWillReset)(View *self);
821
828 SDL_Rect (*renderFrame)(const View *self);
829
838 void (*replaceSubview)(View *self, View *subview, View *replacement);
839
846 void (*resignFirstResponder)(View *self);
847
855 void (*resize)(View *self, const SDL_Size *size);
856
864 void (*resolve)(View *self, Outlet *outlets);
865
873 void (*respondToEvent)(View *self, const SDL_Event *event);
874
883 Set *(*select)(View *self, const char *rule);
884
893 void (*setFirstResponder)(SDL_Window *window, View *view);
894
901 SDL_Size (*size)(const View *self);
902
910 SDL_Size (*sizeThatContains)(const View *self);
911
920 SDL_Size (*sizeThatFits)(const View *self);
921
929 void (*sizeToContain)(View *self);
930
938 void (*sizeToFit)(View *self);
939
947 View *(*subviewWithIdentifier)(const View *self, const char *identifier);
948
956 void (*updateBindings)(View *self);
957
964 SDL_Rect (*viewport)(const View *self);
965
975 View *(*viewWithCharacters)(const char *chars, Outlet *outlets);
976
986 View *(*viewWithData)(const Data *data, Outlet *outlets);
987
998 View *(*viewWithDictionary)(const Dictionary *dictionary, Outlet *outlets);
999
1010 View *(*viewWithResource)(const Resource *resource, Outlet *outlets);
1011
1022 View *(*viewWithResourceName)(const char *name, Outlet *outlets);
1023
1031 Array *(*visibleSubviews)(const View *self);
1032
1040 void (*warn)(View *self, const char *fmt, ...);
1041
1049 void (*willMoveToWindow)(View *self, SDL_Window *window);
1050};
1051
1058OBJECTIVELYMVC_EXPORT Class *_View(void);
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
Definition: Box.c:50
static void layoutSubviews(View *self)
Definition: Box.c:74
static _Bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)
static void applyStyle(View *self, const Style *style)
static SDL_Size sizeThatFits(const View *self)
W3C Color constants.
static _Bool acceptsFirstResponder(const View *self)
Definition: Control.c:68
static void respondToEvent(View *self, const SDL_Event *event)
Definition: Control.c:213
static void render(View *self, Renderer *renderer)
Definition: Control.c:131
static void renderDeviceDidReset(Font *self)
Definition: Font.c:247
static void updateBindings(View *self)
static SDL_Size size(const Image *self)
Definition: Image.c:181
static void renderDeviceWillReset(View *self)
Definition: ImageView.c:121
static void removeSubview(View *self, View *subview)
Definition: PageView.c:58
static void addSubview(View *self, View *subview)
Definition: PageView.c:35
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
static void enumerateSelection(const Selector *self, View *view, ViewEnumerator enumerator, ident data)
Definition: Selector.c:166
static Theme * theme(SDL_Window *window)
Definition: Theme.c:143
The Theme type.
void(* ViewEnumerator)(View *view, ident data)
A function type for View enumeration.
Definition: Types.h:55
#define OBJECTIVELYMVC_EXPORT
Definition: Types.h:39
JSON data binding for Views.
static void removeClassName(View *self, const char *className)
Definition: View.c:1158
static _Bool didReceiveEvent(const View *self, const SDL_Event *event)
Definition: View.c:546
static void addClassName(View *self, const char *className)
Definition: View.c:120
static void warn(View *self, const char *fmt,...)
Definition: View.c:1647
static void addSubviewRelativeTo(View *self, View *subview, View *other, ViewPosition position)
Definition: View.c:146
static void didMoveToWindow(View *self, SDL_Window *window)
Definition: View.c:533
static void resize(View *self, const SDL_Size *size)
Definition: View.c:1326
static _Bool isFirstResponder(const View *self)
Definition: View.c:856
static void setFirstResponder(SDL_Window *window, View *view)
Definition: View.c:1393
static void detachStylesheet(View *self, SDL_Window *window)
Definition: View.c:517
static void layoutIfNeeded(View *self)
Definition: View.c:891
static void sizeToContain(View *self)
Definition: View.c:1485
static void enumerateAncestors(const View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:621
static int depth(const View *self)
Definition: View.c:483
static void draw(View *self, Renderer *renderer)
Definition: View.c:572
static void removeAllClassNames(View *self)
Definition: View.c:1132
static void enumerateSubviews(const View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:685
static void becomeFirstResponder(View *self)
Definition: View.c:370
static _Bool containsPoint(const View *self, const SDL_Point *point)
Definition: View.c:472
static _Bool hasClassName(const View *self, const char *className)
Definition: View.c:730
static void replaceSubview(View *self, View *subview, View *replacement)
Definition: View.c:1302
static void bringSubviewToFront(View *self, View *subview)
Definition: View.c:412
static _Bool isContainer(const View *self)
Definition: View.c:830
static void resignFirstResponder(View *self)
Definition: View.c:1315
static void invalidateStyle(View *self)
Definition: View.c:822
static void awakeWithCharacters(View *self, const char *chars)
Definition: View.c:302
static void moveToWindow(View *self, SDL_Window *window)
Definition: View.c:1073
static void removeFromSuperview(View *self)
Definition: View.c:1175
static void removeAllSubviews(View *self)
Definition: View.c:1150
static SDL_Size sizeThatContains(const View *self)
Definition: View.c:1423
static void applyTheme(View *self, const Theme *theme)
Definition: View.c:246
static void awakeWithResourceName(View *self, const char *name)
Definition: View.c:357
static SDL_Rect renderFrame(const View *self)
Definition: View.c:1275
static void willMoveToWindow(View *self, SDL_Window *window)
Definition: View.c:1664
static void attachStylesheet(View *self, SDL_Window *window)
Definition: View.c:286
static void awakeWithResource(View *self, const Resource *resource)
Definition: View.c:346
static void enumerateSuperview(const View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:699
static void enumerate(View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:588
static void enumerateAdjacent(const View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:601
static SDL_Rect viewport(const View *self)
Definition: View.c:1545
static void applyThemeIfNeeded(View *self, const Theme *theme)
Definition: View.c:269
static _Bool isVisible(const View *self)
Definition: View.c:869
static void sizeToFit(View *self)
Definition: View.c:1496
static SDL_Rect clippingFrame(const View *self)
Definition: View.c:429
static void enumerateSiblings(const View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:665
static void awakeWithData(View *self, const Data *data)
Definition: View.c:315
static void enumerateDescendants(const View *self, ViewEnumerator enumerator, ident data)
Definition: View.c:647
static SDL_Rect bounds(const View *self)
Definition: View.c:394
static void resolve(View *self, Outlet *outlets)
Definition: View.c:1345
static _Bool isDescendantOfView(const View *self, const View *view)
Definition: View.c:838
#define ViewAlignmentMaskInternal
Definition: View.h:49
#define ViewAlignmentMaskCenter
Definition: View.h:47
#define ViewAlignmentMaskLeft
Definition: View.h:46
#define ViewAlignmentMaskBottom
Definition: View.h:45
#define ViewAlignmentMaskTop
Definition: View.h:43
#define ViewAlignmentMaskRight
Definition: View.h:48
#define ViewAlignmentMaskMiddle
Definition: View.h:44
ViewPosition
Relative positioning of subviews within their superview.
Definition: View.h:118
@ ViewPositionBefore
Definition: View.h:119
@ ViewPositionAfter
Definition: View.h:120
OBJECTIVELYMVC_EXPORT const EnumName ViewAlignmentNames[]
Definition: View.h:80
OBJECTIVELYMVC_EXPORT const EnumName ViewAutoresizingNames[]
Definition: View.h:94
ViewAutoresizing
Auto-resizing constants, which are bitmasked.
Definition: View.h:85
@ ViewAutoresizingNone
Definition: View.h:86
@ ViewAutoresizingFill
Definition: View.h:89
@ ViewAutoresizingContain
Definition: View.h:91
@ ViewAutoresizingWidth
Definition: View.h:87
@ ViewAutoresizingHeight
Definition: View.h:88
@ ViewAutoresizingFit
Definition: View.h:90
ViewAlignment
Alignment constants, used to align a View within its superview.
Definition: View.h:60
@ ViewAlignmentBottomRight
Definition: View.h:76
@ ViewAlignmentBottomLeft
Definition: View.h:74
@ ViewAlignmentMiddleCenter
Definition: View.h:72
@ ViewAlignmentInternal
Definition: View.h:77
@ ViewAlignmentTopCenter
Definition: View.h:69
@ ViewAlignmentTopRight
Definition: View.h:70
@ ViewAlignmentMiddleRight
Definition: View.h:73
@ ViewAlignmentTopLeft
Definition: View.h:68
@ ViewAlignmentCenter
Definition: View.h:66
@ ViewAlignmentLeft
Definition: View.h:65
@ ViewAlignmentRight
Definition: View.h:67
@ ViewAlignmentTop
Definition: View.h:62
@ ViewAlignmentMiddleLeft
Definition: View.h:71
@ ViewAlignmentBottom
Definition: View.h:64
@ ViewAlignmentMiddle
Definition: View.h:63
@ ViewAlignmentBottomCenter
Definition: View.h:75
@ ViewAlignmentNone
Definition: View.h:61
Inlets enable inbound data binding of View attributes through JSON.
Definition: View+JSON.h:155
Outlets enable outbound data binding of Views through JSON.
Definition: View+JSON.h:200
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
Definition: Renderer.h:50
The SDL_Size type.
Definition: Types.h:62
The SimpleSelector type.
The Style type.
Definition: Style.h:43
Stylesheets are comprised of Selectors and Styles.
Definition: Stylesheet.h:44
The Theme type.
Definition: Theme.h:51
A ViewController manages a View and its descendants.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
Stylesheet * stylesheet
An optional Stylesheet.
Definition: View.h:247
MutableArray * subviews
The immediate subviews.
Definition: View.h:252
View * superview
The super View.
Definition: View.h:258
MutableArray * warnings
The warnings this View generated.
Definition: View.h:270
ViewController * viewController
The ViewController.
Definition: View.h:264
_Bool clipsSubviews
If true, subviews will be clipped to this View's frame.
Definition: View.h:180
Style * style
The element-level Style of this View.
Definition: View.h:240
ViewAlignment alignment
The alignment.
Definition: View.h:149
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition: View.h:221
_Bool needsApplyTheme
If true, this View will apply the Theme before it is drawn.
Definition: View.h:216
SDL_Window * window
The window.
Definition: View.h:276
_Bool hidden
If true, this View is not drawn.
Definition: View.h:195
Class * _View(void)
The View archetype.
Definition: View.c:1769
SDL_Color borderColor
The border color.
Definition: View.h:164
int autoresizingMask
The ViewAutoresizing bitmask.
Definition: View.h:154
View * nextResponder
The next responder, or event handler, in the chain.
Definition: View.h:228
char * identifier
An optional identifier.
Definition: View.h:201
ViewPadding padding
The padding.
Definition: View.h:233
int borderWidth
The border width.
Definition: View.h:169
SDL_Size minSize
The minimum size this View may be resized to during layout.
Definition: View.h:211
Object object
The superclass.
Definition: View.h:138
Style * computedStyle
The computed Style of this View.
Definition: View.h:185
ViewInterface * interface
The interface.
Definition: View.h:144
MutableSet * classNames
The class names.
Definition: View.h:175
SDL_Size maxSize
The maximum size this View may be resized to during layout.
Definition: View.h:206
SDL_Color backgroundColor
The background color.
Definition: View.h:159
SDL_Rect frame
The frame, relative to the superview.
Definition: View.h:190
Spacing applied to the inside of a View's frame.
Definition: View.h:99
int bottom
Definition: View.h:100