cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX ScrollList with a variable number of items

LaboStk
Associate

Hello,

I am new in TouchGFX and I like it. But now I have a problem:

I am trying to make a ScrollList with a variable number of items. To do that, I made in TouchGFX a ScrolList with number of items: 1  and a height of 50 which is the height of 1 item. The generated code is

 

 scrollList1.setPosition(40, 200, 400, 50);
    scrollList1.setHorizontal(false);
    scrollList1.setCircular(false);
    scrollList1.setEasingEquation(touchgfx::EasingEquations::backEaseOut);
    scrollList1.setSwipeAcceleration(10);
    scrollList1.setDragAcceleration(10);
    scrollList1.setNumberOfItems(1);
    scrollList1.setPadding(0, 0);
    scrollList1.setSnapping(false);
    scrollList1.setOvershootPercentage(75);
    scrollList1.setDrawableSize(50, 0);
    scrollList1.setDrawables(scrollList1ListItems, updateItemCallback);
    add(scrollList1);

 

In the  setUpScreen(), I change the following

 

void Screen4View::setupScreen()
{
	uint16_t elements;
	uint16_t height;
	uint16_t windowsize;

	elements = presenter->NofThick();			// Number of elements

	if(elements < 5) windowsize = elements;		// when < 5 elements, all elements should be visible at same time
		else windowsize = 5;					// max 5 elements should be visible


	height = elements * 50;						// height number of elements * 50 => height of one element

	if (height > 250) height = 250;				// calculate height of the widget				


	scrollList1.setPosition(40, 200, 400, height);
	scrollList1.setWindowSize(windowsize);
	scrollList1.setNumberOfItems(elements);
	scrollList1.invalidate();

    Screen4ViewBase::setupScreen();
}

 

When elements is 1, then ScrollList show 1 element, that's right.
When elements is 2, then the ScrollList show 2 elements, that's right.
When elements is 3 or more, the ScrollList shows 2 elements. I can select the other elements by scrolling through the list, but the ScrollList shows only maximal 2 elements at the same time. What must I change to see more then 2 elements?

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @LaboStk,

It would be easier if you just create a Scroll List in your TouchGFX Designer as large as the maximum number of elements that you will have (it does not matter if the scroll list grows out of the screen), then you can just set the number of elements by using setNumberOfItems(int16_t). If you would like to use setWindowSize(int16_t), please ensure that the defined size for the scroll list is capable of showing the requested number of elements at the same time. 

The logic of your code is correct; however, there is chance of bugs or miscalculations that causes this issue. Therefore, I suggest using simplified methods to reduce the risk of these type of mistakes. 

It is good to point out that you can easily debug your code by using the Visual Studio project generated in the simulator directory. You can find more information about debugging here.

I hope this helps you!
Don't hesitate to ask more questions if you have any!

 

Mohammad MORADI
ST Software Developer | TouchGFX

View solution in original post

3 REPLIES 3

Hello @LaboStk,

It would be easier if you just create a Scroll List in your TouchGFX Designer as large as the maximum number of elements that you will have (it does not matter if the scroll list grows out of the screen), then you can just set the number of elements by using setNumberOfItems(int16_t). If you would like to use setWindowSize(int16_t), please ensure that the defined size for the scroll list is capable of showing the requested number of elements at the same time. 

The logic of your code is correct; however, there is chance of bugs or miscalculations that causes this issue. Therefore, I suggest using simplified methods to reduce the risk of these type of mistakes. 

It is good to point out that you can easily debug your code by using the Visual Studio project generated in the simulator directory. You can find more information about debugging here.

I hope this helps you!
Don't hesitate to ask more questions if you have any!

 

Mohammad MORADI
ST Software Developer | TouchGFX

Thank you very much, now it works.

One strange behaviour: If the number of elements is 1, then the .setPosition-Function in row 18 crashes while setting the width. It's no problem, I removed the setPosition, it is not necessary.

Stefan

Glad to hear that it works :D

Thank you for your feedback, we will look into it.

Best regards,

Mohammad MORADI
ST Software Developer | TouchGFX