cancel
Showing results for 
Search instead for 
Did you mean: 

Drawables

heyo
Senior

Hi, I created a list and I need set visible image when element of the list is clicked

0693W00000aImXhQAK.pngBut problem is that others drawables does not unselected when pressed one of the list elements. When I click on list element I call this function

void AddZone::ZoneSelected()
{
	SelectedZone.setVisible(true);
}

How to unselect others when one of them is pressed? (I can't use radio button because I need scaleable image)

2 REPLIES 2
Romain DIELEMAN
ST Employee

Hi,

Could you give a bit more context on how your code works ? How is your list implemented ? Are you using a list layout widget or is it through another implementation or user code ?

What are those selectedZone that you set visible ? I guess it is a kind of background image you turn visible according to your screenshot ? Could you not just implement a function that sets all of those background images invisible before setting the correct one to visible ? (terrible coding I know :grinning_face_with_sweat: but we need more context on your side anyway to give a better implementation)

/Romain

Yes Im using listlayout .SelectedZone is scalable image which becomes visible when I click. First of all when I click this button:

0693W00000aInZ5QAK.pngit calls function below which creates list elements:

void InputOutpuConfigurationView::AddNewZone()
{
	uint8_t zoneadd = addzone;
	FansExpandss.setVisible(false);
	FansExpand.setVisible(false);
	Fans.setVisible(false);
	fans.setVisible(false);
	DeleteZone.setVisible(true);
	uint8_t SavedIdx = presenter->getZoneVal();
	if(SavedIdx != addzone-1)
		addzone = SavedIdx+1;
	if(addzone<11)
	{
	presenter->SaveClickedZone(addzone);
	presenter->ZoneVal(addzone);
	ZoneClicked(addzone);
	selectedzone.setX((86*(addzone))+zonescroll.getScrolledX());
	Unicode::snprintf(zoneheadlineBuffer, ZONEHEADLINE_SIZE, "%s - %d",TypedText(T_ZONE).getText(),addzone);
	presenter->SaveZoneHeadline(zoneheadlineBuffer,addzone,0);
 
		for (uint8_t i = 0; i < addzone; ++i)
		{
			zonelist.remove(ZoneElements[i]);
		}
		zoneadd = presenter->getZoneVal()+1;
		while(zoneadd > 0)
			{
				zonelist.setHeight(0);
				ZoneElements[zoneadd-1].setupListElement(presenter->getHeadlineOfZone(zoneadd),zoneadd,16,156,241,zoneadd,presenter->getModified(zoneadd));
				zoneadd--;
			}
 
			if(zoneadd == 0)
			{
				addzone = presenter->getZoneVal();
					for (uint8_t i = 0; i < addzone; ++i)
					{
						ZoneElements[i].setAction(listElementClickedCallback);
						zonelist.add(ZoneElements[i]);
					}
			}
	}
	if(addzone>0 && addzone<11)
			addzone++;
}

"setupListElement" sets name, index, color..

void AddZone::setupListElement(Unicode::UnicodeChar* txt,uint8_t add,colortype R,colortype G,colortype B, int _index,int8_t modified)
{
	index = _index;
	Unicode::snprintf(zonetxtBuffer, ZONETXT_SIZE, "%s",txt);
	zonetxtBuffer[ZONETXT_SIZE-1] = '\0';
	zonetxt.setColor(touchgfx::Color::getColorFromRGB(R, G, B));
	zonetxt.resizeToCurrentTextWithAlignment();
	invalidate();
}