cancel
Showing results for 
Search instead for 
Did you mean: 

I delete an item from ScrollList but doesn't redraw on invalidate()

Iñaki_Bidasoro
Associate III

Hi gm

 

I have the following scroll list

Iaki_Bidasoro_0-1726560497067.png

 

When I click on delete i execute the following code

 

 

void Display_Stages::Delete_Stage(uint8_t id) { // Find element with m_id == id auto it = std::find_if(m_elements.begin(), m_elements.end(), [id](Stages_Element *elem) { return elem->Get_Id() == id; }); if (it != m_elements.end()) { delete *it; m_elements.erase(it); m_total_stages--; // Adjust m_stage_id if necessary if (m_stage_id == id && m_stage_id > 0) m_stage_id--; m_scroll_stages.invalidate(); // Sort elements and update UI Sort_Elements(); Resize_Slider(); } }

 

This code does find the item clicked and it does erase it from the elements list which i use to fill item data on m_scroll_stagesUpdateItem(Stages_Element &item, int16_t itemIndex)

 

But its like the scroll list updates the data so now the item that was on the 5th place is on the 4th place (i clicked the delete 4th item) but it doesnt erase the last element and i don't know how to tell it to redraw.

 

Iaki_Bidasoro_1-1726560681030.png

 

 

void Display_Stages::m_scroll_stagesUpdateItem(Stages_Element &item, int16_t itemIndex) { item.Set_Id(m_elements[itemIndex]->Get_Id()); item.Set_List_Number(m_elements[itemIndex]->Get_List_Number()); item.Set_Pressure(m_elements[itemIndex]->Get_Pressure(), 0); item.Set_Time(m_elements[itemIndex]->Get_Time()); item.Set_Callback(m_stage_callback); if (m_can_scroll) { m_slider.setValue(m_scroll_stages.getNumberOfItems() - itemIndex); } item.invalidate(); }

 

 

This is how I update the scroll List. It works fine on scrollable container but we need scroll list for memory reasons. 

1 ACCEPTED SOLUTION

Accepted Solutions
Osman SOYKURT
ST Employee

Hello @Iñaki_Bidasoro ,

Using the remove() function from std will not decrease your array length, so if you have an array of 5 and you delete the 4th element, you'll see the last item twice at the end.

Osman SOYKURT
ST Software Developer | TouchGFX

View solution in original post

3 REPLIES 3
Osman SOYKURT
ST Employee

Hello @Iñaki_Bidasoro ,

Using the remove() function from std will not decrease your array length, so if you have an array of 5 and you delete the 4th element, you'll see the last item twice at the end.

Osman SOYKURT
ST Software Developer | TouchGFX

And how do I decrease its size, what does it leave,  a nullptr?
I have tried erase() and pop_back() but the result is always the same.

Thx for the reply.

Ok with setNumberOfItems sry and thx.