Skip to main content
CHech.1
Associate III
September 14, 2021
Question

Custom Widget with transparency issue

  • September 14, 2021
  • 2 replies
  • 1256 views

Hi,

following my previous post (Thanks alot!):

https://community.st.com/s/question/0D53W000014VujASAS/rectangle-frame-widget?t=1631603862714

I decided to try and create a custom widget.

I'm struggling with setting part of the widget to be transparent.

More precisely, it is transparent, but for some reason shows the previous screen in the transparent area.

This is my first screen:

0693W00000Dn4ucQAB.pngand this is my second screen:

0693W00000Dn4urQAB.png 

as can be seen, the my custom widget is the frame in the top left corner underneath the status bar.

void RectFrame::draw(const touchgfx::Rect& invalidatedArea) const
{
	touchgfx::Rect absolute = getAbsoluteRect();
 
	uint16_t* framebuffer = touchgfx::HAL::getInstance()->lockFrameBuffer();
 
	int left_edge = invalidatedArea.x;
	int up_edge = invalidatedArea.y;
	int bottom_edge = invalidatedArea.bottom();
	int right_edge = invalidatedArea.right();
	
	for (int y = invalidatedArea.y; y < bottom_edge; y++)
	{
		
		for (int x = invalidatedArea.x; x < right_edge; x++)
		{
			
			if((x >= left_edge && x <= left_edge + thickness) ||
				(x <= right_edge && x >= right_edge - thickness)||
				(y >= up_edge && y <= up_edge + thickness) ||
				(y <= bottom_edge && y >= bottom_edge - thickness)){
 
 
					framebuffer[absolute.x + x + (absolute.y + y) * 
 touchgfx::HAL::DISPLAY_WIDTH] = 0xf800;
 
			}
		}
 
 
	}
 
	touchgfx::HAL::getInstance()->unlockFrameBuffer();
	//HAL::lcd().fillRect(absolute, (255, 0, 0, 255), 0);
}

I tried using the commented fillRect() (which is used by Box) line with different parameters but to no avail.

Thanks you

This topic has been closed for replies.

2 replies

CHech.1
CHech.1Author
Associate III
September 14, 2021

Solved - my getSolidRect() method was incorrect (I used the one shown in the Custom Widget QR Code tutorial)

I switched to

Rect RectFrame::getSolidRect() const{
	return touchgfx::Rect(0, 0, 0, 0);
}

and it solved the issue.

Romain DIELEMAN
ST Employee
September 14, 2021

Good to hear it works :thumbs_up: Thanks for sharing the code and the fix

/Romain