Added basic string interning

This commit is contained in:
2024-03-08 23:20:49 -05:00
parent c395cbaeb6
commit f1edf1c43e
13 changed files with 144 additions and 25 deletions

View File

@ -33,7 +33,7 @@ debug_draw_text :: proc( content : string, pos : Vec2, size : f32, color : rl.Co
tint = color );
}
debug_draw_text_world :: proc( content : string, pos : Vec2, size : f32, color : rl.Color = rl.WHITE, font : FontID = Font_Default )
draw_text_string :: proc( content : string, pos : Vec2, size : f32, color : rl.Color = rl.WHITE, font : FontID = Font_Default )
{
state := get_state(); using state
@ -62,6 +62,33 @@ debug_draw_text_world :: proc( content : string, pos : Vec2, size : f32, color :
tint = color );
}
draw_text_string_cached :: proc( content : StringCached, pos : Vec2, size : f32, color : rl.Color = rl.WHITE, font : FontID = Font_Default ) {
state := get_state(); using state
if len( content.str ) == 0 {
return
}
font := font
if font.key == Font_Default.key {
// if len(font) == 0 {
font = default_font
}
pos := world_to_screen_pos(pos)
px_size := size
zoom_adjust := px_size * project.workspace.cam.zoom
runes := content.runes
rl_font := to_rl_Font(font, zoom_adjust )
rl.DrawTextCodepoints( rl_font,
raw_data(runes), cast(i32) len(runes),
position = transmute(rl.Vector2) pos,
fontSize = px_size,
spacing = 0.0,
tint = color );
}
// Raylib's equivalent doesn't take a length for the string (making it a pain in the ass)
// So this is a 1:1 copy except it takes Odin strings
measure_text_size :: proc( text : string, font : FontID, font_size := Font_Use_Default_Size, spacing : f32 ) -> AreaSize