Remove rune tracking for string cache, + vecache changes

Getting ready to de-hardcode vefontcache shaders
This commit is contained in:
2025-01-06 14:12:55 -05:00
parent f1f98ffafb
commit 0350a0c282
26 changed files with 284 additions and 174 deletions

View File

@ -237,7 +237,7 @@ ui_graph_build_begin :: proc( ui : ^ UI_State, bounds : Vec2 = {} )
}
ui.built_box_count = 0
root = ui_box_make( {}, str_intern(str_fmt("%s: root#001", ui == & state.screen_ui ? "Screen" : "Workspace" )).str)
root = ui_box_make( {}, str_intern(str_fmt("%s: root#001", ui == & state.screen_ui ? "Screen" : "Workspace" )))
if ui == & state.screen_ui {
root.layout.size = range2(Vec2(state.app_window.extent) * 2, {})
}
@ -283,7 +283,8 @@ ui_graph_build_end :: proc( ui : ^UI_State )
if ! current.computed.fresh
{
if len(current.text.str) > 0 {
if len(current.text) > 0 {
profile("text shape")
// app_window := get_state().app_window
// screen_extent := app_window.extent
// screen_size := screen_extent * 2
@ -293,7 +294,7 @@ ui_graph_build_end :: proc( ui : ^UI_State )
// over_sample : f32 = f32(get_state().config.font_size_canvas_scalar)
current.computed.text_shape = shape_text_cached( current.text.str, current.style.font, current.layout.font_size, 1.0 )
current.computed.text_shape = shape_text_cached( current.text, current.style.font, current.layout.font_size, 1.0 )
}
ui_box_compute_layout( current )
}
@ -302,6 +303,8 @@ ui_graph_build_end :: proc( ui : ^UI_State )
continue
}
profile("render queue resolution")
different_ancestory := b8(current.ancestors != previous_layer)
entry_box := UI_RenderBoxInfo {
@ -318,7 +321,7 @@ ui_graph_build_end :: proc( ui : ^UI_State )
// if len(current.text.str) > 0
// {
entry_text := UI_RenderTextInfo {
text = current.text.str,
text = current.text,
shape = current.computed.text_shape,
position = current.computed.text_pos,
color = current.style.text_color,

View File

@ -22,8 +22,8 @@ UI_NavLinks :: struct {
UI_Box :: struct {
// Cache ID
key : UI_Key,
label : StrRunesPair,
text : StrRunesPair,
label : StrCached,
text : StrCached,
// Regenerated per frame.
nav : UI_NavLinks,
@ -67,7 +67,7 @@ ui_box_from_key :: #force_inline proc ( cache : ^HMapChained(UI_Box), key : UI_K
ui_box_make :: proc( flags : UI_BoxFlags, label : string ) -> (^ UI_Box)
{
// profile(#procedure)
profile(#procedure)
using ui := get_state().ui_context
key := ui_key_from_string( label )

View File

@ -194,21 +194,21 @@ ui_layout_pop :: #force_inline proc() { pop( &
ui_set_layout :: #force_inline proc( layout : UI_Layout, preset : UI_StylePreset ) { stack_peek_ref( & get_state().ui_context.layout_combo_stack).array[preset] = layout }
ui_size_to_content_xy :: proc ( box : ^UI_Box) {
ui_size_to_content_xy :: #force_inline proc ( box : ^UI_Box) {
using box
children_bounds := ui_compute_children_overall_bounds(box)
layout.size.min = size_range2(children_bounds)
layout.flags |= { .Fixed_Width, .Fixed_Height }
}
ui_size_to_content_x :: proc ( box : ^UI_Box) {
ui_size_to_content_x :: #force_inline proc ( box : ^UI_Box) {
using box
children_bounds := ui_compute_children_overall_bounds(box)
layout.size.min.x = size_range2(children_bounds).x
layout.flags |= { .Fixed_Width }
}
ui_size_to_content_y :: proc ( box : ^UI_Box) {
ui_size_to_content_y :: #force_inline proc ( box : ^UI_Box) {
using box
children_bounds := ui_compute_children_overall_bounds(box)
layout.size.min.y = size_range2(children_bounds).y

View File

@ -71,7 +71,7 @@ ui_box_compute_layout :: proc( box : ^UI_Box,
adjusted_size.y = max( adjusted_max_size_y, layout.size.min.y)
text_size : Vec2
if len(box.text.str) > 0
if len(box.text) > 0
{
text_size = computed.text_shape.size
// if layout.font_size == computed.text_size.y {
@ -187,7 +187,7 @@ ui_box_compute_layout :: proc( box : ^UI_Box,
computed.content = content_bounds
// 8. Text position & size
if len(box.text.str) > 0
if len(box.text) > 0
{
ascent, descent, line_gap := get_font_vertical_metrics(style.font, layout.font_size)

View File

@ -30,7 +30,7 @@ UI_Signal :: struct {
ui_signal_from_box :: proc ( box : ^ UI_Box, update_style := true, update_deltas := true ) -> UI_Signal
{
// profile(#procedure)
profile(#procedure)
ui := get_state().ui_context
input := get_state().input

View File

@ -22,7 +22,7 @@ ui_floating_startup :: proc( self : ^UI_FloatingManager, build_queue_cap, tracke
error : AllocatorError
queue_dbg_name := str_intern(str_fmt("%s: build_queue", dbg_name))
self.build_queue, error = make( Array(UI_Floating), build_queue_cap, dbg_name = queue_dbg_name.str, allocator = allocator )
self.build_queue, error = make( Array(UI_Floating), build_queue_cap, dbg_name = queue_dbg_name, allocator = allocator )
if error != AllocatorError.None
{
ensure(false, "Failed to allocate the build_queue")

View File

@ -61,8 +61,8 @@ test_draggable :: proc()
draggable.layout.pos = debug.draggable_box_pos
draggable.layout.size.min = debug.draggable_box_size
draggable.text = { str_fmt("%v", debug.draggable_box_pos), {} }
draggable.text.runes = to_runes(draggable.text.str)
draggable.text = str_intern_fmt("%v", debug.draggable_box_pos)
// draggable.text.runes = to_runes(draggable.text)
}
test_parenting :: proc( default_layout : ^UI_Layout, frame_style_default : ^UI_Style )
@ -195,6 +195,9 @@ test_whitespace_ast :: proc( default_layout : ^UI_Layout, frame_style_default :
label_id := 0
builder : StringBuilder
str.builder_init_len_cap( & builder, len = 0, cap = 16 * Kilobyte )
line_id := 0
for line in array_to_slice( debug.lorem_parse.lines )
{
@ -205,11 +208,17 @@ test_whitespace_ast :: proc( default_layout : ^UI_Layout, frame_style_default :
profile("line")
ui_layout( text_layout )
line_hbox := ui_widget(str_fmt( "line %v", line_id ), {.Mouse_Clickable})
if line_hbox.key == ui.hot && false
profile_begin("label fmt")
str.builder_reset( & builder)
label := str_fmt_builder( & builder, "line %d", line_id )
profile_end()
line_hbox := ui_widget(label, {.Mouse_Clickable})
if false && line_hbox.key == ui.hot
{
line_hbox.text = StrRunesPair {}
line_hbox.text = StrCached {}
ui_parent(line_hbox)
chunk_layout := text_layout
@ -230,33 +239,34 @@ test_whitespace_ast :: proc( default_layout : ^UI_Layout, frame_style_default :
#partial switch head.type
{
case .Visible:
label := str_intern( str_fmt( "%v %v", head.content.str, label_id ))
widget = ui_text( label.str, head.content )
label := str_fmt( "%v %v", head.content, label_id )
widget = ui_text( label, head.content )
label_id += 1
chunk_layout.pos.x += size_range2( widget.computed.bounds ).x
case .Spaces:
label := str_intern( str_fmt( "%v %v", "space", label_id ))
widget = ui_text_spaces( label.str )
label := str_fmt( "%v %v", "space", label_id )
widget = ui_text_spaces( label )
label_id += 1
for idx in 1 ..< len( head.content.runes )
{
// for idx in 1 ..< len( head.content.runes )
// {
// TODO(Ed): VIRTUAL WHITESPACE
// widget.style.layout.size.x += range2_size( widget.computed.bounds )
}
// }
chunk_layout.pos.x += size_range2( widget.computed.bounds ).x
case .Tabs:
label := str_intern( str_fmt( "%v %v", "tab", label_id ))
widget = ui_text_tabs( label.str )
label := str_fmt( "%v %v", "tab", label_id )
widget = ui_text_tabs( label )
label_id += 1
for idx in 1 ..< len( head.content.runes )
{
// for idx in 1 ..< len( head.content.runes )
// {
// TODO(Ed): VIRTUAL WHITESPACE
// widget.style.layout.size.x += range2_size( widget.computed.bounds )
}
// }
chunk_layout.pos.x += size_range2( widget.computed.bounds ).x
}
@ -268,30 +278,31 @@ test_whitespace_ast :: proc( default_layout : ^UI_Layout, frame_style_default :
}
else
{
builder_backing : [16 * Kilobyte] byte
builder := str.builder_from_bytes( builder_backing[:] )
profile("line (single-box)")
line_hbox.layout.flags |= { .Size_To_Text }
str.builder_reset( & builder)
head := line.first.next
for ; head != nil;
{
str.write_string( & builder, head.content.str )
profile("write ast node")
str.write_string( & builder, head.content )
head = head.next
}
profile("intern")
line_hbox.text = str_intern( to_string( builder ) )
// if len(line_hbox.text.str) == 0 {
// line_hbox.text = str_intern( " " )
// }
}
if len(line_hbox.text.str) > 0 {
if len(line_hbox.text) > 0 {
profile("append actual")
array_append( widgets_ptr, line_hbox )
text_layout.pos.x = text_layout.pos.x
text_layout.pos.y -= size_range2(line_hbox.computed.bounds).y
}
else {
profile("end")
widget := & widgets.data[ widgets.num - 1 ]
if widget.box != nil {
text_layout.pos.y -= size_range2( widget.computed.bounds ).y

View File

@ -11,14 +11,14 @@ UI_Widget :: struct {
using signal : UI_Signal,
}
ui_widget :: proc( label : string, flags : UI_BoxFlags ) -> (widget : UI_Widget)
ui_widget :: #force_inline proc( label : string, flags : UI_BoxFlags ) -> (widget : UI_Widget)
{
widget.box = ui_box_make( flags, label )
widget.signal = ui_signal_from_box( widget.box )
return
}
ui_button :: proc( label : string, flags : UI_BoxFlags = {} ) -> (btn : UI_Widget)
ui_button :: #force_inline proc( label : string, flags : UI_BoxFlags = {} ) -> (btn : UI_Widget)
{
btn_flags := UI_BoxFlags { .Mouse_Clickable }
btn.box = ui_box_make( btn_flags | flags, label )
@ -36,7 +36,7 @@ UI_DropDown :: struct {
}
@(deferred_out = ui_drop_down_end_auto)
ui_drop_down :: proc( drop_down : ^UI_DropDown, label : string, title_text : StrRunesPair,
ui_drop_down :: proc( drop_down : ^UI_DropDown, label : string, title_text : StrCached,
direction := UI_LayoutDirection_Y.Top_To_Bottom,
btn_flags := UI_BoxFlags{},
vb_flags := UI_BoxFlags{},
@ -54,7 +54,7 @@ ui_drop_down :: proc( drop_down : ^UI_DropDown, label : string, title_text : Str
}
// Its assumed that the drop down has a vertical box parent already pushed
ui_drop_down_begin :: proc( drop_down : ^UI_DropDown, label : string, title_text : StrRunesPair,
ui_drop_down_begin :: proc( drop_down : ^UI_DropDown, label : string, title_text : StrCached,
direction := UI_LayoutDirection_Y.Top_To_Bottom,
btn_flags := UI_BoxFlags{},
vb_flags := UI_BoxFlags{},
@ -68,7 +68,7 @@ ui_drop_down_begin :: proc( drop_down : ^UI_DropDown, label : string, title_text
if btn_theme == nil do push(theme_drop_down_btn)
else do push(btn_theme ^)
defer ui_theme_pop()
btn = ui_button( str_intern_fmt("%s.btn", label).str );
btn = ui_button( str_fmt("%s.btn", label) );
{
btn.layout.padding.left = 4
ui_parent(btn)
@ -76,7 +76,7 @@ ui_drop_down_begin :: proc( drop_down : ^UI_DropDown, label : string, title_text
if title_theme == nil do push(theme_text)
else do push(title_theme ^)
defer ui_theme_pop()
title = ui_text( str_intern_fmt("%s.btn.title", label).str, title_text)
title = ui_text( str_fmt("%s.btn.title", label), title_text)
}
if btn.pressed {
@ -91,7 +91,7 @@ ui_drop_down_begin :: proc( drop_down : ^UI_DropDown, label : string, title_text
if vb_parent != nil {
ui_parent_push(vb_parent)
}
vbox = ui_vbox_begin( direction, str_intern_fmt("%v.vbox", label).str, flags = {.Mouse_Clickable}, compute_layout = vb_compute_layout )
vbox = ui_vbox_begin( direction, str_fmt("%v.vbox", label), flags = {.Mouse_Clickable}, compute_layout = vb_compute_layout )
vbox.layout.anchor.ratio.y = 1.0
if vb_parent != nil {
@ -328,7 +328,7 @@ ui_resizable_handles :: #force_no_inline proc( parent : ^UI_Widget, pos : ^Vec2,
name :: proc( label : string ) -> string {
parent_label := (transmute(^string) context.user_ptr) ^
return str_intern(str_fmt("%v.%v", parent_label, label )).str
return str_fmt("%v.%v", parent_label, label )
}
context.user_ptr = & parent.label
@ -523,9 +523,9 @@ ui_scroll_box :: proc( label : string, flags : UI_BoxFlags ) -> (scroll_box : UI
}
#region("Text")
ui_text :: proc( label : string, content : StrRunesPair, flags : UI_BoxFlags = {} ) -> UI_Widget
ui_text :: #force_inline proc( label : string, content : StrCached, flags : UI_BoxFlags = {} ) -> UI_Widget
{
// profile(#procedure)
profile(#procedure)
state := get_state(); using state
box := ui_box_make( flags, label )
@ -535,9 +535,9 @@ ui_text :: proc( label : string, content : StrRunesPair, flags : UI_BoxFlags = {
return { box, signal }
}
ui_text_spaces :: proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget
ui_text_spaces :: #force_inline proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget
{
// profile(#procedure)
profile(#procedure)
state := get_state(); using state
// TODO(Ed) : Move this somwhere in state.
@ -550,9 +550,9 @@ ui_text_spaces :: proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget
return { box, signal }
}
ui_text_tabs :: proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget
ui_text_tabs :: #force_inline proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget
{
// profile(#procedure)
profile(#procedure)
state := get_state(); using state
// TODO(Ed) : Move this somwhere in state.
@ -595,8 +595,8 @@ ui_text_input_box_reload :: #force_inline proc ( text_box : ^UI_TextInputBox, al
ui_text_input_box :: proc( text_input_box : ^UI_TextInputBox, label : string,
flags : UI_BoxFlags = {.Mouse_Clickable, .Focusable, .Click_To_Focus},
allocator := context.allocator,
policy : UI_TextInput_Policy = {}
policy : UI_TextInput_Policy = {},
allocator : Allocator,
)
{
// state := get_state()
@ -619,6 +619,7 @@ ui_text_input_box :: proc( text_input_box : ^UI_TextInputBox, label : string,
input_str, error = make( Array(rune), Kilo, allocator )
ensure(error == AllocatorError.None, "Failed to allocate array for input_str of input_box")
}
input_str.backing = allocator // Always assign allocator for hot-reload purposes
if active
{
@ -706,19 +707,19 @@ ui_text_input_box :: proc( text_input_box : ^UI_TextInputBox, label : string,
ui_parent(text_input_box)
name :: proc( label : string ) -> string {
parent_label := (transmute(^string) context.user_ptr) ^
return str_intern(str_fmt("%v: %v", parent_label, label )).str
return str_intern(str_fmt("%v: %v", parent_label, label ))
}
context.user_ptr = & parent.label
// TODO(Ed): Allow for left and center alignment of text
value_txt : UI_Widget; {
scope(theme_text)
value_txt = ui_text(name("input_str"), to_str_runes_pair(array_to_slice(input_str)))
value_txt = ui_text(name("input_str"), str_intern(to_string(array_to_slice(input_str))))
using value_txt
layout.alignment = {0.0, 0.0}
layout.text_alignment = {1.0, 0.5}
layout.anchor.left = 0.0
layout.size.min = cast(Vec2) measure_text_size( text.str, style.font, layout.font_size, 0 )
layout.size.min = cast(Vec2) measure_text_size( text, style.font, layout.font_size, 0 )
if active {
ui_parent(value_txt)

View File

@ -27,7 +27,7 @@ UI_Window_ChildLayout :: enum(i32) {
@(deferred_in=ui_window_end_auto)
ui_window :: proc (window : ^UI_Window, label : string,
title : StrRunesPair = {},
title : StrCached = {},
closable := true,
maximizable := true,
draggable := true,
@ -41,7 +41,7 @@ ui_window :: proc (window : ^UI_Window, label : string,
}
ui_window_begin :: proc( window : ^UI_Window, label : string,
title : StrRunesPair = {},
title : StrCached = {},
closable := true,
maximizable := true,
draggable := true,
@ -83,7 +83,7 @@ ui_window_begin :: proc( window : ^UI_Window, label : string,
scope(theme_transparent)
vb = ui_vbox(.Top_To_Bottom, str_fmt_tmp("%s.vb", label))
if len(title.str) > 0 || closable || maximizable || draggable {
if len(title) > 0 || closable || maximizable || draggable {
dragged, maximized, closed = ui_window_bar(window, title, closable, maximizable, draggable)
}
@ -109,7 +109,7 @@ ui_window_end :: proc (window : ^UI_Window)
}
ui_window_end_auto :: proc( window : ^UI_Window, label : string,
title : StrRunesPair = {},
title : StrCached = {},
closable := true,
maximizable := true,
draggable := true,
@ -121,7 +121,7 @@ ui_window_end_auto :: proc( window : ^UI_Window, label : string,
}
ui_window_bar :: proc( window : ^UI_Window,
title : StrRunesPair = {},
title : StrCached = {},
closable := true,
maximizable := true,
draggable := true,
@ -132,13 +132,13 @@ ui_window_bar :: proc( window : ^UI_Window,
draggable_flag : UI_BoxFlags = draggable ? {.Mouse_Clickable} : {}
scope(theme_window_bar)
bar = ui_hbox(.Left_To_Right, str_fmt_tmp("%s.bar", frame.label.str), draggable_flag);
bar = ui_hbox(.Left_To_Right, str_fmt_tmp("%s.bar", frame.label), draggable_flag);
ui_parent(bar)
if len(title.str) > 0
if len(title) > 0
{
scope(theme_text)
tile_text = ui_text( str_fmt_tmp("%s.title_text", bar.label.str), title, {.Disabled}); {
tile_text = ui_text( str_fmt_tmp("%s.title_text", bar.label), title, {.Disabled}); {
using tile_text
layout.anchor.ratio.x = 1.0
layout.margins = { 0, 0, 15, 0}
@ -149,7 +149,7 @@ ui_window_bar :: proc( window : ^UI_Window,
scope(theme_window_bar_btn)
if maximizable
{
maximize_btn = ui_button( str_fmt_tmp("%v.maximize_btn", bar.label.str) ); {
maximize_btn = ui_button( str_fmt_tmp("%v.maximize_btn", bar.label) ); {
using maximize_btn
if maximize_btn.pressed {
is_maximized = ~is_maximized