cancel
Showing results for 
Search instead for 
Did you mean: 

Scroll List :Select (Highlight) on Click , Remove and Add Elements How to?

Karan 123
Senior

Hi,

I am working on STM32746-DISC Board . I am working with "container" feature of TouchGFX with Scroll List . I have successfully update array elements (Hard Coded) as List Elements as per below link.

https://support.touchgfx.com/docs/tutorials/tutorial-04

// In Screen1View.hpp
void Screen1View::scrollList1UpdateItem(MenuElement& item, int16_t itemIndex)
{
	touchgfx_printf("Update Item = %d\n" ,itemIndex ) ;
   	item.setNumber(itemIndex);
}

// In MenuElement.hpp
const char Rx_Buffer1[11][20] =  {   "LIST.txt", "HELLO.png", "TouchGFX.gif", "STM32F7.doc", "SCROLL.bmp","NEW.xlsx", "TRY.jpg", "GOOD.bmp", "ABC.png", "XYZ.bmp"								};
       void setNumber(int no)
        {
    		touchgfx_printf("setNumber = %d\n" ,no) ;
            Unicode::itoa(no,  textArea3Buffer, TEXTAREA3_SIZE , 10);
      	Unicode::strncpy(textArea3Buffer ,( const char *) Rx_Buffer1[no] , TEXTAREA3_SIZE -1 );
       }

0693W000000WwmCQAS.png

0693W000000WwlEQAS.png

I want to know:

1) Is the right method ?

2) How to Select/Highlight File Name once item is clicked .

and send Selected item (File name) to touchgfx_print windows?

3) How to add/remove the Element (File Name) from List from some other button ?

Please see short video..

--

Karan

23 REPLIES 23
ChintanParmar
Associate III

Hi @Community member​ ,

Thanks for your reply.

I have tried based on your inputs.

But in that box selection logic is not working.

I want to display 10 items in scroll list.

After pressing downkey, it will directly scroll to the last and same happens for upkey.

It should be incremented one by one.

Below is the screenView file.

#include <gui/status_screen/StatusView.hpp>
 
StatusView::StatusView():
scrollListItemSelectedCallback(this, &StatusView::scrollList_digitalInItemSelectedHandler),
previousIndex(100),
currentIndex(100)
{
 
}
 
void StatusView::setupScreen()
{
    StatusViewBase::setupScreen();
    scrollList_digitalIn.setItemSelectedCallback(scrollListItemSelectedCallback);
}
 
void StatusView::tearDownScreen()
{
    StatusViewBase::tearDownScreen();
}
 
void StatusView::DownKeyPressed()
{
	//TODO Write logic for down key for IO screen.
	//touchgfx_printf("MyUpButton(**)  %d \r\n" , selectedMenuItem ) ;
	selectedMenuItem--;
	if(selectedMenuItem < 0 )
		selectedMenuItem = 15 ;
 
	scrollList_digitalIn.animateToItem(selectedMenuItem,0);
	scrollList_digitalIn.invalidate();
}
 
void StatusView::UpKeyPressed()
{
	//TODO Write logic for down key for IO screen.
	//touchgfx_printf("MyUpButton(**)  %d \r\n" , selectedMenuItem ) ;
	selectedMenuItem++;
	if(selectedMenuItem > 15 )
		selectedMenuItem = 0 ;
 
	scrollList_digitalIn.animateToItem(selectedMenuItem,0);
	scrollList_digitalIn.invalidate();
}
 
 
void StatusView::scrollList_digitalInItemSelectedHandler(int16_t itemSelected)
{
	//touchgfx_printf("Item Selected  = %d \r\n" ,itemSelected) ;
	//touchgfx_printf(Rx_Buffer1[itemSelected]) ;
  	//touchgfx_printf(" \r\n" ) ;
	 // touchgfx_printf("Test %d\n", itemSelected);
    for (int i = 0; i < scrollList_digitalInListItems.getNumberOfDrawables(); i++)
    {
        if(!(scrollList_digitalInListItems[i].isSelected()) && itemSelected == scrollList_digitalInListItems[i].getIndex())
        {
            for (int j = 0; j < scrollList_digitalInListItems.getNumberOfDrawables(); j++)
            {
                if(scrollList_digitalInListItems[j].isSelected())
                {
                	scrollList_digitalInListItems[j].setUnselected();
                }
            }
            // scrollListListItems[currentIndex].setUnselected();
            scrollList_digitalInListItems[i].setSelected();
            currentIndex = itemSelected;
        }
    }
}
 
