|
ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
|
#include <assert.h>#include <math.h>#include <stdarg.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include "Colors.h"#include "Text.h"#include "Theme.h"Go to the source code of this file.
Data Structures | |
| struct | LayoutBuffer |
| A growable string for MVC_LayoutText. More... | |
Macros | |
| #define | _Class _Text |
| #define | _GNU_SOURCE |
Functions | |
| Class * | _Text (void) |
| static void | append (LayoutBuffer *buffer, const char *chars, size_t length) |
| static void | appendRuns (Text *self, TTF_Text *layout, const TextSpan *span, int surfaceWidth) |
Appends the runs for one TextSpan of layout: one color run per line the span touches, or a single icon run positioned by the span's first line. | |
| static void | appendSpan (TextSpan **spans, size_t *count, TextSpan span) |
| static void | applyStyle (View *self, const Style *style) |
| static void | applyTransform (Text *self) |
Rebuilds transformed from text and transform. Color escapes pass through without counting as letters, and icon escapes that resolve against the window's Theme are copied verbatim, since icon names are case sensitive. | |
| static void | awakeWithDictionary (View *self, const Dictionary *dictionary) |
| static void | buildRuns (Text *self, const char *layoutText, const TextSpan *spans, size_t count, int wrapWidth, int surfaceWidth) |
| Builds this Text's runs for its rendered texture: the texture is rendered from the layout string in white, so each color run is a region of it drawn in the color in effect for those characters, and each icon run is the placeholder region an icon is drawn over. The layout is SDL_ttf's own, so the regions are exact glyph clusters, including where wrapping broke the lines. | |
| static void | checkIcons (Text *self) |
Invalidates this Text if the icon atlas it was prepared against has changed: a Theme swap, attaching to a window, or an icon registered since. Sets needsLayout when it does, since the natural size may have changed. | |
| static size_t | colorEscapeLength (const char *chars) |
Length of the color escape at chars, or 0 if there is none: ^N selects a color, ^^ is a literal caret. | |
| static void | dealloc (Object *self) |
| static String * | description (const Object *self) |
| static void | didMoveToWindow (View *self, SDL_Window *window) |
| static const char * | displayText (const Text *self) |
| static bool | hasEscapes (const char *text) |
| static const char * | iconPlaceholder (const Font *font) |
The placeholder an icon occupies in font's layout: a codepoint that is not a line-break opportunity, repeated until it is at least a line height wide. Resolved once per Font, on first use. | |
| static ImageAtlas * | iconsFor (const Text *self) |
| static View * | init (View *self) |
| static void | initialize (Class *clazz) |
| static Text * | initWithText (Text *self, const char *text, Font *font) |
| static void | invalidate (Text *self) |
| Releases this Text's rendered texture and runs, and invalidates its cached size. | |
| bool | MVC_HasColorEscapes (const char *text) |
| size_t | MVC_IconEscapeLength (const char *chars, const ImageAtlas *icons, AtlasImage **image) |
Parses an icon escape at the start of chars: :name:, where name is one or more of [A-Za-z0-9_-] and under 64 bytes, and is registered in icons. An unregistered name is not an escape, so 12:30:45 stays literal unless someone registers an icon called 30. | |
| char * | MVC_LayoutText (const Font *font, const char *text, SDL_Color color, const ImageAtlas *icons, TextSpan **spans, size_t *count) |
Resolves the escapes in text into the string to lay out and the spans to draw it as. | |
| char * | MVC_StripColorEscapes (const char *text) |
Strips color escape sequences from the given text: ^0 through ^9 are removed, and ^^ collapses to ^. | |
| static SDL_Size | naturalSize (const Text *self) |
| static void | refreshFont (Text *self) |
| Re-resolves this Text's Font at the current window's pixel density. Shared by didMoveToWindow and renderDeviceDidReset, rather than the latter dispatching through the public didMoveToWindow, which would re-trigger View's own attachment side effects. | |
| static void | render (View *self, Renderer *renderer) |
| static void | renderDeviceDidReset (View *self) |
| static void | renderDeviceWillReset (View *self) |
| static void | resolveFont (Text *self, const FontAttributes *attributes) |
| Resolves and applies the Font with the given attributes: through the window's Theme when attached, which supplies the window's pixel density, or at a density of 1.0 otherwise, to be re-resolved on attachment via View::didMoveToWindow. The cache's reference is retained to mirror the owned reference the fallback returns. | |
| static void | setFont (Text *self, Font *font) |
| static void | setText (Text *self, const char *text) |
| static void | setTextWithFormat (Text *self, const char *fmt,...) |
| static void | setTransform (Text *self, TextTransform transform) |
| static SDL_Size | sizeText (const Text *self, const char *text) |
| static SDL_Size | sizeThatFits (const View *self) |
Variables | |
| SDL_Color | TextEscapeColors [] |
| const EnumName | TextTransformNames [] |
| Class * _Text | ( | void | ) |
Definition at line 988 of file Text.c.
|
static |
|
static |
Appends the runs for one TextSpan of layout: one color run per line the span touches, or a single icon run positioned by the span's first line.
Definition at line 400 of file Text.c.
Definition at line 534 of file Text.c.
|
static |
Rebuilds transformed from text and transform. Color escapes pass through without counting as letters, and icon escapes that resolve against the window's Theme are copied verbatim, since icon names are case sensitive.
Definition at line 311 of file Text.c.
|
static |
Definition at line 581 of file Text.c.
|
static |
Builds this Text's runs for its rendered texture: the texture is rendered from the layout string in white, so each color run is a region of it drawn in the color in effect for those characters, and each icon run is the placeholder region an icon is drawn over. The layout is SDL_ttf's own, so the regions are exact glyph clusters, including where wrapping broke the lines.
Definition at line 448 of file Text.c.
|
static |
Invalidates this Text if the icon atlas it was prepared against has changed: a Theme swap, attaching to a window, or an icon registered since. Sets needsLayout when it does, since the natural size may have changed.
Definition at line 368 of file Text.c.
|
static |
|
static |
Definition at line 495 of file Text.c.
|
static |
Definition at line 512 of file Text.c.
|
static |
Definition at line 624 of file Text.c.
|
static |
|
static |
|
static |
The placeholder an icon occupies in font's layout: a codepoint that is not a line-break opportunity, repeated until it is at least a line height wide. Resolved once per Font, on first use.
Measured with TTF_GetStringSize, the same engine that lays out and renders the text, rather than glyph metrics: Coda has no U+00A0, and shaping substitutes the space glyph for it at the space's advance, where the glyph metrics would report .notdef's.
Definition at line 171 of file Text.c.
|
static |
NULL when detached. Definition at line 297 of file Text.c.
Definition at line 642 of file Text.c.
|
static |
Definition at line 961 of file Text.c.
|
static |
| bool MVC_HasColorEscapes | ( | const char * | text | ) |
| size_t MVC_IconEscapeLength | ( | const char * | chars, |
| const ImageAtlas * | icons, | ||
| AtlasImage ** | image | ||
| ) |
Parses an icon escape at the start of chars: :name:, where name is one or more of [A-Za-z0-9_-] and under 64 bytes, and is registered in icons. An unregistered name is not an escape, so 12:30:45 stays literal unless someone registers an icon called 30.
| chars | The text, positioned at a candidate :. |
| icons | The icon ImageAtlas, or NULL for none. |
| image | If not NULL, receives the icon, or NULL. |
0 if chars does not start with one. Definition at line 104 of file Text.c.
| char * MVC_LayoutText | ( | const Font * | font, |
| const char * | text, | ||
| SDL_Color | color, | ||
| const ImageAtlas * | icons, | ||
| TextSpan ** | spans, | ||
| size_t * | count | ||
| ) |
Resolves the escapes in text into the string to lay out and the spans to draw it as.
^N selects a color for what follows, ^^ becomes ^, and a registered :icon: becomes a run of placeholder characters at least a line height wide, for the icon to be drawn over. The placeholder is never a line-break opportunity, so an icon stays with its word. With no icons, and spans NULL, the result is that of MVC_StripColorEscapes.
| font | The Font the text will be laid out in. |
| text | The text. |
| color | The color in effect at the start of text. |
| icons | The icon ImageAtlas, or NULL for none. |
| spans | If not NULL, receives the spans, which the caller MUST free. |
| count | If not NULL, receives the number of spans; meaningful only with spans. |
Definition at line 220 of file Text.c.
| char * MVC_StripColorEscapes | ( | const char * | text | ) |
Strips color escape sequences from the given text: ^0 through ^9 are removed, and ^^ collapses to ^.
| text | The text. |
text without escape sequences. The caller must free it. Definition at line 83 of file Text.c.
|
static |
Definition at line 823 of file Text.c.
|
static |
Re-resolves this Text's Font at the current window's pixel density. Shared by didMoveToWindow and renderDeviceDidReset, rather than the latter dispatching through the public didMoveToWindow, which would re-trigger View's own attachment side effects.
Definition at line 649 of file Text.c.
|
static |
|
static |
|
static |
Resolves and applies the Font with the given attributes: through the window's Theme when attached, which supplies the window's pixel density, or at a density of 1.0 otherwise, to be re-resolved on attachment via View::didMoveToWindow. The cache's reference is retained to mirror the owned reference the fallback returns.
Definition at line 470 of file Text.c.
|
static |
Definition at line 899 of file Text.c.
|
static |
|
static |
Definition at line 944 of file Text.c.
|
static |
Definition at line 853 of file Text.c.
|
static |
| SDL_Color TextEscapeColors[] |
Definition at line 41 of file Text.c.
| const EnumName TextTransformNames[] |