ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Text Struct Reference

Text rendered with TrueType fonts. More...

#include <Text.h>

Inheritance diagram for Text:
View

Public Member Functions

Class * _Text (void)
 
TextinitWithText (Text *self, const char *text, Font *font)
 Initializes this Text with the given text and Font.
 
SDL_Size naturalSize (const Text *self)
 Resolves the rendered size of this Text.
 
void setFont (Text *self, Font *font)
 Sets this Text's font.
 
void setText (Text *self, const char *text)
 Sets this Text's text.
 
void setTextWithFormat (Text *self, const char *fmt,...)
 Sets this Text's text with the given format string.
 
- Public Member Functions inherited from View
Class * _View (void)
 The View archetype.
 
bool acceptsKeyResponder (const View *self)
 
bool acceptsTouchResponder (const View *self)
 
void addClassName (View *self, const char *className)
 Adds the given class name to this View.
 
void addSubview (View *self, View *subview)
 Adds a subview to this view, to be drawn above its siblings.
 
void addSubviewRelativeTo (View *self, View *subview, View *other, ViewPosition position)
 Adds a subview to this view, positioned relatively to other.
 
 ancestorWithIdentifier (const View *self, const char *identifier)
 
void applyStyle (View *self, const Style *style)
 Applies the given Style to this View.
 
void applyTheme (View *self, const Theme *theme)
 Applies the given Theme to this View.
 
void applyThemeIfNeeded (View *self, const Theme *theme)
 Recursively applies the Theme to this View and its subviews.
 
void attachStylesheet (View *self, SDL_Window *window)
 Attaches this View's Stylesheet to the Theme associated with the given window.
 
void awakeWithCharacters (View *self, const char *chars)
 Wakes this View with the given null-terminated JSON C string.
 
void awakeWithData (View *self, const Data *data)
 Wakes this View with the specified JSON Data.
 
void awakeWithDictionary (View *, const Dictionary *)
 Wakes this View with the specified Dictionary.
 
void awakeWithResource (View *self, const Resource *resource)
 Wakes this View with the specified Resource.
 
void awakeWithResourceName (View *self, const char *name)
 Wakes this View with the Resource by the specified name.
 
void becomeKeyResponder (View *self)
 Become the key responder in the View hierarchy.
 
void becomeTouchResponder (View *self)
 Become the touch responder in the View hierarchy.
 
bool bind (View *self, const Inlet *inlets, const Dictionary *dictionary)
 Performs data binding for the Inlets described in dictionary.
 
SDL_Rect bounds (const View *self)
 
void bringSubviewToFront (View *self, View *subview)
 Brings the specified subview to the front.
 
void clearWarnings (const View *self, WarningType type)
 Clears this View's Warnings matching the given level.
 
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.
 
void didMoveToWindow (View *self, SDL_Window *window)
 Informs this View that it has been added to the View hierachy of the given window.
 
bool didReceiveEvent (const View *self, const SDL_Event *event)
 
void draw (View *self, Renderer *renderer)
 Draws this View.
 
void emitViewEvent (View *self, ViewEvent code, ident data)
 Emits a ViewEvent originating from this View.
 
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.
 
