ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
View.h File Reference

Views are the fundamental building blocks of ObjectivelyMVC user interfaces. More...

#include <Objectively/Data.h>
#include <Objectively/Enum.h>
#include <Objectively/Dictionary.h>
#include <Objectively/Array.h>
#include <Objectively/Set.h>
#include <Objectively/Resource.h>
#include <ObjectivelyMVC/Colors.h>
#include <ObjectivelyMVC/Renderer.h>
#include <ObjectivelyMVC/Theme.h>
#include <ObjectivelyMVC/View+JSON.h>
#include <ObjectivelyMVC/Warning.h>

Go to the source code of this file.

Data Structures

struct  View
 Views are the fundamental building blocks of ObjectivelyMVC user interfaces. More...
 
struct  ViewPadding
 Spacing applied to the inside of a View's frame. More...
 

Macros

#define AddPadding(a, b)    MakePadding(a.top + b.top, a.right + b.right, a.bottom + b.bottom, a.left + b.left)
 
#define MakePadding(top, right, bottom, left)    (ViewPadding) { (top), (right), (bottom), (left) }
 Creates a ViewPadding with the given dimensions.
 
#define ViewAlignmentMaskBottom   0x4
 
#define ViewAlignmentMaskCenter   0x10
 
#define ViewAlignmentMaskHorizontal    (ViewAlignmentMaskLeft | ViewAlignmentMaskCenter | ViewAlignmentMaskRight)
 
#define ViewAlignmentMaskInternal   0x100
 
#define ViewAlignmentMaskLeft   0x8
 
#define ViewAlignmentMaskMiddle   0x2
 
#define ViewAlignmentMaskRight   0x20
 
#define ViewAlignmentMaskTop   0x1
 
#define ViewAlignmentMaskVertical    (ViewAlignmentMaskTop | ViewAlignmentMaskMiddle | ViewAlignmentMaskBottom)
 

Enumerations

enum  ViewAlignment {
  ViewAlignmentNone , ViewAlignmentTop = ViewAlignmentMaskTop , ViewAlignmentMiddle = ViewAlignmentMaskMiddle , ViewAlignmentBottom = ViewAlignmentMaskBottom ,
  ViewAlignmentLeft = ViewAlignmentMaskLeft , ViewAlignmentCenter = ViewAlignmentMaskCenter , ViewAlignmentRight = ViewAlignmentMaskRight , ViewAlignmentTopLeft = (ViewAlignmentMaskTop | ViewAlignmentMaskLeft) ,
  ViewAlignmentTopCenter = (ViewAlignmentMaskTop | ViewAlignmentMaskCenter) , ViewAlignmentTopRight = (ViewAlignmentMaskTop | ViewAlignmentMaskRight) , ViewAlignmentMiddleLeft = (ViewAlignmentMaskMiddle | ViewAlignmentMaskLeft) , ViewAlignmentMiddleCenter = (ViewAlignmentMaskMiddle | ViewAlignmentMaskCenter) ,
  ViewAlignmentMiddleRight = (ViewAlignmentMaskMiddle | ViewAlignmentMaskRight) , ViewAlignmentBottomLeft = (ViewAlignmentMaskBottom | ViewAlignmentMaskLeft) , ViewAlignmentBottomCenter = (ViewAlignmentMaskBottom | ViewAlignmentMaskCenter) , ViewAlignmentBottomRight = (ViewAlignmentMaskBottom | ViewAlignmentMaskRight) ,
  ViewAlignmentInternal = ViewAlignmentMaskInternal
}
 Alignment constants, used to align a View within its superview. More...
 
enum  ViewAutoresizing {
  ViewAutoresizingNone = 0 , ViewAutoresizingWidth = 0x1 , ViewAutoresizingHeight = 0x2 , ViewAutoresizingFill = 0x3 ,
  ViewAutoresizingFit = 0x4 , ViewAutoresizingContain = 0x8
}
 Auto-resizing constants, which are bitmasked. More...
 
enum  ViewPosition { ViewPositionBefore = -1 , ViewPositionAfter = 1 }
 Relative positioning of subviews within their superview. More...
 

Functions

OBJECTIVELYMVC_EXPORT Class * _View (void)
 

Variables

