ButtonShape2D
- Last UpdatedFeb 19, 2025
- 14 minute read
The ButtonShape2D node provides full pushbutton and toggle functionality. A ButtonShape2D can assume four different states: Normal, Over, Down, and Disabled. A different image and/or shape can be assigned to each state.
ButtonShape2D facilitates the design of 2D adaptive interfaces by providing configuration parameters that allow to easy management of how the graphic scales and aligns when the ButtonShape2D size or aspect ratio does not match the graphic size or aspect ratio.
Platform support
This element is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-P WASM platforms.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Full support |
Full support |
Full support |
Full support |
|
|
|
|
|
|
Button modes
ButtonShape2D supports three button behaviors.
|
Behavior |
Description |
|---|---|
|
push |
A standard stateless pushbutton. When the button is released, it returns to original position. |
|
toggle |
A stateful button. When clicked, the toggle switches its state between pressed and released. Use buttonDown parameter to read toggle state. A ButtonShape2D in pressed state does not support Over state, although it does when released. |
|
radio |
A grouped stateful button. You can create a group of radio buttons by setting them all to radio mode and assigning the same radioGroup name. Only one button in the radio group can be in pressed state. Pressing another button releases the previously pressed button. |
Button states
The ButtonShape2D has four different states: Normal, Over, Down, and Disabled. Different images and shape colors can be defined for each state.
|
State |
Condition |
Image Displayed |
Shape Colors displayed |
|---|---|---|---|
|
Normal |
Enabled, not over, no click |
imageNormal |
shapeNormalColor, shapeNormalBorderColor |
|
Over |
Enabled, over, no click |
imageOver |
shapeOverColor, shapeOverBorderColor |
|
Disabled |
Enabled, over, click |
imageDown |
shapeDownColor, shapeDownBorderColor |
|
Disabled |
Not enabled |
imageDisabled |
shapeDisabledColor, shapeDisabledBorderColor |
Adaptive size support
ButtonShape2D provides functionalities to manage how the displayed image behaves when the node rect has a different size and aspect ratio from the displayed image. The behavior is configured independently through these parameters.
|
Parameter |
Description |
|---|---|
|
imageWrapAlignment |
Defines the alignment of the displayed image relative to the node rect when the image aspect ratio and the node aspect ratio do not match. The following styles are supported: center, left, top, right, bottom, top_left, top_right, bottom_left, bottom_right. |
|
imageWrapMode |
Defines the wrap mode of the image in the node rect. The following styles are supported: fit, fill, fill_width, fill_height, original_size, stretch. Any value except for stretch will make the displayed image keep its original aspect ratio relatively to the grid or the screen. This depends on the parameter imageWrapKeepProportions. |
Wrap mode
The imageWrapMode and shapeWrapMode fields define how the graphics is wrapped in the node rect,
stretch—The simplest behavior is achieved with the stretch style. This behaves exactly as a Button2D node and stretches the graphic so that is covers the entire rect area.

fit—The fit behavior makes the graphic keep its original aspect ratio and keeps the whole graphic inside the node rect by possibly displaying a padding on the top, bottom, left, or right corners depending on the container aspect ratio and selected imageWrapAlignment.
|
|
|
fill—The fill behavior makes the graphic keep its original aspect ratio and fills all the available space in the node rect by possibly cropping the graphic on the top, bottom, left, or right corners depending on the container aspect ratio and selected imageWrapAlignment. The logic is to fill either the width or height of the node rect (whichever needs the major expansion of the graphic to be covered) and crop the graphic on the other measure.
|
|
|
fill_width—The fill_width behavior makes the graphic keep its original aspect ratio and fills all the available width in the node rect by possibly cropping the graphic or displaying a padding on the top or bottom, depending on the container aspect ratio and selected imageWrapAlignment. The logic is to fill the width of the node rect and crop or pad the graphic on the height.
|
|
|
fill_height—The fill_height behavior makes the graphic keep its original aspect ratio and fills all the available height in the node rect by possibly cropping the graphic or displaying a padding on the top or bottom, depending on the container aspect ratio and selected imageWrapAlignment. The logic is to fill the height of the node rect and crop or pad the graphic on the width.
|
|
|
original_size—The original_size behavior makes the graphic keep its original aspect ratio regardless of the size and aspect ratio of the container, padding, and cropping of the image may occur in both width and height when the node rect size is different from the graphic size depending on the selected imageWrapAlignment.

Wrap alignment
The imageWrapAlignment and shapeWrapAlignment fields define how to align the graphic inside the node rect when a wrap mode (different from stretch) is applied.
The most effective way to test the effect of this parameter is to render an image in a bigger container and specify original_size as imageWrapMode. A small image will display inside a bigger node rect and the effect of selecting an alignment is clearly different between different options.
By selecting an imageWrapMode such as fill_width, the imageWrapAlignment options left, center, and right will have the same result. This is due to the image already filling all the horizontal space.
center—The center behavior aligns the graphic at the center of the rect node.

