diff --git a/prosperon/clay.cm b/prosperon/clay.cm index d29f0ee1..ea21d155 100644 --- a/prosperon/clay.cm +++ b/prosperon/clay.cm @@ -100,6 +100,29 @@ clay.draw = function draw(fn, size = [prosperon.camera.width, prosperon.camera.h node.marginbox.y -= margin.t; node.marginbox.width += margin.l+margin.r; node.marginbox.height += margin.t+margin.b; + + // Apply max_size clamping post-layout + if (node.config.max_size) { + if (node.config.max_size.width != null) { + // Clamp the layout rect size + var rect = lay_ctx.get_rect(node.id); + rect.width = Math.min(rect.width, node.config.max_size.width); + // Also clamp bounding box + node.content.width = Math.min(node.content.width, node.config.max_size.width); + node.boundingbox.width = Math.min(node.boundingbox.width, node.config.max_size.width + padding.l + padding.r); + node.marginbox.width = Math.min(node.marginbox.width, node.config.max_size.width + padding.l + padding.r + margin.l + margin.r); + } + if (node.config.max_size.height != null) { + // Clamp the layout rect size + var rect = lay_ctx.get_rect(node.id); + rect.height = Math.min(rect.height, node.config.max_size.height); + // Also clamp bounding box + node.content.height = Math.min(node.content.height, node.config.max_size.height); + node.boundingbox.height = Math.min(node.boundingbox.height, node.config.max_size.height + padding.t + padding.b); + node.marginbox.height = Math.min(node.marginbox.height, node.config.max_size.height + padding.t + padding.b + margin.t + margin.b); + } + } + node.content.y *= -1; node.content.y += size.height; node.boundingbox.y *= -1; @@ -205,22 +228,10 @@ function add_item(config) if (Array.isArray(use_config.size)) { use_config.size = {width: use_config.size[0], height: use_config.size[1]}; } - // Apply max_size constraint + // Apply max_size constraint - only clamp computed size, don't set explicit size pre-layout if (use_config.max_size) { - // For containers with max_size, set explicit size to enable proper clipping - if (use_config.contain && use_config.size.width == 0 && use_config.max_size.width != null) { - use_config.size.width = use_config.max_size.width; - } - if (use_config.contain && use_config.size.height == 0 && use_config.max_size.height != null) { - use_config.size.height = use_config.max_size.height; - } - // Clamp any size that exceeds max_size - if (use_config.max_size.width != null && use_config.size.width > use_config.max_size.width) { - use_config.size.width = use_config.max_size.width; - } - if (use_config.max_size.height != null && use_config.size.height > use_config.max_size.height) { - use_config.size.height = use_config.max_size.height; - } + // max_size should not force explicit sizing pre-layout - let children compute natural size, + // then clamp the container after layout. For now, just ensure we don't set size to max_size. } lay_ctx.set_size(item,use_config.size); lay_ctx.set_contain(item,use_config.contain);