OBJECTIVELYMVC_EXPORT const EnumName ViewAlignmentNames []
 
OBJECTIVELYMVC_EXPORT const EnumName ViewAutoresizingNames []
 

Detailed Description

Views are the fundamental building blocks of ObjectivelyMVC user interfaces.

Definition in file View.h.

Macro Definition Documentation

◆ AddPadding

#define AddPadding (   a,
 
)     MakePadding(a.top + b.top, a.right + b.right, a.bottom + b.bottom, a.left + b.left)
Returns
A ViewPadding that is the sum of a and b.

Definition at line 113 of file View.h.

118 {
122
123typedef struct ViewInterface ViewInterface;
124
133struct View {
134
138 Object object;
139
144 ViewInterface *interface;
145
150
155
159 SDL_Color backgroundColor;
160
164 SDL_Color borderColor;
165
169 int borderWidth;
170
175 Set *classNames;
176
180 bool clipsSubviews;
181
186
190 SDL_Rect frame;
191
195 bool hidden;
196
201 char *identifier;
202
206 SDL_Size maxSize;
207
211 SDL_Size minSize;
212
216 bool needsApplyTheme;
217
221 bool needsLayout;
222
229
234
240 Style *style;
241
248
252 Array *subviews;
253
259
265
270 Array *warnings;
271
276 SDL_Window *window;
277};
278
282struct ViewInterface {
283
287 ObjectInterface parentInterface;
288
295 bool (*acceptsKeyResponder)(const View *self);
296
303 bool (*acceptsTouchResponder)(const View *self);
304
312 void (*addClassName)(View *self, const char *className);
313
322 void (*addSubview)(View *self, View *subview);
323
333 void (*addSubviewRelativeTo)(View *self, View *subview, View *other, ViewPosition position);
334
342 View *(*ancestorWithIdentifier)(const View *self, const char *identifier);
343
351 void (*applyStyle)(View *self, const Style *style);
352
360 void (*applyTheme)(View *self, const Theme *theme);
361
369 void (*applyThemeIfNeeded)(View *self, const Theme *theme);
370
378 void (*attachStylesheet)(View *self, SDL_Window *window);
379
388 void (*awakeWithCharacters)(View *self, const char *chars);
389
398 void (*awakeWithData)(View *self, const Data *data);
399
409 void (*awakeWithDictionary)(View *self, const Dictionary *dictionary);
410
418 void (*awakeWithResource)(View *self, const Resource *resource);
419
427 void (*awakeWithResourceName)(View *self, const char *name);
428
436 void (*becomeKeyResponder)(View *self);
437
445 void (*becomeTouchResponder)(View *self);
446
457 bool (*bind)(View *self, const Inlet *inlets, const Dictionary *dictionary);
458
465 SDL_Rect (*bounds)(const View *self);
466
474 void (*bringSubviewToFront)(View *self, View *subview);
475
483 void (*clearWarnings)(const View *self, WarningType level);
484
493 SDL_Rect (*clippingFrame)(const View *self);
494
502 bool (*containsPoint)(const View *self, const SDL_Point *point);
503
510 int (*depth)(const View *self);
511
519 View *(*descendantWithIdentifier)(const View *self, const char *identifier);
520
528 void (*detachStylesheet)(View *self, SDL_Window *window);
529
537 void (*didMoveToWindow)(View *self, SDL_Window *window);
538
546 bool (*didReceiveEvent)(const View *self, const SDL_Event *event);
547
558 void (*draw)(View *self, Renderer *renderer);
559
570 void (*emitViewEvent)(View *self, ViewEvent code, ident data);
571
580 void (*enumerate)(View *self, ViewEnumerator enumerator, ident data);
581
590 void (*enumerateAdjacent)(const View *self, ViewEnumerator enumerator, ident data);
591
600 void (*enumerateAncestors)(const View *self, ViewEnumerator enumerator, ident data);
601
610 void (*enumerateDescendants)(const View *self, ViewEnumerator enumerator, ident data);
611
621 void (*enumerateSelection)(View *self, const char *rule, ViewEnumerator enumerator, ident data);
622
631 void (*enumerateSiblings)(const View *self, ViewEnumerator enumerator, ident data);
632
641 void (*enumerateSubviews)(const View *self, ViewEnumerator enumerator, ident data);
642
651 void (*enumerateSuperview)(const View *self, ViewEnumerator enumerator, ident data);
652
662 void (*enumerateVisible)(View *self, ViewEnumerator enumerator, ident data);
663
671 bool (*hasClassName)(const View *self, const char *className);
672
679 bool (*hasOverflow)(const View *self);
680
689 View *(*hitTest)(const View *self, const SDL_Point *point);
690
701 View *(*init)(View *self);
702
712 View *(*initWithFrame)(View *self, const SDL_Rect *frame);
713
720 void (*invalidateStyle)(View *self);
721
728 bool (*isContainer)(const View *self);
729
737 bool (*isDescendantOfView)(const View *self, const View *view);
738
745 bool (*isKeyResponder)(const View *self);
746
753 bool (*isTouchResponder)(const View *self);
754
761 bool (*isVisible)(const View *self);
762
769 void (*layoutIfNeeded)(View *self);
770
779 void (*layoutSubviews)(View *self);
780
788 bool (*matchesSelector)(const View *self, const SimpleSelector *simpleSelector);
789
797 void (*moveToWindow)(View *self, SDL_Window *window);
798
805 String *(*path)(const View *self);
806
813 void (*removeAllClassNames)(View *self);
814
821 void (*removeAllSubviews)(View *self);
822
830 void (*removeClassName)(View *self, const char *className);
831
838 void (*removeFromSuperview)(View *self);
839
847 void (*removeSubview)(View *self, View *subview);
848
858 void (*render)(View *self, Renderer *renderer);
859
867 void (*renderDeviceDidReset)(View *self);
868
876 void (*renderDeviceWillReset)(View *self);
877
884 SDL_Rect (*renderFrame)(const View *self);
885
894 void (*replaceSubview)(View *self, View *subview, View *replacement);
895
902 void (*resignKeyResponder)(View *self);
903
910 void (*resignTouchResponder)(View *self);
911
919 void (*resize)(View *self, const SDL_Size *size);
920
928 void (*resolve)(View *self, Outlet *outlets);
929
937 void (*respondToEvent)(View *self, const SDL_Event *event);
938
947 Set *(*select)(View *self, const char *rule);
948
957 View *(*selectFirst)(View *self, const char *rule);
958
965 SDL_Size (*size)(const View *self);
966
974 SDL_Size (*sizeThatContains)(const View *self);
975
984 SDL_Size (*sizeThatFits)(const View *self);
985
992 SDL_Size (*sizeThatFills)(const View *self);
993
1001 void (*sizeToContain)(View *self);
1002
1010 void (*sizeToFill)(View *self);
1011
1019 void (*sizeToFit)(View *self);
1020
1028 View *(*subviewWithIdentifier)(const View *self, const char *identifier);
1029
1037 void (*updateBindings)(View *self);
1038
1045 SDL_Rect (*viewport)(const View *self);
1046
1056 View *(*viewWithCharacters)(const char *chars, Outlet *outlets);
1057
1067 View *(*viewWithData)(const Data *data, Outlet *outlets);
1068
1079 View *(*viewWithDictionary)(const Dictionary *dictionary, Outlet *outlets);
1080
1091 View *(*viewWithResource)(const Resource *resource, Outlet *outlets);
1092
1103 View *(*viewWithResourceName)(const char *name, Outlet *outlets);
1104
1112 Array *(*visibleSubviews)(const View *self);
1113
1122 void (*warn)(View *self, WarningType level, const char *fmt, ...);
1123
1131 void (*willMoveToWindow)(View *self, SDL_Window *window);
1132};
1133
1140OBJECTIVELYMVC_EXPORT Class *_View(void);
static Theme * theme(SDL_Window *window)
Definition Theme.c:143
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
OBJECTIVELYMVC_EXPORT Class * _View(void)
Definition View.c:2067
ViewPosition
Relative positioning of subviews within their superview.
Definition View.h:119
@ ViewPositionBefore
Definition View.h:120
@ ViewPositionAfter
Definition View.h:121
ViewAlignment
Alignment constants, used to align a View within its superview.
Definition View.h:61
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

◆ MakePadding

#define MakePadding (   top,
  right,
  bottom,
  left 
)     (ViewPadding) { (top), (right), (bottom), (left) }

