Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Layout] Image sizes don't bubble up to FIT sized parents in all cases #273

Open
mikejsavage opened this issue Feb 17, 2025 · 3 comments
Open
Labels
bug Something isn't working

Comments

@mikejsavage
Copy link
Contributor

mikejsavage commented Feb 17, 2025

d9e02ab 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.

@nicbarker nicbarker added the bug Something isn't working label Feb 17, 2025
@nicbarker
Copy link
Owner

Thanks for reporting this! Cascading layout bugs are always the most likely to slip through, let's see if I can get it fixed 🙂

@nicbarker
Copy link
Owner

This is reasonably tricky to solve at the moment, are there any workaround or are you stuck?

@mikejsavage
Copy link
Contributor Author

mikejsavage commented Feb 18, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants