2024-02-27 06:27 AM
Hi,
i have a scrollable container with some objects inside:
on the left and right i have these images:
i need to hide the images images on left and right border according to scroll position and number of objects:
Any suggestion?
Solved! Go to Solution.
2024-02-27 08:13 AM
Hello @ToniT ,
I took some freedom and assumed you wanted to display you side images only when you are able to scroll in the direction of the image (assuming that 6 objects make is so that the container cannot fully hold all the elements but this is only true with a specific size of elements).
I implemented a handleTickEvent function that is called 60 times per second and check the current "amount of scroll" to see if we are scrolled completely to the right, in the middle or to the left and set visible or not the side images :
void Screen1View::handleTickEvent()
{
boxLeft.setVisible(scrollableContainer1.getChildrenContainedArea().x<0);
boxRight.setVisible(scrollableContainer1.getChildrenContainedArea().right()-scrollableContainer1.getWidth()>0);
boxLeft.invalidate();
boxRight.invalidate();
//to see the values
if(0 == tickCount%60) //every sec
{
Rect containedArea = scrollableContainer1.getChildrenContainedArea();
touchgfx_printf("\nleft : %03d\t|\tright : %03d", containedArea.x, containedArea.right());
touchgfx_printf("\nleft : %03d\t|\tright : %03d (minus width [%03d])", containedArea.x, containedArea.right()-scrollableContainer1.getWidth(), scrollableContainer1.getWidth());
}
tickCount++;
}
Please find attached my project.
Hope this answers your question.
If you really want to check the amount of children, you can iterate through the children and count them :
Drawable* child = firstChild;
// child found (!=0)
while (child)
{
// set the touchable property of that child
childCount++;;
// find next sibling
child = child->nextSibling;
}
Regards,
2024-02-27 08:13 AM
Hello @ToniT ,
I took some freedom and assumed you wanted to display you side images only when you are able to scroll in the direction of the image (assuming that 6 objects make is so that the container cannot fully hold all the elements but this is only true with a specific size of elements).
I implemented a handleTickEvent function that is called 60 times per second and check the current "amount of scroll" to see if we are scrolled completely to the right, in the middle or to the left and set visible or not the side images :
void Screen1View::handleTickEvent()
{
boxLeft.setVisible(scrollableContainer1.getChildrenContainedArea().x<0);
boxRight.setVisible(scrollableContainer1.getChildrenContainedArea().right()-scrollableContainer1.getWidth()>0);
boxLeft.invalidate();
boxRight.invalidate();
//to see the values
if(0 == tickCount%60) //every sec
{
Rect containedArea = scrollableContainer1.getChildrenContainedArea();
touchgfx_printf("\nleft : %03d\t|\tright : %03d", containedArea.x, containedArea.right());
touchgfx_printf("\nleft : %03d\t|\tright : %03d (minus width [%03d])", containedArea.x, containedArea.right()-scrollableContainer1.getWidth(), scrollableContainer1.getWidth());
}
tickCount++;
}
Please find attached my project.
Hope this answers your question.
If you really want to check the amount of children, you can iterate through the children and count them :
Drawable* child = firstChild;
// child found (!=0)
while (child)
{
// set the touchable property of that child
childCount++;;
// find next sibling
child = child->nextSibling;
}
Regards,
2024-02-27 11:17 PM
HI,
it's exactly what I needed, works great.
Thank you