mirror of
https://github.com/nicbarker/clay.git
synced 2026-02-06 12:48:49 +00:00
SetMesureText and SetQueryScrollOffset takes userData (#212)
This commit is contained in:
parent
8e7e30dda6
commit
e8025cc254
12 changed files with 44 additions and 31 deletions
|
|
@ -12,11 +12,12 @@ typedef struct
|
|||
TTF_Font *font;
|
||||
} SDL2_Font;
|
||||
|
||||
static SDL2_Font SDL2_fonts[1];
|
||||
|
||||
static Clay_Dimensions SDL2_MeasureText(Clay_String *text, Clay_TextElementConfig *config)
|
||||
static Clay_Dimensions SDL2_MeasureText(Clay_String *text, Clay_TextElementConfig *config, uintptr_t userData)
|
||||
{
|
||||
TTF_Font *font = SDL2_fonts[config->fontId].font;
|
||||
SDL2_Font *fonts = (SDL2_Font*)userData;
|
||||
|
||||
TTF_Font *font = fonts[config->fontId].font;
|
||||
char *chars = (char *)calloc(text->length + 1, 1);
|
||||
memcpy(chars, text->chars, text->length);
|
||||
int width = 0;
|
||||
|
|
@ -34,7 +35,7 @@ static Clay_Dimensions SDL2_MeasureText(Clay_String *text, Clay_TextElementConfi
|
|||
|
||||
SDL_Rect currentClippingRectangle;
|
||||
|
||||
static void Clay_SDL2_Render(SDL_Renderer *renderer, Clay_RenderCommandArray renderCommands)
|
||||
static void Clay_SDL2_Render(SDL_Renderer *renderer, Clay_RenderCommandArray renderCommands, SDL2_Font *fonts)
|
||||
{
|
||||
for (uint32_t i = 0; i < renderCommands.length; i++)
|
||||
{
|
||||
|
|
@ -60,7 +61,7 @@ static void Clay_SDL2_Render(SDL_Renderer *renderer, Clay_RenderCommandArray ren
|
|||
Clay_String text = renderCommand->text;
|
||||
char *cloned = (char *)calloc(text.length + 1, 1);
|
||||
memcpy(cloned, text.chars, text.length);
|
||||
TTF_Font* font = SDL2_fonts[config->fontId].font;
|
||||
TTF_Font* font = fonts[config->fontId].font;
|
||||
SDL_Surface *surface = TTF_RenderUTF8_Blended(font, cloned, (SDL_Color) {
|
||||
.r = (Uint8)config->textColor.r,
|
||||
.g = (Uint8)config->textColor.g,
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ static inline char *Clay_Cairo__NullTerminate(Clay_String *str) {
|
|||
}
|
||||
|
||||
// Measure text using cairo's *toy* text API.
|
||||
static inline Clay_Dimensions Clay_Cairo_MeasureText(Clay_String *str, Clay_TextElementConfig *config) {
|
||||
static inline Clay_Dimensions Clay_Cairo_MeasureText(Clay_String *str, Clay_TextElementConfig *config, uintptr_t userData) {
|
||||
// Edge case: Clay computes the width of a whitespace character
|
||||
// once. Cairo does not factor in whitespaces when computing text
|
||||
// extents, this edge-case serves as a short-circuit to introduce
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int scre
|
|||
|
||||
uint32_t measureCalls = 0;
|
||||
|
||||
static inline Clay_Dimensions Raylib_MeasureText(Clay_String *text, Clay_TextElementConfig *config) {
|
||||
static inline Clay_Dimensions Raylib_MeasureText(Clay_String *text, Clay_TextElementConfig *config, uintptr_t userData) {
|
||||
measureCalls++;
|
||||
// Measure string size for Font
|
||||
Clay_Dimensions textSize = { 0 };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue