$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
ui.h File Reference

Minimal immediate-mode User Interface (UI) library. More...

#include "shader.h"
#include <cglm/cglm.h>
Include dependency graph for ui.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GlyphInfo
 Metrics and texture coordinates for a single font character. More...
 
struct  UIVertex
 Vertex data for the batch renderer. More...
 
struct  UIContext
 Persistent state for the UI system. More...
 
struct  UILayout
 Helper for automatic vertical stacking of UI elements. More...
 

Macros

#define ASCII_CHAR_COUNT   96
 Number of supported glyphs in the font atlas. More...
 
#define UI_MAX_BATCH_VERTICES   8192
 Maximum number of vertices per UI batch. More...
 

Functions

int ui_init (UIContext *ui_context, const char *font_path, float font_size)
 Initializes the UI system. More...
 
void ui_destroy (UIContext *ui_context)
 Releases UI resources. More...
 
void ui_begin (UIContext *ui_context, int screen_width, int screen_height)
 Begins a new UI batch. More...
 
void ui_flush (UIContext *ui_context)
 Flushes the current UI batch to the GPU. More...
 
void ui_end (UIContext *ui_context)
 Ends the current UI batch and restores OpenGL state. More...
 
void ui_layout_init (UILayout *layout, UIContext *ui_ctx, float pos_x, float pos_y, float padding, int screen_width, int screen_height)
 Initializes a layout helper for a frame. More...
 
void ui_layout_text (UILayout *layout, const char *text, const vec3 color)
 Draws text and advances the layout cursor. More...
 
void ui_layout_separator (UILayout *layout, float space)
 Adds vertical space to the layout. More...
 
void ui_draw_text (UIContext *ui_context, const char *text, float pos_x, float pos_y, const vec3 color, int screen_width, int screen_height)
 Draws a single text string at a specific coordinate. More...
 
float ui_measure_text (const UIContext *ui_context, const char *text)
 Measures the width of a text string in pixels. More...
 
void ui_draw_text_ex (UIContext *ui_context, const char *text, float pos_x, float pos_y, const vec3 color, float alpha, int screen_width, int screen_height)
 Draws text with custom alpha transparency. More...
 
void ui_draw_text_scaled (UIContext *ui_context, const char *text, float pos_x, float pos_y, const vec3 color, float alpha, float scale, int screen_width, int screen_height)
 Draws text with custom alpha transparency and a scale factor. More...
 
void ui_draw_rect (UIContext *ui_context, float rect_x, float rect_y, float width, float height, const vec3 color, int screen_width, int screen_height)
 Draws a solid color rectangle. More...
 
void ui_draw_rect_ex (UIContext *ui_context, float rect_x, float rect_y, float width, float height, const vec3 color, float alpha, int screen_width, int screen_height)
 Draws a solid color rectangle with custom alpha transparency. More...
 
void ui_draw_spinner (UIContext *ui_context, float center_x, float center_y, float size, float angle, const vec3 color, int screen_width, int screen_height)
 Draws a rotating loading spinner. More...
 
void ui_draw_rounded_rect (UIContext *ui_context, float rect_x, float rect_y, float width, float height, float radius, const vec3 color, float alpha, int screen_width, int screen_height)
 Draws a rounded rectangle with custom alpha. More...
 
void ui_draw_glow_rect (UIContext *ui_context, float rect_x, float rect_y, float width, float height, float radius, const vec3 color, float alpha, int screen_width, int screen_height)
 Draws an SDF neon glow border around a rounded rectangle area. More...
 
void ui_draw_textured_quad (UIContext *ui_context, GLuint texture, float rect_x, float rect_y, float width, float height, const vec3 tint, float alpha, int screen_width, int screen_height)
 Draws a textured quad tinted by a color (mode 3). More...
 
void ui_draw_bloom_quad (UIContext *ui_context, GLuint texture, float rect_x, float rect_y, float width, float height, const vec3 tint, float intensity, int screen_width, int screen_height)
 Draws a textured quad with additive blending for bloom effects (mode 4). More...
 

Detailed Description

Minimal immediate-mode User Interface (UI) library.

This module provides basic text rendering and shape drawing for overlays, debug information, and menus. It uses a custom font atlas.

Macro Definition Documentation

◆ ASCII_CHAR_COUNT

#define ASCII_CHAR_COUNT   96

Number of supported glyphs in the font atlas.

◆ UI_MAX_BATCH_VERTICES

#define UI_MAX_BATCH_VERTICES   8192

Maximum number of vertices per UI batch.

Function Documentation

◆ ui_begin()

void ui_begin ( UIContext ui_context,
int  screen_width,
int  screen_height 
)

Begins a new UI batch.

Parameters
ui_contextPointer to the UI context.
screen_widthCurrent window width.
screen_heightCurrent window height.
Here is the call graph for this function:

◆ ui_destroy()

void ui_destroy ( UIContext ui_context)

Releases UI resources.

Parameters
ui_contextPointer to the struct.
Here is the call graph for this function:

◆ ui_draw_bloom_quad()

void ui_draw_bloom_quad ( UIContext ui_context,
GLuint  texture,
float  rect_x,
float  rect_y,
float  width,
float  height,
const vec3  tint,
float  intensity,
int  screen_width,
int  screen_height 
)