Creates a ViewPadding with the given dimensions.

Definition at line 107 of file View.h.

108 { (top), (right), (bottom), (left) }

◆ ViewAlignmentMaskBottom

#define ViewAlignmentMaskBottom   0x4

Definition at line 46 of file View.h.

◆ ViewAlignmentMaskCenter

#define ViewAlignmentMaskCenter   0x10

Definition at line 48 of file View.h.

◆ ViewAlignmentMaskHorizontal

#define ViewAlignmentMaskHorizontal    (ViewAlignmentMaskLeft | ViewAlignmentMaskCenter | ViewAlignmentMaskRight)

Definition at line 55 of file View.h.

◆ ViewAlignmentMaskInternal

#define ViewAlignmentMaskInternal   0x100

Definition at line 50 of file View.h.

◆ ViewAlignmentMaskLeft

#define ViewAlignmentMaskLeft   0x8

Definition at line 47 of file View.h.

◆ ViewAlignmentMaskMiddle

#define ViewAlignmentMaskMiddle   0x2

Definition at line 45 of file View.h.

◆ ViewAlignmentMaskRight

#define ViewAlignmentMaskRight   0x20

Definition at line 49 of file View.h.

◆ ViewAlignmentMaskTop

#define ViewAlignmentMaskTop   0x1

