ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
View.h
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for SDL3 and 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/Dictionary.h>
29#include <Objectively/Array.h>
30#include <Objectively/Set.h>
31#include <Objectively/Resource.h>
32
38
44#define ViewAlignmentMaskTop 0x1
45#define ViewAlignmentMaskMiddle 0x2
46#define ViewAlignmentMaskBottom 0x4
47#define ViewAlignmentMaskLeft 0x8
48#define ViewAlignmentMaskCenter 0x10
49#define ViewAlignmentMaskRight 0x20
50#define ViewAlignmentMaskInternal 0x100
51
52#define ViewAlignmentMaskVertical \
53 (ViewAlignmentMaskTop | ViewAlignmentMaskMiddle | ViewAlignmentMaskBottom)
54
55#define ViewAlignmentMaskHorizontal \
56 (ViewAlignmentMaskLeft | ViewAlignmentMaskCenter | ViewAlignmentMaskRight)
57
80
82
94
96
100typedef struct {
101 int top, right, bottom, left;
103
107#define MakePadding(top, right, bottom, left) \
108 (ViewPadding) { (top), (right), (bottom), (left) }
109
113#define AddPadding(a, b) \
114 MakePadding(a.top + b.top, a.right + b.right, a.bottom + b.bottom, a.left + b.left)
115
123
124typedef struct ViewInterface ViewInterface;
125
134struct View {
135
139 Object object;
140
145 ViewInterface *interface;
146
151
156
161
165 SDL_Color borderColor;
166
171
177
182
187
191 SDL_Rect frame;
192
196 bool hidden;
197
203
207 SDL_Size maxSize;
208
212 SDL_Size minSize;
213
218
223
230
235
242
249
253 Array *subviews;
254
260
266
271 Array *warnings;
272
277 SDL_Window *window;
278};
279
283struct ViewInterface {
284
288 ObjectInterface parentInterface;
289
296 bool (*acceptsKeyResponder)(const View *self);
297
304 bool (*acceptsTouchResponder)(const View *self);
305
313 void (*addClassName)(View *self, const char *className);
314
323 void (*addSubview)(View *self, View *subview);
324
334 void (*addSubviewRelativeTo)(View *self, View *subview, View *other, ViewPosition position);
335
343 View *(*ancestorWithIdentifier)(const View *self, const char *identifier);
344
352 void (*applyStyle)(View *self, const Style *style);
353
361 void (*applyTheme)(View *self, const Theme *theme);
362
370 void (*applyThemeIfNeeded)(View *self, const Theme *theme);
371
379 void (*attachStylesheet)(View *self, SDL_Window *window);
380
389 void (*awakeWithCharacters)(View *self, const char *chars);
390
399 void (*awakeWithData)(View *self, const Data *data);
400
410 void (*awakeWithDictionary)(View *self, const Dictionary *dictionary);
411
419 void (*awakeWithResource)(View *self, const Resource *resource);
420
428 void (*awakeWithResourceName)(View *self, const char *name);
429
437 void (*becomeKeyResponder)(View *self);
438
446 void (*becomeTouchResponder)(View *self);
447
458 bool (*bind)(View *self, const Inlet *inlets, const Dictionary *dictionary);
459
466 SDL_Rect (*bounds)(const View *self);
467
475 void (*bringSubviewToFront)(View *self, View *subview);
476
484 void (*clearWarnings)(const View *self, WarningType level);
485
494 SDL_Rect (*clippingFrame)(const View *self);
495
503 bool (*containsPoint)(const View *self, const SDL_Point *point);
504
511 int (*depth)(const View *self);
512
520 View *(*descendantWithIdentifier)(const View *self, const char *identifier);
521
529 void (*detachStylesheet)(View *self, SDL_Window *window);
530
538 void (*didMoveToWindow)(View *self, SDL_Window *window);
539
547 bool (*didReceiveEvent)(const View *self, const SDL_Event *event);
548
559 void (*draw)(View *self, Renderer *renderer);
560
571 void (*emitViewEvent)(View *self, ViewEvent code, ident data);
572
581 void (*enumerate)(View *self, ViewEnumerator enumerator, ident data);
582
591 void (*enumerateAdjacent)(const View *self, ViewEnumerator enumerator, ident data);
592
601 void (*enumerateAncestors)(const View *self, ViewEnumerator enumerator, ident data);
602
611 void (*enumerateDescendants)(const View *self, ViewEnumerator enumerator, ident data);
612
622 void (*enumerateSelection)(View *self, const char *rule, ViewEnumerator enumerator, ident data);
623
632 void (*enumerateSiblings)(const View *self, ViewEnumerator enumerator, ident data);
633
642 void (*enumerateSubviews)(const View *self, ViewEnumerator enumerator, ident data);
643
652 void (*enumerateSuperview)(const View *self, ViewEnumerator enumerator, ident data);
653
663 void (*enumerateVisible)(View *self, ViewEnumerator enumerator, ident data);
664
672 bool (*hasClassName)(const View *self, const char *className);
673
680 bool (*hasOverflow)(const View *self);
681
690 View *(*hitTest)(const View *self, const SDL_Point *point);
691
702 View *(*init)(View *self);
703
713 View *(*initWithFrame)(View *self, const SDL_Rect *frame);
714
721 void (*invalidateStyle)(View *self);
722
729 bool (*isContainer)(const View *self);
730
738 bool (*isDescendantOfView)(const View *self, const View *view);
739
746 bool (*isKeyResponder)(const View *self);
747
754 bool (*isTouchResponder)(const View *self);
755
762 bool (*isVisible)(const View *self);
763
770 void (*layoutIfNeeded)(View *self);
771
780 void (*layoutSubviews)(View *self);
781
789 bool (*matchesSelector)(const View *self, const SimpleSelector *simpleSelector);
790
798 void (*moveToWindow)(View *self, SDL_Window *window);
799
806 String *(*path)(const View *self);
807
814 void (*removeAllClassNames)(View *self);
815
822 void (*removeAllSubviews)(View *self);
823
831 void (*removeClassName)(View *self, const char *className);
832
839 void (*removeFromSuperview)(View *self);
840
848 void (*removeSubview)(View *self, View *subview);
849
859 void (*render)(View *self, Renderer *renderer);
860
868 void (*renderDeviceDidReset)(View *self);
869
877 void (*renderDeviceWillReset)(View *self);
878
885 SDL_Rect (*renderFrame)(const View *self);
886
895 void (*replaceSubview)(View *self, View *subview, View *replacement);
896
903 void (*resignKeyResponder)(View *self);
904
911 void (*resignTouchResponder)(View *self);
912
920 void (*resize)(View *self, const SDL_Size *size);
921
929 void (*resolve)(View *self, Outlet *outlets);
930
938 void (*respondToEvent)(View *self, const SDL_Event *event);
939
948 Set *(*select)(View *self, const char *rule);
949
958 View *(*selectFirst)(View *self, const char *rule);
959
966 SDL_Size (*size)(const View *self);
967
975 SDL_Size (*sizeThatContains)(const View *self);
976
985 SDL_Size (*sizeThatFits)(const View *self);
986
993 SDL_Size (*sizeThatFills)(const View *self);
994
1002 void (*sizeToContain)(View *self);
1003
1011 void (*sizeToFill)(View *self);
1012
1020 void (*sizeToFit)(View *self);
1021
1029 View *(*subviewWithIdentifier)(const View *self, const char *identifier);
1030
1038 void (*updateBindings)(View *self);
1039
1046 SDL_Rect (*viewport)(const View *self);
1047
1057 View *(*viewWithCharacters)(const char *chars, Outlet *outlets);
1058
1068 View *(*viewWithData)(const Data *data, Outlet *outlets);
1069
1080 View *(*viewWithDictionary)(const Dictionary *dictionary, Outlet *outlets);
1081
1092 View *(*viewWithResource)(const Resource *resource, Outlet *outlets);
1093
1104 View *(*viewWithResourceName)(const char *name, Outlet *outlets);
1105
1113 Array *(*visibleSubviews)(const View *self);
1114
1123 void (*warn)(View *self, WarningType level, const char *fmt, ...);
1124
1132 void (*willMoveToWindow)(View *self, SDL_Window *window);
1133};
1134
1141OBJECTIVELYMVC_EXPORT Class *_View(void);
W3C Color constants.
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
static Theme * theme(SDL_Window *window)
Definition Theme.c:143
The Theme type.
ViewEvent
View event relay codes.
Definition Types.h:61
void(* ViewEnumerator)(View *view, ident data)
A function type for View enumeration.
Definition Types.h:56
#define OBJECTIVELYMVC_EXPORT
Definition Types.h:40
JSON data binding for Views.
#define ViewAlignmentMaskInternal
Definition View.h:50
#define ViewAlignmentMaskCenter
Definition View.h:48
OBJECTIVELYMVC_EXPORT Class * _View(void)
Definition View.c:2067
#define ViewAlignmentMaskLeft
Definition View.h:47
#define ViewAlignmentMaskBottom
Definition View.h:46
#define ViewAlignmentMaskTop
Definition View.h:44
#define ViewAlignmentMaskRight
Definition View.h:49
#define ViewAlignmentMaskMiddle
Definition View.h:45
ViewPosition
Relative positioning of subviews within their superview.
Definition View.h:119
@ ViewPositionBefore
Definition View.h:120
@ ViewPositionAfter
Definition View.h:121
OBJECTIVELYMVC_EXPORT const EnumName ViewAlignmentNames[]
Definition View.h:81
OBJECTIVELYMVC_EXPORT const EnumName ViewAutoresizingNames[]
Definition View.h:95
ViewAutoresizing
Auto-resizing constants, which are bitmasked.
Definition View.h:86
@ ViewAutoresizingNone
Definition View.h:87
@ ViewAutoresizingFill
Definition View.h:90
@ ViewAutoresizingContain
Definition View.h:92
@ ViewAutoresizingWidth
Definition View.h:88
@ ViewAutoresizingHeight
Definition View.h:89
@ ViewAutoresizingFit
Definition View.h:91
ViewAlignment
Alignment constants, used to align a View within its superview.
Definition View.h:61
@ ViewAlignmentBottomRight
Definition View.h:77
@ ViewAlignmentBottomLeft
Definition View.h:75
@ ViewAlignmentMiddleCenter
Definition View.h:73
@ ViewAlignmentInternal
Definition View.h:78
@ ViewAlignmentTopCenter
Definition View.h:70
@ ViewAlignmentTopRight
Definition View.h:71
@ ViewAlignmentMiddleRight
Definition View.h:74
@ ViewAlignmentTopLeft
Definition View.h:69
@ ViewAlignmentCenter
Definition View.h:67
@ ViewAlignmentLeft
Definition View.h:66
@ ViewAlignmentRight
Definition View.h:68
@ ViewAlignmentTop
Definition View.h:63
@ ViewAlignmentMiddleLeft
Definition View.h:72
@ ViewAlignmentBottom
Definition View.h:65
@ ViewAlignmentMiddle
Definition View.h:64
@ ViewAlignmentBottomCenter
Definition View.h:76
@ ViewAlignmentNone
Definition View.h:62
Warnings are accumulated on Views so that they may be reported by the DebugViewController.
WarningType
Warning types.
Definition Warning.h:33
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
Renderer extends Object with ObjectivelyMVC's UI rendering layer.
Definition Renderer.h:70
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:134
Stylesheet * stylesheet
An optional Stylesheet.
Definition View.h:248
bool clipsSubviews
If true, subviews will be clipped to this View's frame.
Definition View.h:181
View * superview
The super View.
Definition View.h:259
Array * subviews
The immediate subviews.
Definition View.h:253
ViewController * viewController
The ViewController.
Definition View.h:265
Style * style
The element-level Style of this View.
Definition View.h:241
ViewAlignment alignment
The alignment.
Definition View.h:150
SDL_Window * window
The window.
Definition View.h:277
bool needsApplyTheme
If true, this View will apply the Theme before it is drawn.
Definition View.h:217
SDL_Color borderColor
The border color.
Definition View.h:165
int autoresizingMask
The ViewAutoresizing bitmask.
Definition View.h:155
View * nextResponder
The next responder, or event handler, in the chain.
Definition View.h:229
bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition View.h:222
char * identifier
An optional identifier.
Definition View.h:202
Array * warnings
The Warnings this View generated.
Definition View.h:271
ViewPadding padding
The padding.
Definition View.h:234
int borderWidth
The border width.
Definition View.h:170
SDL_Size minSize
The minimum size this View may be resized to during layout.
Definition View.h:212
Object object
The superclass.
Definition View.h:139
Style * computedStyle
The computed Style of this View.
Definition View.h:186
Set * classNames
The class names.
Definition View.h:176
ViewInterface * interface
The interface.
Definition View.h:145
SDL_Size maxSize
The maximum size this View may be resized to during layout.
Definition View.h:207
SDL_Color backgroundColor
The background color.
Definition View.h:160
SDL_Rect frame
The frame, relative to the superview.
Definition View.h:191
bool hidden
If true, this View is not drawn.
Definition View.h:196
Spacing applied to the inside of a View's frame.
Definition View.h:100
int bottom
Definition View.h:101