Non-rectangular Buttons in UI Toolkit

Hello, I’m trying to make a button using UI Toolkit in a shape of a ring segment/crescent but UI Toolkit doesn’t seem to have any non-rectangular options for visual elements/buttons. I’ve tried using visual elements with pointer events but the hitbox is still the rectangular hitbox. The button element also seems to only be rectangular. Is there a way to create a non-rectangular button with UI Toolkit?

In a subclass you can override ContainsPoint to change the picking behaviour.

To draw whatever you want on the elements you can either set the background image to something, or use the vector API in the generateVisualContent callback.

1 Like