This commit is contained in:
2025-11-06 18:11:01 -06:00
parent 0dd4ad8046
commit 60d2d3b8d6
4 changed files with 24 additions and 41 deletions

View File

@@ -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'

View File

@@ -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 crossfade
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

View File

@@ -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

View File

@@ -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