clay
clay copied to clipboard
[Layout] Image sizes don't bubble up to FIT sized parents in all cases
https://github.com/nicbarker/clay/commit/d9e02ab1d365054997afe2068b3b59bdc20df5d9 fixes the image element's size, but not its parent's. This emits a 0x100 rectangle with a 100x100 image inside it:
#include <stdio.h>
#define CLAY_IMPLEMENTATION
#include "clay.h"
int main( int argc, char ** argv ) {
static char mem[ 10000000 ];
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory( sizeof( mem ), mem );
Clay_Initialize( arena, { }, { } );
auto measure_text = []( Clay_StringSlice text, Clay_TextElementConfig * config, void * user_data ) -> Clay_Dimensions {
return { 5, 5 };
};
Clay_SetMeasureTextFunction( measure_text, NULL );
Clay_SetLayoutDimensions( Clay_Dimensions { 100, 100 } );
Clay_BeginLayout();
CLAY( {
.id = 1,
.layout = { .sizing = { .width = CLAY_SIZING_FIT( 0.0f ), .height = CLAY_SIZING_PERCENT( 1.0f ) } },
.backgroundColor = { 255, 255, 255, 255 },
} ) {
CLAY( {
.id = 2,
.layout = { .sizing = { .height = CLAY_SIZING_PERCENT( 1.0f ) } },
.image = { .imageData = mem, .sourceDimensions = { 1, 1 } },
} ) { }
};
Clay_RenderCommandArray layout = Clay_EndLayout();
for( int32_t i = 0; i < layout.length; i++ ) {
const Clay_BoundingBox & bounds = layout.internalArray[ i ].boundingBox;
printf( "%d,%d %dx%d\n", int( bounds.x ), int( bounds.y ), int( bounds.width ), int( bounds.height ) );
}
return 0;
}
This does work if you make the child image FIXED/GROW size.
Thanks for reporting this! Cascading layout bugs are always the most likely to slip through, let's see if I can get it fixed 🙂
This is reasonably tricky to solve at the moment, are there any workaround or are you stuck?
You can use size = grow(99999) instead of 100% :)
edit: actually that seems to just be for this poc because the canvas is 100x100, still no rush on this though