Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
UI_text.h File Reference

Implements text rendering and management for the UI system. More...

#include <UI.h>
#include <SDL_ttf.h>

Go to the source code of this file.

Classes

struct  UI_TextData
 Data structure for UI text elements. More...
 

Typedefs

typedef struct UI_TextData UI_TextData
 Data structure for UI text elements.
 

Enumerations

enum  UI_TextAlignment { UI_TEXT_ALIGN_LEFT , UI_TEXT_ALIGN_CENTER , UI_TEXT_ALIGN_RIGHT }
 An enum for text alignment. More...
 

Functions

UIElement * UI_CreateText (const char *text, SDL_Rect rect, SDL_Color color, float scale, UI_TextAlignment alignment, TTF_Font *font)
 
SDL_Texture * UI_CreateTextTexture (const char *text, SDL_Color color, TTF_Font *font)
 
void UI_UpdateText (UIElement *element)
 
void UI_RenderText (UIElement *element)
 
void UI_DestroyText (UIElement *element)
 
void UI_ChangeText (UIElement *element, const char *text)
 
void UI_ChangeTextColor (UIElement *element, SDL_Color color)
 
void UI_SetHovered (UIElement *element, bool hovered)
 
bool UI_IsHovered (UIElement *element)
 

Detailed Description

Implements text rendering and management for the UI system.

Author
Mango
Date
2025-03-12

Usage Examples

Creating and managing text elements:

// Create a simple text element
UIElement* titleText = UI_CreateText(
"Operation Null Mind", // Text content
(SDL_Rect){400, 100, 400, 50}, // Position and size of text box
(SDL_Color){255, 255, 255, 255}, // Color
1.5f, // Scale (text size)
UI_TEXT_ALIGN_CENTER, // Alignment // Alignment (Look at UI_TextAlignment enum)
app.resources.fonts.titleFont // Font
);
// Changing text content dynamically
UI_ChangeText(scoreText, "Score: 1500");
// Changing text color
UI_ChangeTextColor(warningText, (SDL_Color){255, 0, 0, 255});
void UI_ChangeTextColor(UIElement *element, SDL_Color color)
Definition UI_text.c:135
void UI_ChangeText(UIElement *element, const char *text)
Definition UI_text.c:125
UIElement * UI_CreateText(const char *text, SDL_Rect rect, SDL_Color color, float scale, UI_TextAlignment alignment, TTF_Font *font)
Definition UI_text.c:38
@ UI_TEXT_ALIGN_CENTER
Definition UI_text.h:40
AppData app
A global variable containing the app's resources, state, and configurations.
AppResources resources
The app's resources.
Definition app.h:108
UI Element structure.
Definition UI.h:55

Typedef Documentation

◆ UI_TextData

typedef struct UI_TextData UI_TextData

Data structure for UI text elements.

This structure holds all necessary data for rendering and managing text UI elements, including the text content, texture, font and alignment properties.

Enumeration Type Documentation

◆ UI_TextAlignment

An enum for text alignment.

Enumerator
UI_TEXT_ALIGN_LEFT 
UI_TEXT_ALIGN_CENTER 
UI_TEXT_ALIGN_RIGHT 

Function Documentation

◆ UI_ChangeText()

void UI_ChangeText ( UIElement *  element,
const char *  text 
)

◆ UI_ChangeTextColor()

void UI_ChangeTextColor ( UIElement *  element,
SDL_Color  color 
)

◆ UI_CreateText()

UIElement * UI_CreateText ( const char *  text,
SDL_Rect  rect,
SDL_Color  color,
float  scale,
UI_TextAlignment  alignment,
TTF_Font *  font 
)

◆ UI_CreateTextTexture()

SDL_Texture * UI_CreateTextTexture ( const char *  text,
SDL_Color  color,
TTF_Font *  font 
)

◆ UI_DestroyText()

void UI_DestroyText ( UIElement *  element)

◆ UI_IsHovered()

bool UI_IsHovered ( UIElement *  element)

◆ UI_RenderText()

void UI_RenderText ( UIElement *  element)

◆ UI_SetHovered()

void UI_SetHovered ( UIElement *  element,
bool  hovered 
)

◆ UI_UpdateText()

void UI_UpdateText ( UIElement *  element)