mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-17 15:58:05 +00:00
Compare commits
4 Commits
86c6efc175
...
f8c3121421
Author | SHA1 | Date | |
---|---|---|---|
|
f8c3121421 | ||
|
22e8cc318c | ||
|
8e6640f7a2 | ||
|
d7e072fe25 |
@ -102,6 +102,7 @@ TextAlignment :: enum EnumBackingType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextElementConfig :: struct {
|
TextElementConfig :: struct {
|
||||||
|
userData: rawptr,
|
||||||
textColor: Color,
|
textColor: Color,
|
||||||
fontId: u16,
|
fontId: u16,
|
||||||
fontSize: u16,
|
fontSize: u16,
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -489,7 +489,7 @@ errorHandler :: proc "c" (errorData: clay.ErrorData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
minMemorySize: u32 = clay.MinMemorySize()
|
minMemorySize: c.size_t = cast(c.size_t)clay.MinMemorySize()
|
||||||
memory := make([^]u8, minMemorySize)
|
memory := make([^]u8, minMemorySize)
|
||||||
arena: clay.Arena = clay.CreateArenaWithCapacityAndMemory(minMemorySize, memory)
|
arena: clay.Arena = clay.CreateArenaWithCapacityAndMemory(minMemorySize, memory)
|
||||||
clay.Initialize(arena, {cast(f32)raylib.GetScreenWidth(), cast(f32)raylib.GetScreenHeight()}, { handler = errorHandler })
|
clay.Initialize(arena, {cast(f32)raylib.GetScreenWidth(), cast(f32)raylib.GetScreenHeight()}, { handler = errorHandler })
|
||||||
|
4
clay.h
4
clay.h
@ -357,6 +357,8 @@ typedef CLAY_PACKED_ENUM {
|
|||||||
|
|
||||||
// Controls various functionality related to text elements.
|
// Controls various functionality related to text elements.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// A pointer that will be transparently passed through to the resulting render command.
|
||||||
|
void *userData;
|
||||||
// The RGBA color of the font to render, conventionally specified as 0-255.
|
// The RGBA color of the font to render, conventionally specified as 0-255.
|
||||||
Clay_Color textColor;
|
Clay_Color textColor;
|
||||||
// An integer transparently passed to Clay_MeasureText to identify the font to use.
|
// An integer transparently passed to Clay_MeasureText to identify the font to use.
|
||||||
@ -2692,7 +2694,7 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
.letterSpacing = textElementConfig->letterSpacing,
|
.letterSpacing = textElementConfig->letterSpacing,
|
||||||
.lineHeight = textElementConfig->lineHeight,
|
.lineHeight = textElementConfig->lineHeight,
|
||||||
}},
|
}},
|
||||||
.userData = sharedConfig->userData,
|
.userData = textElementConfig->userData,
|
||||||
.id = Clay__HashNumber(lineIndex, currentElement->id).id,
|
.id = Clay__HashNumber(lineIndex, currentElement->id).id,
|
||||||
.zIndex = root->zIndex,
|
.zIndex = root->zIndex,
|
||||||
.commandType = CLAY_RENDER_COMMAND_TYPE_TEXT,
|
.commandType = CLAY_RENDER_COMMAND_TYPE_TEXT,
|
||||||
|
@ -119,6 +119,7 @@
|
|||||||
{name: 'bottomRight', type: 'float'},
|
{name: 'bottomRight', type: 'float'},
|
||||||
]};
|
]};
|
||||||
let textConfigDefinition = { name: 'text', type: 'struct', members: [
|
let textConfigDefinition = { name: 'text', type: 'struct', members: [
|
||||||
|
{ name: 'userData', type: 'uint32_t' },
|
||||||
{ name: 'textColor', ...colorDefinition },
|
{ name: 'textColor', ...colorDefinition },
|
||||||
{ name: 'fontId', type: 'uint16_t' },
|
{ name: 'fontId', type: 'uint16_t' },
|
||||||
{ name: 'fontSize', type: 'uint16_t' },
|
{ name: 'fontSize', type: 'uint16_t' },
|
||||||
|
Binary file not shown.
@ -119,6 +119,7 @@
|
|||||||
{name: 'bottomRight', type: 'float'},
|
{name: 'bottomRight', type: 'float'},
|
||||||
]};
|
]};
|
||||||
let textConfigDefinition = { name: 'text', type: 'struct', members: [
|
let textConfigDefinition = { name: 'text', type: 'struct', members: [
|
||||||
|
{ name: 'userData', type: 'uint32_t' },
|
||||||
{ name: 'textColor', ...colorDefinition },
|
{ name: 'textColor', ...colorDefinition },
|
||||||
{ name: 'fontId', type: 'uint16_t' },
|
{ name: 'fontId', type: 'uint16_t' },
|
||||||
{ name: 'fontSize', type: 'uint16_t' },
|
{ name: 'fontSize', type: 'uint16_t' },
|
||||||
|
@ -99,16 +99,22 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex
|
|||||||
|
|
||||||
float scaleFactor = config->fontSize/(float)fontToUse.baseSize;
|
float scaleFactor = config->fontSize/(float)fontToUse.baseSize;
|
||||||
|
|
||||||
for (int i = 0; i < text.length; ++i)
|
int byte_index = 0;
|
||||||
{
|
while (byte_index < text.length) {
|
||||||
if (text.chars[i] == '\n') {
|
if (text.chars[byte_index] == '\n') {
|
||||||
maxTextWidth = fmax(maxTextWidth, lineTextWidth);
|
maxTextWidth = fmax(maxTextWidth, lineTextWidth);
|
||||||
lineTextWidth = 0;
|
lineTextWidth = 0;
|
||||||
|
byte_index++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int index = text.chars[i] - 32;
|
|
||||||
if (fontToUse.glyphs[index].advanceX != 0) lineTextWidth += fontToUse.glyphs[index].advanceX;
|
int codepoint_bytes = 0;
|
||||||
else lineTextWidth += (fontToUse.recs[index].width + fontToUse.glyphs[index].offsetX);
|
int codepoint = GetCodepoint(&text.chars[byte_index], &codepoint_bytes);
|
||||||
|
int glyph_index = GetGlyphIndex(fontToUse, codepoint);
|
||||||
|
byte_index += codepoint_bytes;
|
||||||
|
|
||||||
|
if (fontToUse.glyphs[glyph_index].advanceX != 0) lineTextWidth += fontToUse.glyphs[glyph_index].advanceX;
|
||||||
|
else lineTextWidth += (fontToUse.recs[glyph_index].width + fontToUse.glyphs[glyph_index].offsetX);
|
||||||
}
|
}
|
||||||
|
|
||||||
maxTextWidth = fmax(maxTextWidth, lineTextWidth);
|
maxTextWidth = fmax(maxTextWidth, lineTextWidth);
|
||||||
|
Loading…
Reference in New Issue
Block a user