top—The top behavior aligns the graphic at the center of the rect node and keeps it horizontally centered.

bottom—The bottom behavior aligns the graphic at the bottom of the rect node and keeps it horizontally centered.

left—The left behavior aligns the graphic at the left of the rect node and keeps it vertically centered.

right—The right behavior aligns the graphic at the right of the rect node and keeps it vertically centered.

top_left—The top_left behavior aligns the graphic at the top-left corner of the rect node.

top_right—The top_right behavior aligns the graphic at the top-right corner of the rect node.

bottom_left—The bottom_left behavior aligns the graphic at the bottom-left corner of the rect node.

bottom_right—The bottom_right behavior aligns the graphic at the bottom-right corner of the rect node.

Image functionalities
ButtonShape2D can display a different image for each of its states: Normal, Over, Down, Disabled.
PNG and TGA image formats are supported. GIF is also supported, but animation of GIF is not. The first frame will be displayed for animated gif.
|
Parameter |
Description |
|---|---|
|
imageNormal |
The image to display in the Normal state. |
|
imageOver |
The image to display in the Over state. |
|
imageDown |
The image to display in the Down state. |
|
imageDisabled |
The image to display in the Disabled state. |
Image default state
If one or more of the Over, Down, or Disabled states do not have a defined image field, the image defined in the imageNormal field will be used as default image for the state without an image. Therefore, it is possible to provide only one image if there is no need to change image on state change.
Shape functionalities
ButtonShape2D can draw a shape that can have a border. The shape can be picked from three predefined shapes: rectangle, rounded_rectangle, and circle, or can be custom defined.

For each of its states: Normal, Over, Down, and Disabled, it is possible to specify different colors to differentiate the state.

Color parameters
The color parameters can be different for each state.
|
Parameter |
Description |
|---|---|
|
shapeNormalBorderColor |
Defines the color of the border of the shape for the Normal state. Can be transparent |
|
shapeNormalColor |
Defines the color of the shape for the Normal state. Can be transparent |
|
shapeOverBorderColor |
Defines the color of the border of the shape for the Over state. Can be transparent |
|
shapeOverColor |
Defines the color of the shape for the Over state. Can be transparent |
|
shapeDownBorderColor |
Defines the color of the border of the shape for the Down state. Can be transparent |
|
shapeDownColor |
Defines the color of the shape for the Down state. Can be transparent |
|
shapeDisabledBorderColor |
Defines the color of the border of the shape for the Disabled state. Can be transparent |
|
shapeDisabledColor |
Defines the color of the shape for the Disabled state. Can be transparent |
Configuration parameters
Other configuration parameters related to the shape are shared by the four states. The shape and border can change their color in different states, but the shape itself always stays the same.
|
Parameter |
Description |
|---|---|
|
shapeBorderThickness |
Defines the thickness of the border. |
|
shapeCustom |
Allows the definition of a custom shape for shapeStyle=custom_shape, by using the following syntax: where {points=…} is mandatory and shall contain a list of tuples, separated by ‘commas’, representing the points of the contour of the shape; x,y coordinates are expressed in unitary values where 0 represents 0% of the x/y axis and 1 represents 100% of the x,y axis. {tension=…} is optional (default=0) and shall contain a float number representing the tension to apply to the edges of the shape, values >0 will make the shape convex while values <0 will make the shape concave, values in the range [-1,1] are recommended, but numbers outside that range work as well. Example {tension=0.1}{points=0.5 0.1,0.9 0.9,0.1 0.9} This draws a triangle with vertexes in (x:0.5, y:0.1), (x:0.9, y:0.9) and (x:0.1, y:0.9) with slightly convex edges (according to the 0.1 tension) This example is the default value for the shapeCustom field. |
|
shapeRoundRectCorner |
Defines the corners radius, in pixels, of the rounded_rectangle shape. |
|
shapeStyle |
Defines the style of the shape, the following styles are supported: rectangle, rounded_rectangle,circle, custom_shape. |
isOverGraphics
ButtonShape2D provides the isOverGraphics field that gives control of the over state of the pointer with a pixel-perfect check. This field is true if the pixel of the ButtonShape2D graphic underlying the pointer position is colored with an alpha > 0, false otherwise.
pixelPerfectOver
The pixelPerfectOver flag drives the pushbutton functionality with pixel perfect interaction. If set to true, overing and clicking the button will be triggered only if the pixel of the ButtonShape2D graphic underlying the pointer position is colored with an alpha > 0 (uses isOverGraphics as check). Otherwise, interactions will be triggered relying on the whole node rect. This parameter is set to true by default.
renderToTexture2D
ButtonShape2D supports the rendering to a Texture2D. Pushbutton functionality is supported as well.
Code example
This is a code example for the ButtonShape2D node. It creates a node with different images for each state, overlayed to a rounded_rectangle shape which color changes for each different state.
<ButtonShape2D name="ButtonShape2D"
templateInfo="ButtonShape2D|ButtonShape2D"
position="100 100"
size="200 150"
imageNormal="image_normal.png"
imageDown="image_down.png"
imageOver="image_over.png"
imageDisabled="image_disabled.png"
shapeStyle="rounded_rectangle"
shapeNormalColor="0 0.68 0.93 1"
shapeNormalBorderColor="0.44 0.44 0.44 1"
shapeOverColor="0 0.62 0.84 1"
shapeOverBorderColor="0.25 0.25 0.25 1"
shapeDownColor="0.52 0.86 1 1"
shapeDownBorderColor="0.55 0.55 0.55 1"
shapeDisabledColor="0.25 0.25 0.24 1"
shapeDisabledBorderColor="0.067 0.067 0.067 1" />
Image color filter modes
The following options define the strategy to use when applying a color filter to an image:
-
none—The selected color is not applied to the images.
-
screen—The selected color is added to the image. This makes the image brighter and has more effect on dark colors. Black color is colored, light colors will tend to white, and white color stays white (since it is already the lightest color possible). This mode is suited to color black or dark glyphs by a selected color.
-
multiply—The image colors are multiplied by the selected color. This makes the images darker and has more effect on light colors. White color is colored, dark colors will tend to black, and black color stays black (since it is already the darkest color possible). This mode is suited to color white or light glyphs by a selected color.
-
overlay—Applies both screen and multiply strategies to the image by the selected color. This keeps the image brightness almost the same, has a balanced influence on light and dark colors, and allows to color both black and white.
-
invert—Inverts the color of the displayed image. The selected color is not used in this mode.

