clay icon indicating copy to clipboard operation
clay copied to clipboard

allow CLAY_SIZING_PERCENT to be used for the opposite axis

Open DucaRii opened this issue 9 months ago • 2 comments

say you have a parent container in which you wanna have a series of squares where the size is the height of the parent container like so:

Image

the way this would have to be done with the current API (unless im missing something) is like so

CLAY( Clay_ElementDeclaration{
    .id              = CLAY_ID( "ExampleContainer" ),
    .layout          = { .sizing = { CLAY_SIZING_FIXED( 800 ), CLAY_SIZING_PERCENT( 0.2 ) }, .childGap = 8 },
    .backgroundColor = { 50, 50, 50, 255 }
} )
{
    auto element = Clay_GetElementData( CLAY_ID( "ExampleContainer" ) );

    CLAY( Clay_ElementDeclaration{
        .layout          = { .sizing = { CLAY_SIZING_FIXED( element.boundingBox.height ), CLAY_SIZING_PERCENT( 1.f ) } },
        .backgroundColor = { 255, 0, 0, 100 }
    } );

    CLAY( Clay_ElementDeclaration{
        .layout          = { .sizing = { CLAY_SIZING_FIXED( element.boundingBox.height ), CLAY_SIZING_PERCENT( 1.f ) } },
        .backgroundColor = { 255, 0, 0, 100 }
    } );

    CLAY( Clay_ElementDeclaration{
        .layout          = { .sizing = { CLAY_SIZING_FIXED( element.boundingBox.height ), CLAY_SIZING_PERCENT( 1.f ) } },
        .backgroundColor = { 255, 0, 0, 100 }
    } );
}

(note that this would break with any sort of padding in the parent container)

however, i think an api like .layout = { .sizing = { CLAY_SIZING_PERCENT_Y( 1.f ), CLAY_SIZING_PERCENT( 1.f ) } },

would be nicer.

is this something that would be considered for a merge or is it out of scope?

DucaRii avatar Mar 25 '25 21:03 DucaRii

i suppose https://github.com/nicbarker/clay/issues/147 would also address this and might be a cleaner implementation than what i suggested

DucaRii avatar Mar 25 '25 21:03 DucaRii

Aspect ratio boxes will be implemented soon, apologies for the delay 🙂

nicbarker avatar Mar 27 '25 22:03 nicbarker

Since https://github.com/nicbarker/clay/issues/147 is now closed, shouldn't this be closed as well?

lakazatong avatar Oct 04 '25 22:10 lakazatong