Massive renaming

This commit is contained in:
Zachary Levy
2026-04-19 19:37:27 -07:00
parent 7a21d6f253
commit 0953462b3b
5 changed files with 551 additions and 512 deletions

View File

@@ -69,7 +69,7 @@ register_font :: proc(bytes: []u8) -> (id: Font_Id, ok: bool) #optional_ok {
}
Text :: struct {
ref: ^sdl_ttf.Text,
sdl_text: ^sdl_ttf.Text,
position: [2]f32,
color: Color,
}
@@ -81,8 +81,8 @@ Text :: struct {
// Hash a string to a u32 cache key using the same Jenkins one-at-a-time algorithm as Clay.
// This means Clay element IDs and user-chosen string IDs share the same keyspace — same
// string produces the same cache key regardless of whether it came from Clay or user code.
text_cache_hash :: #force_inline proc(s: string) -> u32 {
return hash.jenkins(transmute([]u8)s) + 1 // +1 reserves 0 as "no entry" (matches Clay convention)
text_cache_hash :: #force_inline proc(text_string: string) -> u32 {
return hash.jenkins(transmute([]u8)text_string) + 1 // +1 reserves 0 as "no entry" (matches Clay convention)
}
// Shared cache lookup/create/update logic used by both the `text` proc and the Clay render path.
@@ -125,8 +125,8 @@ cache_get_or_update :: proc(cache_id: u32, c_str: cstring, font: ^sdl_ttf.Font)
// `rotation` is in degrees, counter-clockwise.
text :: proc(
layer: ^Layer,
str: string,
pos: [2]f32,
text_string: string,
position: [2]f32,
font_id: Font_Id,
font_size: u16 = 44,
color: Color = BLACK,
@@ -135,14 +135,14 @@ text :: proc(
id: Maybe(string) = nil,
temp_allocator := context.temp_allocator,
) {
c_str := strings.clone_to_cstring(str, temp_allocator)
c_str := strings.clone_to_cstring(text_string, temp_allocator)
sdl_text: ^sdl_ttf.Text
cached := false
if id_str, ok := id.?; ok {
if id_string, ok := id.?; ok {
cached = true
sdl_text = cache_get_or_update(text_cache_hash(id_str), c_str, get_font(font_id, font_size))
sdl_text = cache_get_or_update(text_cache_hash(id_string), c_str, get_font(font_id, font_size))
} else {
sdl_text = sdl_ttf.CreateText(GLOB.text_cache.engine, get_font(font_id, font_size), c_str, 0)
if sdl_text == nil {
@@ -151,11 +151,11 @@ text :: proc(
}
if needs_transform(origin, rotation) {
dpi := GLOB.dpi_scaling
xform := build_pivot_rot(pos * dpi, origin * dpi, rotation)
prepare_text_transformed(layer, Text{sdl_text, {0, 0}, color}, xform)
dpi_scale := GLOB.dpi_scaling
transform := build_pivot_rotation(position * dpi_scale, origin * dpi_scale, rotation)
prepare_text_transformed(layer, Text{sdl_text, {0, 0}, color}, transform)
} else {
prepare_text(layer, Text{sdl_text, pos, color})
prepare_text(layer, Text{sdl_text, position, color})
}
if !cached {
@@ -171,64 +171,64 @@ text :: proc(
// Measure a string in logical pixels (pre-DPI-scaling) using the same font backend as the renderer.
measure_text :: proc(
str: string,
text_string: string,
font_id: Font_Id,
font_size: u16 = 44,
allocator := context.temp_allocator,
) -> [2]f32 {
c_str := strings.clone_to_cstring(str, allocator)
w, h: c.int
if !sdl_ttf.GetStringSize(get_font(font_id, font_size), c_str, 0, &w, &h) {
c_str := strings.clone_to_cstring(text_string, allocator)
width, height: c.int
if !sdl_ttf.GetStringSize(get_font(font_id, font_size), c_str, 0, &width, &height) {
log.panicf("Failed to measure text: %s", sdl.GetError())
}
return {f32(w) / GLOB.dpi_scaling, f32(h) / GLOB.dpi_scaling}
return {f32(width) / GLOB.dpi_scaling, f32(height) / GLOB.dpi_scaling}
}
// ---------------------------------------------------------------------------------------------------------------------
// ----- Text anchor helpers -----------
// ---------------------------------------------------------------------------------------------------------------------
center_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
center_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return size * 0.5
}
top_left_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
top_left_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
return {0, 0}
}
top_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
top_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return {size.x * 0.5, 0}
}
top_right_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
top_right_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return {size.x, 0}
}
left_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
left_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return {0, size.y * 0.5}
}
right_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
right_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return {size.x, size.y * 0.5}
}
bottom_left_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
bottom_left_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return {0, size.y}
}
bottom_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
bottom_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return {size.x * 0.5, size.y}
}
bottom_right_of_text :: proc(str: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(str, font_id, font_size)
bottom_right_of_text :: proc(text_string: string, font_id: Font_Id, font_size: u16 = 44) -> [2]f32 {
size := measure_text(text_string, font_id, font_size)
return size
}