ButtonShape2D fields
These are the fields for ButtonShape2D node. Only the node-specific fields are indicated, fields obtained by inheritance are not.
Field inheritance: NodeBase > RectBase2D > ButtonShape2D
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
buttonDown |
sbool |
Optional |
Read only |
This field becomes true when the button is pressed. |
|
changeOnUp |
sbool |
Optional |
false |
This field enables custom behavior of the buttonDown update for toggle and radio button modes. When set to false, buttonDown changes on mouse down. When set to true, it changes on mouse up. |
|
clicked |
sevent |
Optional |
Read only |
Raised when a click is completed (mouseDown and mouseUp inside button area). |
|
doubleClicked |
sevent |
Optional |
Read only |
Raised when the interval between two clicks is less than doubleClickedDelay. |
|
doubleClickedDelay |
sfloat |
Optional |
0.5 |
Maximum interval, in seconds, between two clicks to recognize a double-click. |
|
enabled |
sbool |
Optional |
true |
Enabled button interaction. |
|
joyInputEnable |
sbool |
Optional |
true |
Enabled joypad interaction. |
|
keyInputEnable |
sbool |
Optional |
true |
Enabled keyboard interaction. |
|
imageDisabled |
sstring |
Optional |
|
The image shown when disabled. |
|
imageDisabledColorFilter |
svec4 |
Optional |
127, 127, 127 |
A solid color that is blended to the imageDisabled, supports alpha channel. For more information about different blend strategies, see Image color filter modes. |
|
imageDisabledColorFilter Mode |
senum |
Optional |
none |
Defines the strategy used to blend the color selected in imageDisabledColorFilter to the displayed imageDisabled, The following options are available: none, screen, multiply, color, invert. See Image color filter modes section for details. |
|
imageDown |
sstring |
Optional |
|
The Clicked state image. |
|
imageDownColorFilter |
svec4 |
Optional |
147, 56, 51 |
A solid color that is blended on the displayed imageDown, supports alpha channel. For more information about different blend strategies, see Image color filter modes. |
|
imageDownColorFilterMode |
senum |
Optional |
none |
Defines the strategy used to blend the color selected in imageDownColorFilter on the displayed imageDown. The following options are available: none, screen, multiply, color, invert. See Image color filter modes section for details. |
|
imageNormal |
sstring |
Optional |
|
The Normal state image. |
|
imageNormalColorFilter |
svec4 |
Optional |
0, 175, 239 |
A solid color that is blended on the displayed imageNormal, supports alpha channel. For more information about different blend strategies, see Image color filter modes. |
|
imageNormalColorFilterMode |
senum |
Optional |
none |
Defines the strategy used to blend the color selected in imageNormalColorFilter on the displayed imageNormal, the following options are available: none, screen, multiply, color, invert. See Image color filter modes section for details. |
|
imageOver |
sstring |
Optional |
|
The Over state image. |
|
imageOverColorFilter |
svec4 |
Optional |
0, 175, 79 |
A solid color that is blended on the displayed imageOver, supports alpha channel. For more information about different blend strategies, see Image color filter modes. |
|
imageOverColorFilterMode |
senum |
Optional |
none |
Defines the strategy used to blend the color selected in imageOverColorFilteron the displayed imageOver. The following options are available: none, screen, multiply, color, invert. See Image color filter modes section for details. |
|
imageWrapAlignmentc |
senum |
Optional, |
center |
Defines the alignment of the displayed image relative to the node rect when the image aspect ratio and the node aspect ratio do not match. The following styles are supported: center, left, top, right, bottom, top_left, top_right, bottom_left, bottom_right. Only used when an image field is set. |
|
imageWrapMode |
senum |
Optional, |
fit |
Defines the wrap mode of the image in the node rect. The following styles are supported: fit, fill, fill_width, fill_height, original_size, stretch. Any value, except for stretch, will make the displayed image keep its original aspect ratio relative to the grid or the screen (depending on imageWrapKeepProportions). Only used when an image field is set |
|
isOverGraphics |
sbool |
Read only |
false |
Reveals the over state of the pointer with a pixel-perfect check. This field is true if the pixel of the ButtonShape2D graphics underlying the pointer position is colored with an alpha>0, false otherwise. |
|
mode |
senum |
push |
Specifies the button type as push, toggle, or radio. These values must be in lowercase. |
|
|
mouseDown |
sevent |
Optional |
Read only |
Raised when pressing mouse left button inside button area. |
|
mouseUp |
sevent |
Optional |
Read only |
Raised when releasing mouse left button inside button area or exiting button area with mouse left button pressed. |
|
radioGroup |
sstring |
Optional |
|
Used only when mode is set to radio. All the buttons set to radio mode that have the same radioGroup string value are grouped together. |
|
shapeBorderThickness |
sfloat |
Optional |
2 |
Defines the thickness of the border. Only used when shapeStyle field is different from none |
|
shapeCustom |
senum |
Optional |
{tension=0.1}
|
Allows the definition of a custom shape by using the following syntax: where {points=…} is mandatory and shall contain a list of tuples, separated by ‘commas’, representing the points of the contour of the shape; x,y coordinates are expressed in unitary values where 0 represents 0% of the x/y axis and 1 represents 100% of the x,y axis {tension=…} is optional (default=0) and shall contain a float number representing the tension to apply to the edges of the shape, values >0 will make the shape convex while values <0 will make the shape concave, values in the range [-1,1] are recommended, but numbers outside that range work as well Example {tension=0.1}{points=0.5 0.1,0.9 0.9,0.1 0.9} This draws a triangle with vertexes in (x:0.5, y:0.1), (x:0.9, y:0.9) and (x:0.1, y:0.9) with slightly convex edges (according to the 0.1 tension) This example is the default value for the shapeCustom field. Only used when shapeStyle field is different from none. |
|
shapeDisabledBorderColor |
svec4 |
Optional |
17, 17, 17, 1 |
Defines the border color of the shape for the Disabled state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeDisabledColor |
svec4 |
Optional |
63, 63, 63, 1 |
Defines the color of the shape for the Disabled state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeDownBorderColor |
svec4 |
Optional |
140, 140, 140, 1 |
Defines border color of the shape for the Down state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeDownColor |
svec4 |
Optional |
132, 219, 255, 1 |
Defines the color of the shape for the Down state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeNormalBorderColor |
svec4 |
Optional |
114, 114, 114, 1 |
Defines the border color of the shape for the Normal state. It can be transparent. Only used when shapeStyle field is different from none |
|
shapeNormalColor |
svec4 |
Optional |
0, 175, 239, 1 |
Defines the color of the shape for the Normal state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeOverBorderColor |
svec4 |
Optional |
63, 63, 63, 1 |
Defines the border color of the shape for the Over state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeOverColor |
svec4 |
Optional, |
0, 158, 214, 1 |
Defines the color of the shape for the Over state. It can be transparent. Only used when shapeStyle field is different from none. |
|
shapeRoundRectCorner |
sfloat |
Optional, |
20 |
Defines the corners radius, in pixels, of the rounded_rectangle shape. Only used when shapeStyle field is rounded_rectangle. |
|
shapeStyle |
senum |
Mandatory |
none |
Defines the style of the shape. The following styles are supported: rectangle, rounded_rectangle,circle, custom_shape, none. |