void enumerateAdjacent (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates adjacent siblings of this View, applying enumerator to each.
 
void enumerateAncestors (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all ancestors of this View, applying enumerator to each.
 
void enumerateDescendants (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all descendants of this View, applying enumerator to each.
 
void enumerateSelection (View *self, const char *rule, ViewEnumerator enumerator, ident data)
 Enumerates all Views in the selection matched by rule, applying enumerator to each.
 
void enumerateSiblings (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all siblings of this View, applying enumerator to each.
 
void enumerateSubviews (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates all subviews of this View, applying enumerator to each.
 
void enumerateSuperview (const View *self, ViewEnumerator enumerator, ident data)
 Enumerates the superview of this View, if any, applying enumerator to it.
 
void enumerateVisible (const View *self, ViewEnumerator enumerator, ident data)
 
void enumerateVisible (View *self, ViewEnumerator enumerator, ident data)
 Enumerates this View and its visible descendants, applying enumerator to each.
 
bool hasClassName (const View *self, cosnt char *className)
 
bool hasOverflow (const View *self)
 
ViewhitTest (const View *self, const SDL_Point *point)
 Performs a hit test against this View and its descendants for the given point.
 
Viewinit (View *self)
 Initializes this View.
 
ViewinitWithFrame (View *self, const SDL_Rect *frame)
 Initializes this View with the specified frame.
 
void invalidateStyle (View *self)
 Invalidates the computed Style for this View and its descendants.
 
bool isContainer (const View *self)
 
bool isDescendantOfView (const View *self, const View *view)
 
bool isKeyResponder (const View *self)
 
bool isTouchResponder (const View *self)
 
bool isVisible (const View *self)
 
void layoutIfNeeded (View *self)
 Recursively updates the layout of this View and its subviews.
 
 layoutSubviews (View *self)
 Performs layout for this View's immediate subviews.
 
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.
 
String * path (const View *self)
 
void removeAllClassNames (View *self)
 Removes all class names from this View.
 
void removeAllSubviews (View *self)
 Removes all subviews from this View.
 
void removeClassName (View *self, const char *className)
 Removes the given class name to this View.
 
void removeFromSuperview (View *self)
 Removes this View from its superview.
 
void removeSubview (View *self, View *subview)
 Removes the given subview from this View.
 
void render (View *self, Renderer *renderer)
 Renders this View using the given renderer.
 
void renderDeviceDidReset (View *self)
 Informs this View that the render device has reset.
 
void renderDeviceWillReset (View *self)
 Informs this View that the render device will reset.
 
SDL_Rect renderFrame (const View *self)
 
void replaceSubview (View *self, View *subview, View *replacement)
 Replaces the specified subview with the given replacement.
 
void resignKeyResponder (View *self)
 Resigns key responder priority.
 
void resignTouchResponder (View *self)
 Resigns touch responder priority.
 
void resize (View *self, const SDL_Size *size)
 Resizes this View to the specified size.
 
void resolve (View *self, Outlet *outlets)
 Resolves the given Outlets from this View's hierarchy.
 
void respondToEvent (View *self, const SDL_Event *event)
 Responds to the specified event.
 
Set * select (View *self, const char *rule)
 Resolves all descendants (including this View) that match the given Selector rule.
 
ViewselectFirst (View *self, const char *rule)
 Resolves the first descendant View that matches the given Selector rule.
 
SDL_Size size (const View *self)
 
SDL_Size sizeThastFills (const View *self)
 
SDL_Size sizeThatContains (const View *self)
 
SDL_Size sizeThatFills (const View *self)
 
void sizeThatFits (const View *self)
 
void sizeToContain (View *self)
 Resizes this View to contain its subviews.
 
void sizeToFill (View *self)
 Resizes this View to fill its superview.
 
void sizeToFit (View *self)
 Resizes this View to fit its subviews.
 
 subviewWithIdentifier (const View *self, const char *identifier)
 
void updateBindings (View *self)
 Updates data bindings, prompting the appropriate layout changes.
 
SDL_Rect viewport (const View *self)
 
ViewviewWithCharacters (const char *chars, Outlet *outlets)
 Instantiates a View initialized with the given null-terminated JSON C string.
 
ViewviewWithData (const Data *data, Outlet *outlets)
 Instantiates a View initialized with the contents of data.
 
ViewviewWithDictionary (const Dictionary *dictionary, Outlet *outlets)
 Instantiates a View initialized with the attributes described in dictionary.
 
ViewviewWithResource (const Resource *resource, Outlet *outlets)
 Instantiates a View initialized with the JSON data in resource.
 
ViewviewWithResourceName (const char *name, Outlet *outlets)
 Instantiates a View initialized with the JSON Resource with the specified name.
 
Array * visibleSubviews (const View *self)
 
void warn (View *self, ViewWarningType type, const char *fmt,...)
 
void warn (View *self, WarningType level, const char *fmt,...)
 Appends a warning for this View.
 
void willMoveToWindow (View *self, SDL_Window *window)
 Informs this View that it will be added to the View hierarchy for the given window.
 

Data Fields

SDL_Color color
 The text color.
 
bool colorEscapes
 If true, render text with color escape sequence support (^0-^7).
 
Fontfont
 The Font.
 
bool lineWrap
 If true, wrap text along word boundaries to fit this Text's width.
 
char * text
 The text.
 
View view
 The superclass.
 
- Data Fields inherited from View
ViewAlignment alignment
 The alignment.
 
int autoresizingMask
 The ViewAutoresizing bitmask.
 
SDL_Color backgroundColor
 The background color.
 
SDL_Color borderColor
 The border color.
 
int borderWidth
 The border width.
 
Set * classNames
 The class names.
 
bool clipsSubviews
 If true, subviews will be clipped to this View's frame.
 
StylecomputedStyle
 The computed Style of this View.
 
SDL_Rect frame
 The frame, relative to the superview.
 
bool hidden
 If true, this View is not drawn.
 
char * identifier
 An optional identifier.
 
SDL_Size maxSize
 The maximum size this View may be resized to during layout.
 
SDL_Size minSize
 The minimum size this View may be resized to during layout.
 
bool needsApplyTheme
 If true, this View will apply the Theme before it is drawn.
 
bool needsLayout
 If true, this View will layout its subviews before it is drawn.
 
ViewnextResponder
 The next responder, or event handler, in the chain.
 
Object object
 The superclass.
 
ViewPadding padding
 The padding.
 
Stylestyle
 The element-level Style of this View.
 
Stylesheetstylesheet
 An optional Stylesheet.
 
Array * subviews
 The immediate subviews.
 
Viewsuperview
 The super View.
 
ViewControllerviewController
 The ViewController.
 
Array * warnings
 The Warnings this View generated.
 
SDL_Window * window
 The window.
 

Protected Attributes

TextInterface * interface
 The interface.
 
Texture * texture
 The rendered GPU texture.
 
SDL_Size textureSize
 The logical draw dimensions of the texture (surface size / pixel density).
 
- Protected Attributes inherited from View
ViewInterface * interface
 The interface.
 

Detailed Description

Text rendered with TrueType fonts.

Definition at line 69 of file Text.h.

Member Function Documentation

◆ _Text()

Class * _Text ( void  )

Definition at line 602 of file Text.c.

602 {
603 static Class *clazz;
604 static Once once;
605
606 do_once(&once, {
607 clazz = _initialize(&(const ClassDef) {
608 .name = "Text",
609 .superclass = _View(),
610 .instanceSize = sizeof(Text),
611 .interfaceOffset = offsetof(Text, interface),
612 .interfaceSize = sizeof(TextInterface),
614 });
615 });
616
617 return clazz;
618}
static void initialize(Class *clazz)
Definition Box.c:123
Text rendered with TrueType fonts.
Definition Text.h:69
TextInterface * interface
The interface.
Definition Text.h:80
Class * _View(void)
The View archetype.
Definition View.c:2067

◆ initWithText()

Text * initWithText ( Text self,
const char *  text,
Font font 
)

Initializes this Text with the given text and Font.

Parameters
selfThe Text.
textThe text.
fontThe Font (optional).
Returns
The initialized Text, or NULL on error.

Definition at line 476 of file Text.c.

476 {
477
478 self = (Text *) super(View, self, initWithFrame, NULL);
479 if (self) {
480 $(self, setFont, font);
481 $(self, setText, text);
482 }
483
484 return self;
485}
void setFont(Text *self, Font *font)
Sets this Text's font.
Definition Text.c:512
void setText(Text *self, const char *text)
Sets this Text's text.
Definition Text.c:532
Font * font
The Font.
Definition Text.h:92
char * text
The text.
Definition Text.h:113
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134
View * initWithFrame(View *self, const SDL_Rect *frame)
Initializes this View with the specified frame.
Definition View.c:989

◆ naturalSize()

SDL_Size naturalSize ( const Text self)

Resolves the rendered size of this Text.

Parameters
selfThe Text.

Definition at line 491 of file Text.c.

491 {
492
493 SDL_Size size = MakeSize(0, 0);
494
495 if (self->font) {
496 const char *text = self->text ?: "";
497
498 if (self->colorEscapes) {
499 sizeWithColorEscapes(self, &size.w, &size.h);
500 } else {
501 $(self->font, sizeCharacters, text, &size.w, &size.h);
502 }
503 }
504
505 return size;
506}
static void sizeCharacters(const Font *self, const char *chars, int *w, int *h)
Definition Font.c:273
static void sizeWithColorEscapes(const Text *self, int *w, int *h)
Resolves the rendered size of this Text's content, stripping color escapes.
Definition Text.c:228
bool colorEscapes
If true, render text with color escape sequence support (^0-^7).
Definition Text.h:101
SDL_Size size(const View *self)
Definition View.c:1651

◆ setFont()

void setFont ( Text self,
Font font 
)

Sets this Text's font.

Parameters
selfThe Text.
fontThe Font to set.

Definition at line 512 of file Text.c.

512 {
513
514 font = font ?: $$(Font, defaultFont);
515
516 if (font != self->font) {
517
518 release(self->font);
519 self->font = retain(font);
520
521 self->texture = release(self->texture);
522 self->textureSize = MakeSize(0, 0);
523
524 $((View *) self, sizeToFit);
525 }
526}
static Font * defaultFont(void)
Definition Font.c:177
TrueType fonts.
Definition Font.h:63
SDL_Size textureSize
The logical draw dimensions of the texture (surface size / pixel density).
Definition Text.h:126
Texture * texture
The rendered GPU texture.
Definition Text.h:119
void sizeToFit(View *self)
Resizes this View to fit its subviews.
Definition View.c:1767

◆ setText()

void setText ( Text self,
const char *  text 
)

Sets this Text's text.

Parameters
selfThe Text.
textThe text to set.

Definition at line 532 of file Text.c.

532 {
533
534 if (strcmp(self->text ?: "", text ?: "")) {
535
536 free(self->text);
537
538 if (text && strlen(text)) {
539 self->text = strdup(text);
540 } else {
541 self->text = NULL;
542 }
543
544 self->texture = release(self->texture);
545 self->textureSize = MakeSize(0, 0);
546
547 $((View *) self, sizeToFit);
548 }
549}

◆ setTextWithFormat()

void setTextWithFormat ( Text self,
const char *  fmt,
  ... 
)

Sets this Text's text with the given format string.

Parameters
selfThe Text.
fmtThe format string.

Definition at line 558 of file Text.c.

558 {
559
560 va_list args;
561 va_start(args, fmt);
562
563 char *text;
564 const int len = vasprintf(&text, fmt, args);
565 if (len >= 0) {
566 $(self, setText, text);
567 }
568
569 free(text);
570 va_end(args);
571}

Field Documentation

◆ color

SDL_Color Text::color

The text color.

Definition at line 85 of file Text.h.

◆ colorEscapes

bool Text::colorEscapes

If true, render text with color escape sequence support (^0-^7).

Remarks
Enables per-character colorization via Font::renderCharactersWithColors. Only enable for Text that uses color escape sequences, as the code path is significantly more expensive than plain rendering.
See also
FontEscapeColors

Definition at line 101 of file Text.h.

◆ font

Font* Text::font

The Font.

Remarks
Do not set this property directly.
See also
Text::setFont(Text *, Font *)

Definition at line 92 of file Text.h.

◆ interface

TextInterface* Text::interface
protected

The interface.

Definition at line 80 of file Text.h.

◆ lineWrap

bool Text::lineWrap

If true, wrap text along word boundaries to fit this Text's width.

Definition at line 106 of file Text.h.

◆ text

char* Text::text

The text.

Remarks
Do not set this property directly.
See also
Text::setText(Text *, const char *)

Definition at line 113 of file Text.h.

◆ texture

Texture* Text::texture
protected

The rendered GPU texture.

Definition at line 119 of file Text.h.

◆ textureSize

SDL_Size Text::textureSize
protected

The logical draw dimensions of the texture (surface size / pixel density).

Remarks
Stored when the texture is created; used for pixel-perfect rendering.

Definition at line 126 of file Text.h.

◆ view

View Text::view

The superclass.

Definition at line 74 of file Text.h.


The documentation for this struct was generated from the following files: