2026-03-27 09:51:53 +03:00
# include "ScrollAreaHelpers.hpp"
# include "../GUIManager.hpp"
namespace GUIStuff { namespace ElementHelpers {
2026-04-01 22:28:48 +03:00
ScrollArea * scroll_area_many_entries ( GUIManager & gui , const char * id , const ScrollBarManyEntriesOptions & options ) {
return gui . clipping_element < ScrollArea > ( id , ScrollArea : : Options {
2026-03-27 09:51:53 +03:00
. scrollVertical = true ,
. clipHorizontal = options . clipHorizontal ,
. clipVertical = true ,
. showScrollbarY = true ,
2026-04-01 18:00:22 +03:00
. innerContent = [ & ] ( const ScrollArea : : InnerContentParameters & params ) {
if ( options . innerContentExtraCallback ) options . innerContentExtraCallback ( params ) ;
2026-03-27 09:51:53 +03:00
float absScrollAmount = std : : fabs ( params . scrollOffset . y ( ) ) ;
size_t startPoint = absScrollAmount / options . entryHeight ;
size_t elementsContainable = ( params . containerDimensions . y ( ) / options . entryHeight ) + 2 ; // Displaying 2 more elements ensures that there isn't any empty space in the container
size_t endPoint = std : : min ( options . entryCount , startPoint + elementsContainable ) ;
if ( startPoint ! = 0 ) {
CLAY_AUTO_ID ( {
. layout = {
. sizing = { . width = CLAY_SIZING_GROW ( 0 ) , . height = CLAY_SIZING_FIXED ( startPoint * options . entryHeight ) } ,
}
} ) { }
}
2026-03-30 18:51:14 +03:00
for ( size_t i = startPoint ; i < endPoint ; i + + )
gui . new_id ( i , [ & ] { options . elementContent ( i ) ; } ) ;
2026-03-27 09:51:53 +03:00
if ( endPoint ! = options . entryCount ) {
CLAY_AUTO_ID ( {
. layout = {
. sizing = { . width = CLAY_SIZING_GROW ( 0 ) , . height = CLAY_SIZING_FIXED ( ( options . entryCount - endPoint ) * options . entryHeight ) } ,
}
} ) { }
}
}
} ) ;
}
} }