Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
ui.h
Go to the documentation of this file.
1
9#ifndef UI_H
10#define UI_H
11
13#define ASCII_CHAR_COUNT 96
14
15#include "gl_common.h"
16#include <cglm/cglm.h>
17#include <stdbool.h>
18
19typedef struct Shader Shader;
20
25typedef struct {
26 float x0, y0, x1, y1;
27 float w, h;
28 float x_off, y_off;
29 float advance;
30} GlyphInfo;
31
33#define UI_MAX_BATCH_VERTICES 8192
34
39typedef struct {
40 float x, y;
41 float u, v;
42 float r, g, b, a;
43 float mode; // 0=solid, 1=text, 2=rounded
44 float rect_size_x, rect_size_y;
45 float radius;
46} UIVertex;
47
67
72typedef struct {
74 float start_x;
75 float cursor_y;
76 float padding;
79} UILayout;
80
88int ui_init(UIContext* ui_context, const char* font_path, float font_size);
89
94void ui_destroy(UIContext* ui_context);
95
96/* --- Batch API --- */
97
104void ui_begin(UIContext* ui_context, int screen_width, int screen_height);
105
110void ui_flush(UIContext* ui_context);
111
116void ui_end(UIContext* ui_context);
117
118/* --- Layout API --- */
119
123void ui_layout_init(UILayout* layout, UIContext* ui_ctx, float pos_x,
124 float pos_y, float padding, int screen_width,
125 int screen_height);
126
128void ui_layout_text(UILayout* layout, const char* text, const vec3 color);
129
131void ui_layout_separator(UILayout* layout, float space);
132
133/* --- Low-level API --- */
134
136void ui_draw_text(UIContext* ui_context, const char* text, float pos_x,
137 float pos_y, const vec3 color, int screen_width,
138 int screen_height);
139
146float ui_measure_text(const UIContext* ui_context, const char* text);
147
149void ui_draw_text_ex(UIContext* ui_context, const char* text, float pos_x,
150 float pos_y, const vec3 color, float alpha,
151 int screen_width, int screen_height);
152
154void ui_draw_text_scaled(UIContext* ui_context, const char* text, float pos_x,
155 float pos_y, const vec3 color, float alpha,
156 float scale, int screen_width, int screen_height);
157
159void ui_draw_rect(UIContext* ui_context, float rect_x, float rect_y,
160 float width, float height, const vec3 color, int screen_width,
161 int screen_height);
162
164void ui_draw_rect_ex(UIContext* ui_context, float rect_x, float rect_y,
165 float width, float height, const vec3 color, float alpha,
166 int screen_width, int screen_height);
167
169void ui_draw_spinner(UIContext* ui_context, float center_x, float center_y,
170 float size, float angle, const vec3 color,
171 int screen_width, int screen_height);
172
174void ui_draw_rounded_rect(UIContext* ui_context, float rect_x, float rect_y,
175 float width, float height, float radius,
176 const vec3 color, float alpha, int screen_width,
177 int screen_height);
178
180void ui_draw_glow_rect(UIContext* ui_context, float rect_x, float rect_y,
181 float width, float height, float radius,
182 const vec3 color, float alpha, int screen_width,
183 int screen_height);
184
196void ui_draw_textured_quad(UIContext* ui_context, GLuint texture, float rect_x,
197 float rect_y, float width, float height,
198 const vec3 tint, float alpha, int screen_width,
199 int screen_height);
200
214void ui_draw_bloom_quad(UIContext* ui_context, GLuint texture, float rect_x,
215 float rect_y, float width, float height,
216 const vec3 tint, float intensity, int screen_width,
217 int screen_height);
218
219#endif /* UI_H */
layout(location=0) in vec3 RayDir
Common OpenGL definitions, RAII helpers, and utilities.
Metrics and texture coordinates for a single font character.
Definition ui.h:25
float h
Definition ui.h:27
float advance
Definition ui.h:29
float x_off
Definition ui.h:28
float x0
Definition ui.h:26
Wrapper for an OpenGL program with uniform caching and automatic cleanup.
Definition shader.h:71
Persistent state for the UI system.
Definition ui.h:52
bool batch_active
Definition ui.h:64
GLuint vao
Definition ui.h:57
GLuint current_texture
Definition ui.h:65
Shader * spinner_shader
Definition ui.h:56
int current_screen_width
Definition ui.h:62
Shader * shader
Definition ui.h:54
GLuint texture
Definition ui.h:53
int current_screen_height
Definition ui.h:63
float font_size
Definition ui.h:59
int batch_count
Definition ui.h:61
Helper for automatic vertical stacking of UI elements.
Definition ui.h:72
float cursor_y
Definition ui.h:75
int screen_height
Definition ui.h:78
float start_x
Definition ui.h:74
float padding
Definition ui.h:76
int screen_width
Definition ui.h:77
UIContext * ui
Definition ui.h:73
Vertex data for the batch renderer.
Definition ui.h:39
float rect_size_x
Definition ui.h:44
float mode
Definition ui.h:43
float u
Definition ui.h:41
float a
Definition ui.h:42
float radius
Definition ui.h:45
float x
Definition ui.h:40
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.
Definition ui.c:552
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.
Definition ui.c:493
float ui_measure_text(const UIContext *ui_context, const char *text)
Measures the width of a text string in pixels.
Definition ui.c:403
void ui_begin(UIContext *ui_context, int screen_width, int screen_height)
Begins a new UI batch.
Definition ui.c:327
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.
Definition ui.c:770
void ui_destroy(UIContext *ui_context)
Releases UI resources.
Definition ui.c:522
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.
Definition ui.c:426
void ui_layout_text(UILayout *layout, const char *text, const vec3 color)
Draws text and advances the layout cursor.
Definition ui.c:564
void ui_layout_separator(UILayout *layout, float space)
Adds vertical space to the layout.
Definition ui.c:578
#define UI_MAX_BATCH_VERTICES
Maximum number of vertices per UI batch.
Definition ui.h:33
#define ASCII_CHAR_COUNT
Number of supported glyphs in the font atlas.
Definition ui.h:13
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.
Definition ui.c:395
void ui_flush(UIContext *ui_context)
Flushes the current UI batch to the GPU.
Definition ui.c:350
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).
Definition ui.c:726
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).
Definition ui.c:693
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.
Definition ui.c:434
int ui_init(UIContext *ui_context, const char *font_path, float font_size)
Initializes the UI system.
Definition ui.c:260
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.
Definition ui.c:485
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.
Definition ui.c:586
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.
Definition ui.c:648
void ui_end(UIContext *ui_context)
Ends the current UI batch and restores OpenGL state.
Definition ui.c:384