Definition at line 44 of file View.h.

◆ ViewAlignmentMaskVertical

#define ViewAlignmentMaskVertical    (ViewAlignmentMaskTop | ViewAlignmentMaskMiddle | ViewAlignmentMaskBottom)

Definition at line 52 of file View.h.

Enumeration Type Documentation

◆ ViewAlignment

Alignment constants, used to align a View within its superview.

Enumerator
ViewAlignmentNone 
ViewAlignmentTop 
ViewAlignmentMiddle 
ViewAlignmentBottom 
ViewAlignmentLeft 
ViewAlignmentCenter 
ViewAlignmentRight 
ViewAlignmentTopLeft 
ViewAlignmentTopCenter 
ViewAlignmentTopRight 
ViewAlignmentMiddleLeft 
ViewAlignmentMiddleCenter 
ViewAlignmentMiddleRight 
ViewAlignmentBottomLeft 
ViewAlignmentBottomCenter 
ViewAlignmentBottomRight 
ViewAlignmentInternal 

Definition at line 61 of file View.h.

61 {
#define ViewAlignmentMaskInternal
Definition View.h:50
#define ViewAlignmentMaskCenter
Definition View.h:48
#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
@ 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

◆ ViewAutoresizing

Auto-resizing constants, which are bitmasked.

Enumerator
ViewAutoresizingNone 
ViewAutoresizingWidth 
ViewAutoresizingHeight 
ViewAutoresizingFill 
ViewAutoresizingFit 
ViewAutoresizingContain 

Definition at line 86 of file View.h.

86 {
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

◆ ViewPosition

Relative positioning of subviews within their superview.

Enumerator
ViewPositionBefore 
ViewPositionAfter 

Definition at line 119 of file View.h.

119 {

Function Documentation

◆ _View()

OBJECTIVELYMVC_EXPORT Class * _View ( void  )

Definition at line 2067 of file View.c.

2067 {
2068 static Class *clazz;
2069 static Once once;
2070
2071 do_once(&once, {
2072 clazz = _initialize(&(const ClassDef) {
2073 .name = "View",
2074 .superclass = _Object(),
2075 .instanceSize = sizeof(View),
2076 .interfaceOffset = offsetof(View, interface),
2077 .interfaceSize = sizeof(ViewInterface),
2079 });
2080 });
2081
2082 return clazz;
2083}
static void initialize(Class *clazz)
Definition View.c:1960

Variable Documentation

◆ ViewAlignmentNames

OBJECTIVELYMVC_EXPORT const EnumName ViewAlignmentNames[]

Definition at line 81 of file View.h.

◆ ViewAutoresizingNames

OBJECTIVELYMVC_EXPORT const EnumName ViewAutoresizingNames[]

Definition at line 95 of file View.h.