Draws a textured quad with additive blending for bloom effects (mode 4).

Uses GL_ONE, GL_ONE blending so dark pixels are invisible and bright pixels add light on top of existing content. The texture should be a radial bloom (bright center, black surround). The tint parameter allows coloring the bloom.

Parameters
textureOpenGL texture handle (bloom PNG, black background).
tintColor of the bloom light (e.g. white or cyan).
intensityBloom brightness (0.0 = invisible, 1.0 = full).
Here is the call graph for this function:

◆ ui_draw_glow_rect()

void ui_draw_glow_rect ( UIContext ui_context,
float  rect_x,
float  rect_y,
float  width,
float  height,
float  radius,
const vec3  color,
float  alpha,
int  screen_width,
int  screen_height 
)

Draws an SDF neon glow border around a rounded rectangle area.

Here is the call graph for this function:

◆ ui_draw_rect()

void ui_draw_rect ( UIContext ui_context,
float  rect_x,
float  rect_y,
float  width,
float  height,
const vec3  color,
int  screen_width,
int  screen_height 
)

Draws a solid color rectangle.

Here is the call graph for this function:

◆ ui_draw_rect_ex()

void ui_draw_rect_ex ( UIContext ui_context,
float  rect_x,
float  rect_y,
float  width,
float  height,
const vec3  color,
float  alpha,
int  screen_width,
int  screen_height 
)

Draws a solid color rectangle with custom alpha transparency.

Here is the call graph for this function:

◆ ui_draw_rounded_rect()

void ui_draw_rounded_rect ( UIContext ui_context,
float  rect_x,
float  rect_y,
float  width,
float  height,
float  radius,
const vec3  color,
float  alpha,
int  screen_width,
int  screen_height 
)

Draws a rounded rectangle with custom alpha.

Here is the call graph for this function:

◆ ui_draw_spinner()

void ui_draw_spinner ( UIContext ui_context,
float  center_x,
float  center_y,
float  size,
float  angle,
const vec3  color,
int  screen_width,
int  screen_height 
)

Draws a rotating loading spinner.

Here is the call graph for this function:

◆ ui_draw_text()

void ui_draw_text ( UIContext ui_context,
const char *  text,
float  pos_x,
float  pos_y,
const vec3  color,
int  screen_width,
int  screen_height 
)

Draws a single text string at a specific coordinate.

Here is the call graph for this function:

◆ ui_draw_text_ex()

void ui_draw_text_ex ( UIContext ui_context,
const char *  text,
float  pos_x,
float  pos_y,
const vec3  color,
float  alpha,
int  screen_width,
int  screen_height 
)

Draws text with custom alpha transparency.

Here is the call graph for this function:

◆ ui_draw_text_scaled()

void ui_draw_text_scaled ( UIContext ui_context,
const char *  text,
float  pos_x,
float  pos_y,
const vec3  color,
float  alpha,
float  scale,
int  screen_width,
int  screen_height 
)

Draws text with custom alpha transparency and a scale factor.

Here is the call graph for this function:

◆ ui_draw_textured_quad()

void ui_draw_textured_quad ( UIContext ui_context,
GLuint  texture,
float  rect_x,
float  rect_y,
float  width,
float  height,
const vec3  tint,
float  alpha,
int  screen_width,
int  screen_height 
)

Draws a textured quad tinted by a color (mode 3).

The PNG texture's RGB is multiplied by the tint color, and its alpha channel is scaled by the alpha parameter. Use for keycaps and panel frame.

Note
Flushes the current batch if the active texture differs.
Parameters
textureOpenGL texture handle (RGBA PNG).
tintTint color multiplied against the texture RGB.
alphaOverall opacity.
Here is the call graph for this function:

◆ ui_end()

void ui_end ( UIContext ui_context)

Ends the current UI batch and restores OpenGL state.

Parameters
ui_contextPointer to the UI context.
Here is the call graph for this function:

◆ ui_flush()

void ui_flush ( UIContext ui_context)

Flushes the current UI batch to the GPU.

Parameters
ui_contextPointer to the UI context.
Here is the call graph for this function:

◆ ui_init()

int ui_init ( UIContext ui_context,
const char *  font_path,
float  font_size 
)

Initializes the UI system.

Parameters
ui_contextPointer to the struct.
font_pathPath to the binary font metrics/texture.
font_sizeDefault scale.
Returns
0 on success, non-zero on error.
Here is the call graph for this function:

◆ ui_layout_init()

void ui_layout_init ( UILayout layout,
UIContext ui_ctx,
float  pos_x,
float  pos_y,
float  padding,
int  screen_width,
int  screen_height 
)

Initializes a layout helper for a frame.

Here is the call graph for this function:

◆ ui_layout_separator()

void ui_layout_separator ( UILayout layout,
float  space 
)

Adds vertical space to the layout.

Here is the call graph for this function:

◆ ui_layout_text()

void ui_layout_text ( UILayout layout,
const char *  text,
const vec3  color 
)

Draws text and advances the layout cursor.

Here is the call graph for this function:

◆ ui_measure_text()

float ui_measure_text ( const UIContext ui_context,
const char *  text 
)

Measures the width of a text string in pixels.

Parameters
ui_contextPointer to the context.
textThe text to measure.
Returns
Width in pixels.