cancel
Showing results for 
Search instead for 
Did you mean: 

how to size customList in view using model const

JPabl.1
Senior

Hi there Touchgfx team!

 

I have a view with a custom container list as in the ListLayout example. 

 

class test_selectionView : public test_selectionViewBase
{
public:
    test_selectionView();
    virtual ~test_selectionView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();

    /**
     * Handler of list element clicks.
     */
    void listElementClicked(CustomListElement &element);

protected:
    static const int number_of_select_test_kit_list_elements = 30;
    CustomListElement select_test_kit_list_elements[number_of_select_test_kit_list_elements];


    // Callback that is assigned to each list element
    Callback<test_selectionView, CustomListElement &> listElementClickedCallback;
};

 

I would like to have the number of elements in the model, and access it with a get method. Right now, you can see I'm harcoding the "30" value in the view. 

I already created number_of_select_test_kit_list_elements in the model and created the get method, because that number will be used across several screens. 

How can I create the CustomListElement using the get method from the model? 

 

Thanks a lot in advance

1 ACCEPTED SOLUTION

Accepted Solutions

If I have understood your question correctly, custom containers cannot directly access the values in the Model, and you have to provide access to them through the screens they are instantiated in. Therefore, you will not be able to create an array with a variable as the number of elements, in other words, a non-constant as the number of array elements. That is the reason why I suggest using Scroll List.

Mohammad MORADI
ST Software Developer | TouchGFX

View solution in original post

4 REPLIES 4

Hello @JPabl.1,

I suggest using Scroll List instead, which allows you to set the number of elements you want via setNumberOfItems(). Just keep in mind that in the TouchGFX designer, you have to create your scroll list as large as the number of elements it should accommodate (even if the list grows out of the screen). 

I hope this helps you! 

 

Mohammad MORADI
ST Software Developer | TouchGFX
JPabl.1
Senior

Hi @Mohammad MORADI ESFAHANIASL thanks for the reply. 

 

I have a custom container with some text and a button. If I understand correctly, I need to initialize the custom container amount of elements, that's what I do here: 

protected:
    static const int number_of_select_test_kit_list_elements = 30;
    CustomListElement select_test_kit_list_elements[number_of_select_test_kit_list_elements];

The listLayout size is not a problem because I can use the add method inside a for loop. I use a get method from the model for the for loop limit. That is, I have a "30" in my model and I call the get method. If I need to update this value in the future, I just change the value in the model and that's it. 

What I want is to be able to set the custom container using this get method, to avoid the scenario where I need to update values both in model and views

JPabl1_1-1729261078634.png

 

 

If I have understood your question correctly, custom containers cannot directly access the values in the Model, and you have to provide access to them through the screens they are instantiated in. Therefore, you will not be able to create an array with a variable as the number of elements, in other words, a non-constant as the number of array elements. That is the reason why I suggest using Scroll List.

Mohammad MORADI
ST Software Developer | TouchGFX

Hello @JPabl.1 ,


Have you been able to move forward on your project?

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)