void StatusView::scrollList_digitalInUpdateItem(CustomDIList& item, int16_t itemIndex)
{
	//touchgfx_printf("Update Item = %d\n" ,itemIndex ) ;
	 item.setIndex(itemIndex);
    // touchgfx_printf("test %d\n", itemIndex);
 
    for (int i = 0; i < scrollList_digitalInListItems.getNumberOfDrawables(); i++)
    {
        if(item.getIndex() == currentIndex)
        {
            item.setSelected();
        }
        else
        {
            item.setUnselected();
        }
    }
 
    switch (itemIndex)
    {
    case 0:
        item.UpdateList(T_DILIST_1);
        break;
    case 1:
        item.UpdateList(T_DILIST_2);
        break;
    case 2:
        item.UpdateList(T_DILIST_3);
        break;
    case 3:
        item.UpdateList(T_DILIST_4);
        break;
    case 4:
        item.UpdateList(T_DILIST_5);
        break;
    case 5:
        item.UpdateList(T_DILIST_6);
        break;
    case 6:
        item.UpdateList(T_DILIST_7);
        break;
    case 7:
        item.UpdateList(T_DILIST_8);
        break;
    case 8:
        item.UpdateList(T_DILIST_9);
        break;
    case 9:
        item.UpdateList(T_DILIST_10);
        break;
    case 10:
        item.UpdateList(T_DILIST_11);
        break;
    case 11:
        item.UpdateList(T_DILIST_12);
        break;
    case 12:
        item.UpdateList(T_DILIST_13);
        break;
    case 13:
        item.UpdateList(T_DILIST_14);
        break;
    case 14:
        item.UpdateList(T_DILIST_15);
        break;
    case 15:
        item.UpdateList(T_DILIST_16);
        break;
    }
}

And custom containers list file is as below

#include <gui/containers/CustomDIList.hpp>
 
CustomDIList::CustomDIList():
index(0),
selected(false)
{
 
}
 
void CustomDIList::initialize()
{
    CustomDIListBase::initialize();
}
 
void CustomDIList::UpdateList(TEXTS iconTextID)
{
    text.setTypedText(TypedText(iconTextID));
    text.resizeToCurrentText();
    invalidate();
}
 
void CustomDIList::setIndex(uint8_t ind)
{
    index = ind;
}
 
uint8_t CustomDIList::getIndex()
{
    return index;
}
 
void CustomDIList::setSelected()
{
    box1.setVisible(true);
    invalidate();
    selected = true;
}
 
void CustomDIList::setUnselected()
{
    box1.setVisible(false);
    invalidate();
    selected = false;
}
 
bool CustomDIList::isSelected()
{
    return selected;
}

I am trying to debug out what is happening but getting no positive outcome.

Can you help me for this?

ChintanParmar
Associate III

In my case,

This callback function is not called. scrollList1ItemSelectedHandler()

And due to that currentIndex value is not getting updated. Its default value is 100. And I think that due to that onlt selection logic is not working.

Can you debug your output with UART ​on PC software Like TeraTerm and Send me results?

I am not able to configure ITM Trace console so I cannot send you debug results.

However, I just want to say that my scrollListItemSelectedHandler() function is not called. I think this is callback function. I don't know why callback function is not called.