WIP (Broken) docs and huge changes

This commit is contained in:
2025-01-07 03:06:12 -05:00
parent a9080fe1f3
commit 3a245a1e9b
20 changed files with 725 additions and 438 deletions

View File

@ -26,6 +26,9 @@ ui_screen_reload :: proc( screen_ui : ^UI_ScreenState ) {
ui_screen_tick :: proc( screen_ui : ^UI_ScreenState ) {
profile("Screenspace Imgui")
font_provider_set_px_scalar( app_config().text_size_screen_scalar )
// screen_ui.zoom_scale = 1.0
ui_graph_build( screen_ui )
ui_floating_manager( & screen_ui.floating )
ui_floating("Menu Bar", & screen_ui.menu_bar, ui_screen_menu_bar_builder)

View File

@ -496,7 +496,7 @@ ui_settings_menu_builder :: proc( captures : rawptr = nil ) -> ( should_raise :
}
}
Font_Size_Screen_Scalar:
Text_Size_Screen_Scalar:
{
ui_settings_entry_inputbox( & font_size_screen_scalar_input, false, "settings_menu.font_size_screen_scalar", str_intern("Font: Size Screen Scalar"),
UI_TextInput_Policy {
@ -515,17 +515,46 @@ ui_settings_menu_builder :: proc( captures : rawptr = nil ) -> ( should_raise :
value, success := parse_f32(to_string(array_to_slice(input_str)))
if success {
value = clamp(value, 0.001, 9999.0)
config.font_size_screen_scalar = value
config.text_size_screen_scalar = value
}
}
else
{
clear( input_str )
append( & input_str, to_runes(str_fmt("%v", config.font_size_screen_scalar)))
append( & input_str, to_runes(str_fmt("%v", config.text_size_screen_scalar)))
}
}
Font_Size_Canvas_Scalar:
Text_Snap_Glyph_Positions:
{
ui_settings_entry_inputbox( & font_size_canvas_scalar_input, false, "settings_menu.font_size_canvas_scalar", str_intern("Font: Size Canvas Scalar"),
UI_TextInput_Policy {
digits_only = true,
disallow_leading_zeros = false,
disallow_decimal = false,
digit_min = 0,
digit_max = 1,
max_length = 1,
}
)
using font_size_canvas_scalar_input
if was_active
{
value, success := parse_f32(to_string(array_to_slice(input_str)))
if success {
value = clamp(value, 0, 1)
config.text_snap_glyph_positions = cast(b32) i32(value)
}
}
else
{
clear( input_str )
append( & input_str, to_runes(str_fmt("%v", config.text_size_canvas_scalar)))
}
}
Text_Size_Canvas_Scalar:
{
ui_settings_entry_inputbox( & font_size_canvas_scalar_input, false, "settings_menu.font_size_canvas_scalar", str_intern("Font: Size Canvas Scalar"),
UI_TextInput_Policy {
@ -544,19 +573,19 @@ ui_settings_menu_builder :: proc( captures : rawptr = nil ) -> ( should_raise :
value, success := parse_f32(to_string(array_to_slice(input_str)))
if success {
value = clamp(value, 0.001, 9999.0)
config.font_size_canvas_scalar = value
config.text_size_canvas_scalar = value
}
}
else
{
clear( input_str )
append( & input_str, to_runes(str_fmt("%v", config.font_size_canvas_scalar)))
append( & input_str, to_runes(str_fmt("%v", config.text_size_canvas_scalar)))
}
}
Text_Alpha_Sharpen:
{
ui_settings_entry_inputbox( & font_size_canvas_scalar_input, false, "settings_menu.font_size_canvas_scalar", str_intern("Font: Size Canvas Scalar"),
ui_settings_entry_inputbox( & font_size_canvas_scalar_input, false, "settings_menu.text_alpha_sharpen", str_intern("Text: Alpha Sharpen"),
UI_TextInput_Policy {
digits_only = true,
disallow_leading_zeros = false,
@ -572,14 +601,14 @@ ui_settings_menu_builder :: proc( captures : rawptr = nil ) -> ( should_raise :
{
value, success := parse_f32(to_string(array_to_slice(input_str)))
if success {
value = clamp(value, 0.001, 9999.0)
config.font_size_canvas_scalar = value
value = clamp(value, 0.001, 10.0)
config.text_alpha_sharpen = value
}
}
else
{
clear( input_str )
append( & input_str, to_runes(str_fmt("%v", config.font_size_canvas_scalar)))
append( & input_str, to_runes(str_fmt("%v", config.text_size_canvas_scalar)))
}
}
}

View File

@ -161,8 +161,10 @@ AppConfig :: struct {
color_theme : AppColorTheme,
font_size_screen_scalar : f32,
font_size_canvas_scalar : f32,
text_snap_glyph_positions : b32,
text_size_screen_scalar : f32,
text_size_canvas_scalar : f32,
text_alpha_sharpen : f32,
}
AppWindow :: struct {

View File

@ -152,8 +152,10 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
color_theme = App_Thm_Dusk
font_size_screen_scalar = 1.0
font_size_canvas_scalar = 1.0
text_snap_glyph_positions = true
text_size_screen_scalar = 2.0
text_size_canvas_scalar = 2.0
text_alpha_sharpen = 0.25
}
Desired_OS_Scheduler_MS :: 1
@ -354,7 +356,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (197).txt", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (1022).txt", allocator = persistent_slab_allocator())
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/sokol_gp.h", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/sokol_gp.h", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/ve_fontcache.h", allocator = persistent_slab_allocator())
alloc_error : AllocatorError; success : bool

View File

@ -57,7 +57,7 @@ render_mode_2d_workspace :: proc( screen_extent : Vec2, cam : Camera, input : In
screen_size := screen_extent * 2
// TODO(Ed): Eventually will be the viewport extents
ve.set_px_scalar( ve_ctx, app_config().font_size_canvas_scalar )
font_provider_set_px_scalar( app_config().text_size_canvas_scalar )
ve.configure_snap( ve_ctx, u32(screen_size.x), u32(screen_size.y) )
// ve.configure_snap( ve_ctx, 0, 0 )
@ -123,7 +123,7 @@ render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State
screen_size := screen_extent * 2
screen_ratio := screen_size.x * ( 1.0 / screen_size.y )
ve.set_px_scalar( ve_ctx, app_config().font_size_screen_scalar )
font_provider_set_px_scalar( app_config().text_size_canvas_scalar )
ve.configure_snap( ve_ctx, u32(screen_size.x), u32(screen_size.y) )
render_screen_ui( screen_extent, screen_ui, ve_ctx, ve_render )
@ -265,14 +265,6 @@ render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State
}
}
if true {
zoom_adjust_size := 16 * state.project.workspace.cam.zoom
over_sample := f32(state.config.font_size_canvas_scalar)
debug_text("font_size_canvas_scalar: %v", config.font_size_canvas_scalar)
ve_id, resolved_size := font_provider_resolve_draw_id( default_font, zoom_adjust_size * over_sample )
debug_text("font_size resolved: %v px", resolved_size)
}
render_text_layer( screen_extent, ve_ctx, ve_render )
}
@ -663,6 +655,7 @@ render_ui_via_box_list :: proc( box_list : []UI_RenderBoxInfo, text_list : []UI_
if cam != nil {
draw_text_string_pos_extent_zoomed( entry.text, font, entry.font_size, entry.position, cam_offset, screen_size, screen_size_norm, cam.zoom, entry.color )
// draw_text_shape_pos_extent_zoomed( entry.shape, font, entry.font_size, entry.position, cam_offset, screen_size, screen_size_norm, cam.zoom, entry.color )
}
else {
draw_text_string_pos_extent( entry.text, font, entry.font_size, entry.position, entry.color )
@ -987,10 +980,6 @@ draw_text_string_pos_extent_zoomed :: #force_inline proc( text : string, id : Fo
zoom_adjust_size := size * zoom
// Over-sample font-size for any render under a camera
// over_sample : f32 = f32(config.font_size_canvas_scalar)
// zoom_adjust_size *= over_sample
pos_offset := (pos + cam_offset)
render_pos := ws_view_to_render_pos(pos)
normalized_pos := render_pos * screen_size_norm
@ -1007,11 +996,7 @@ draw_text_string_pos_extent_zoomed :: #force_inline proc( text : string, id : Fo
text_scale.y = clamp( text_scale.y, 0, screen_size.y )
}
// Down-sample back
// text_scale /= over_sample
color_norm := normalize_rgba8(color)
// ve.set_px_scalar( & get_state().font_provider_ctx.ve_ctx, config.font_size_canvas_scalar )
ve.set_colour( & get_state().font_provider_ctx.ve_ctx, color_norm )
ve.draw_text( & get_state().font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), normalized_pos, text_scale, text )
}

View File

@ -302,19 +302,20 @@ update :: proc( delta_time : f64 ) -> b32
// TODO(Ed): We need input buffer so that we can consume input actions based on the UI with priority
font_provider_set_px_scalar( app_config().font_size_screen_scalar )
ui_screen_tick( & get_state().screen_ui )
//region WorkspaceImgui Tick
if true
{
font_provider_set_px_scalar( app_config().font_size_canvas_scalar )
font_provider_set_px_scalar( app_config().text_size_canvas_scalar )
profile("Workspace Imgui")
// Creates the root box node, set its as the first parent.
ui_graph_build( & state.project.workspace.ui )
ui := ui_context
ui.zoom_scale = state.project.workspace.cam.zoom
frame_style_flags : UI_LayoutFlags = {
.Fixed_Position_X, .Fixed_Position_Y,
.Fixed_Width, .Fixed_Height,

View File

@ -140,6 +140,12 @@ font_provider_resolve_draw_id :: #force_inline proc( id : FontID, size := Font_U
return
}
measure_text_shape :: #force_inline proc( shape : ShapedText ) -> Vec2
{
measured := ve.measure_shape_size( & get_state().font_provider_ctx.ve_ctx, shape )
return measured
}
measure_text_size :: #force_inline proc( text : string, font : FontID, font_size := Font_Use_Default_Size, spacing : f32 ) -> Vec2
{
ve_id, size := font_provider_resolve_draw_id( font, font_size )

View File

@ -123,6 +123,8 @@ UI_State :: struct {
// build_arenas : [2]Arena,
// build_arena : ^ Arena,
zoom_scale : f32,
built_box_count : i32,
caches : [2] HMapChained( UI_Box ),
@ -285,15 +287,6 @@ ui_graph_build_end :: proc( ui : ^UI_State )
{
if len(current.text) > 0 {
profile("text shape")
// app_window := get_state().app_window
// screen_extent := app_window.extent
// screen_size := screen_extent * 2
// screen_size_norm := 1 / screen_size
font_size_screen_scalar := app_config().font_size_screen_scalar
// over_sample : f32 = f32(get_state().config.font_size_canvas_scalar)
current.computed.text_shape = shape_text_cached( current.text, current.style.font, current.layout.font_size, 1.0 )
}
ui_box_compute_layout( current )

View File

@ -73,7 +73,7 @@ ui_box_compute_layout :: proc( box : ^UI_Box,
text_size : Vec2
if len(box.text) > 0
{
text_size = computed.text_shape.size
text_size = measure_text_shape( computed.text_shape )
// if layout.font_size == computed.text_size.y {
// text_size = computed.text_size
// }