From 60d2d3b8d61153879229151842596f0266cfa321 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 6 Nov 2025 18:11:01 -0600 Subject: [PATCH] fix text --- prosperon/clay.cm | 16 +++++++++------- prosperon/sound.cm | 37 +++---------------------------------- scripts/math.cm | 4 ++++ source/qjs_staef.c | 8 ++++++++ 4 files changed, 24 insertions(+), 41 deletions(-) diff --git a/prosperon/clay.cm b/prosperon/clay.cm index fe6729af..02318b95 100644 --- a/prosperon/clay.cm +++ b/prosperon/clay.cm @@ -159,6 +159,8 @@ clay.spacer = create_view_fn({ behave: layout.behave.hfill | layout.behave.vfill }); +clay.frame = create_view_fn({}); + function image_size(img) { return [img.width * (img.rect?.width || 1), img.height * (img.rect?.height || 1)]; @@ -253,7 +255,6 @@ clay.text = function text(str, ...configs) tsize.x = Math.ceil(tsize.x) tsize.y = Math.ceil(tsize.y) config.size = config.size.map((x,i) => Math.max(x, tsize[i])); - config.text = str; add_item(config); } @@ -300,10 +301,12 @@ clay.draw_commands = function draw_commands(tree_root, pos = {x:0,y:0}) else draw.image(config.background_image, boundingbox, 0, config.color) else if (config.background_color) - draw.rectangle(boundingbox, config.background_color) + draw.rectangle(boundingbox, null, {color:config.background_color}) - if (config.text) - draw.text(config.text, content, config.font, config.color, config.size.width) + if (config.text) { + var baseline_y = content.y //+ config.font.ascent + draw.text(config.text, {x: content.x, y: baseline_y}, config.font, config.color, content.width) + } if (config.image) draw.image(config.image, content, 0, config.color) @@ -329,8 +332,8 @@ clay.draw_debug = function draw_debug(tree_root, pos = {x:0, y:0}) function draw_debug_node(node) { var boundingbox = geometry.rect_move(node.boundingbox,pos); var content = geometry.rect_move(node.content,pos); - draw.rectangle(content, dbg_colors.content); - draw.rectangle(boundingbox, dbg_colors.boundingbox); + draw.rectangle(content, null, {color:dbg_colors.content}); + draw.rectangle(boundingbox, null, {color:dbg_colors.boundingbox}); // draw.rectangle(geometry.rect_move(node.marginbox,pos), dbg_colors.margin); // Recursively draw debug for children @@ -345,7 +348,6 @@ clay.draw_debug = function draw_debug(tree_root, pos = {x:0, y:0}) } clay.print_tree = function print_tree(tree_root, indent = 0) { - log.console(json.encode(tree_root[clay.CHILDREN])) var indent_str = ' '.repeat(indent) var node_type = 'unknown' diff --git a/prosperon/sound.cm b/prosperon/sound.cm index 0b40b138..2a7e17de 100644 --- a/prosperon/sound.cm +++ b/prosperon/sound.cm @@ -21,6 +21,8 @@ audio.pcm = function pcm(file) { } function cleanup() { + var cleaned_voices = voices.filter(v => !v.is_valid()) + cleaned_voices.forEach(v => v.finish_hook?.()) voices = voices.filter(v => v.is_valid()) } @@ -38,39 +40,6 @@ audio.cry = function cry(file) { return function() { v.stop(); v = null } } -// music with optional cross‑fade -var song -audio.music = function music(file, fade = 0.5) { - if (!file) { - if (song) song.volume = 0; - return; - } - - if (!fade) { - song = audio.play(file); - song.loop = true; - return; - } - - if (!song) { - song = audio.play(file); - song.volume = 1; - // tween.tween(song,'volume', 1, fade); - return; - } - - var temp = audio.play(file); - if (!temp) return; - - temp.volume = 1; - var temp2 = song; - // tween.tween(temp, 'volume', 1, fade); - // tween.tween(temp2, 'volume', 0, fade); - song = temp; - song.loop = true; - temp2.stop() -}; - // // pump + periodic cleanup // @@ -92,6 +61,6 @@ function pump() { $_.delay(pump, 1/240) } -//pump() +pump() return audio diff --git a/scripts/math.cm b/scripts/math.cm index cd01a812..8f23d4bf 100644 --- a/scripts/math.cm +++ b/scripts/math.cm @@ -31,4 +31,8 @@ math.rad2turn = function (x) { return x / Math.TAU; }; math.turn2deg = function (x) { return x * 360; }; math.deg2turn = function (x) { return x / 360; }; +math.rand_int = function(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + return math diff --git a/source/qjs_staef.c b/source/qjs_staef.c index 7615a09b..a635dfe0 100644 --- a/source/qjs_staef.c +++ b/source/qjs_staef.c @@ -101,12 +101,20 @@ JSC_CCALL(staef_font_make_text_buffer, // Font property getters/setters JSC_GETSET(font, linegap, number) +JSC_GETSET(font, ascent, number) +JSC_GETSET(font, descent, number) +JSC_GETSET(font, line_height, number) +JSC_GETSET(font, height, number) // Font methods static const JSCFunctionListEntry js_font_funcs[] = { MIST_FUNC_DEF(staef_font, text_size, 5), MIST_FUNC_DEF(staef_font, make_text_buffer, 6), CGETSET_ADD(font, linegap), + CGETSET_ADD(font, ascent), + CGETSET_ADD(font, descent), + CGETSET_ADD(font, line_height), + CGETSET_ADD(font, height), }; // Font constructor function