cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a Scroll List/Scrollable Container of variable size buttons?

psilvaggio
Associate III

I'd like to have a list of buttons that's scrollable, the number of buttons in the list can be changed at run time (it's essentially a list of errors, so errors may become active and inactive at any time), and I'd like to have the button height be variable depending on how long the text is in the button. I've attached a crude mockup.

I've searched these forums and couldn't find any questions dealing with the button size being variable. I followed Tutorial 4: Creating a Scroll Wheel with Custom Behavior, but I'm not sure how or if it's possible to change the size of a particular instance of a custom container on the fly.

I've also explored using a scrollable container widget instead of the scroll list. I would use button widgets and write the code to place and size the buttons within the scrollable container according to how many buttons I need and how large they need to be. Is this a better approach? I'm not sure if I could create buttons on the fly.

Thank you!

2 REPLIES 2
MM..1
Chief II

I dont test it but maybe

void Screen1View::scrollListUpdateItem(CustomContainer& item, int16_t itemIndex)
{
    item.setHeight(itemIndex * 70);
}

Yoann KLEIN
ST Employee

Hello @psilvaggio​ ,

The solution @MM..1​ presented could be a good a way to achieve what you want.

There might be another post very interesting for you here. In this post, I shared a project in which the user could switch to different screens after clicking on "Buttons" contained inside a Custom Container.

That will give you a hint about how to get a particular instance of each dynamically generated button in your Custom Container.

For your user case, you'll simply have to get the current "itemIndex" of your ScrollList and then modify the dimension of this widget, like @MM..1​  showed us.

Let me know if you have other questions,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX