Skip to content

CanvasItem

Eduard Gushchin edited this page Jul 1, 2026 · 5 revisions

Home | API by Category | Complete API Index | API Compatibility

Field Value
Full name Electron2D.CanvasItem
Namespace Electron2D
Kind class
Category Rendering

Overview

Provides the Electron2D base node for items that can be drawn on a 2D canvas.

Syntax

public class Electron2D.CanvasItem : Electron2D.Node

Godot 4.7 C# profile compatibility

Profile: Electron2D 0.1.0 2D
Status: Partial / Not verified
Out of profile: yes
Godot reference: CanvasItem

Visibility, inherited modulate, self-modulate, z-index, y-sort flag, show/hide and GetWorld2D() baseline.

Remarks

CanvasItem owns visibility, color modulation and draw-order properties for 2D nodes. Electron2D 0.1.0 Preview implements the subset required by Node2D, Sprite2D and internal sprite submission.

Visibility and Modulate are inherited only through direct CanvasItem ancestors. A plain Electron2D.Node between two canvas items breaks the inherited canvas chain, matching the canvas inheritance behavior used by this preview.

Thread Safety

This type is not synchronized. Create and mutate canvas items on the main thread that owns the scene tree.

Since

This type is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Node2D
  • Electron2D.Sprite2D

Members

Member Kind Summary
Modulate Property Gets or sets the color multiplied into this item and its direct canvas descendants.
SelfModulate Property Gets or sets the color multiplied into this item only.
Visible Property Gets or sets whether this canvas item is visible.
YSortEnabled Property Gets or sets whether this item participates in Y-sort ordering.
ZIndex Property Gets or sets the 2D draw-order index inside the current canvas layer.
Electron2D.CanvasItem() Constructor Initializes a new instance of the CanvasItem type.
DrawCircle(Electron2D.Vector2, System.Single, Electron2D.Color, System.Boolean, System.Single, System.Boolean) Method Draws a filled or stroked circle in local space.
DrawLine(Electron2D.Vector2, Electron2D.Vector2, Electron2D.Color, System.Single, System.Boolean) Method Draws a line between two local-space points.
DrawPolygon(Electron2D.Vector2[], Electron2D.Color[], Electron2D.Vector2[], Electron2D.Texture2D) Method Draws a solid polygon using per-point colors.
DrawRect(Electron2D.Rect2, Electron2D.Color, System.Boolean, System.Single, System.Boolean) Method Draws a filled or stroked rectangle in local space.
DrawString(Electron2D.Font, Electron2D.Vector2, System.String, Electron2D.HorizontalAlignment, System.Single, System.Int32, Electron2D.Color?) Method Draws text using a font at a local-space baseline position.
DrawTexture(Electron2D.Texture2D, Electron2D.Vector2, Electron2D.Color?) Method Draws a texture at a local-space position.
GetWorld2D() Method Gets the 2D world associated with this canvas item.
Hide() Method Hides this canvas item.
IsVisibleInTree() Method Checks whether this canvas item is visible after direct canvas ancestors are considered.
QueueRedraw() Method Queues this canvas item to redraw during the next processed frame.
Show() Method Shows this canvas item.
_Draw() Method Called when this canvas item has been requested to redraw.

Member Details

Modulate

Kind: Property

public Electron2D.Color Modulate { get; set; }

Summary

Gets or sets the color multiplied into this item and its direct canvas descendants.

Remarks

The default value is Electron2D.Color.White. During submission, inherited Modulate values are multiplied before the current Electron2D.CanvasItem.SelfModulate is applied to the current item.

Value

The current modulate value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.SelfModulate

SelfModulate

Kind: Property

public Electron2D.Color SelfModulate { get; set; }

Summary

Gets or sets the color multiplied into this item only.

Remarks

SelfModulate does not affect children. Use Electron2D.CanvasItem.Modulate when a color should be inherited by direct canvas descendants.

Value

The current self modulate value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.Modulate

Visible

Kind: Property

public System.Boolean Visible { get; set; }

Summary

Gets or sets whether this canvas item is visible.

Remarks

Hidden canvas items also hide direct CanvasItem descendants in the inherited canvas chain. Descendants separated by a non-CanvasItem node start a new independent canvas chain.

Value

The current visible value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

YSortEnabled

Kind: Property

public System.Boolean YSortEnabled { get; set; }

Summary

Gets or sets whether this item participates in Y-sort ordering.

Remarks

Electron2D 0.1.0 Preview forwards this flag to the internal render queue. The full Y-sort container behavior is intentionally limited to the existing queue ordering rules.

Value

The current ysort enabled value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

ZIndex

Kind: Property

public System.Int32 ZIndex { get; set; }

Summary

Gets or sets the 2D draw-order index inside the current canvas layer.

Remarks

Lower values are drawn before higher values within the same Electron2D.CanvasLayer. Layer order still has priority over ZIndex.

Value

The current zindex value.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

Electron2D.CanvasItem()

Kind: Constructor

public Electron2D.CanvasItem()

Summary

Initializes a new instance of the CanvasItem type.

Remarks

The new instance follows the lifetime and validation rules of its declaring type.

Thread Safety

This member is not synchronized. Call it from the thread that owns the related object unless the declaring type states otherwise.

Since

This API is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

DrawCircle(Electron2D.Vector2, System.Single, Electron2D.Color, System.Boolean, System.Single, System.Boolean)

Kind: Method

public System.Void DrawCircle(Electron2D.Vector2, System.Single, Electron2D.Color, System.Boolean, System.Single, System.Boolean)(Electron2D.Vector2 position, System.Single radius, Electron2D.Color color, System.Boolean filled, System.Single width, System.Boolean antialiased)

Summary

Draws a filled or stroked circle in local space.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • position: The local-space circle center.
  • radius: The circle radius. It must be finite and non-negative.
  • color: The circle color.
  • filled: Whether the circle should be filled.
  • width: The stroke width used when filled is false.
  • antialiased: Whether the stroke should request antialiasing when supported.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when radius is negative or not finite.

Thread Safety

This method is not synchronized. Call it only from Electron2D.CanvasItem._Draw on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

DrawLine(Electron2D.Vector2, Electron2D.Vector2, Electron2D.Color, System.Single, System.Boolean)

Kind: Method

public System.Void DrawLine(Electron2D.Vector2, Electron2D.Vector2, Electron2D.Color, System.Single, System.Boolean)(Electron2D.Vector2 from, Electron2D.Vector2 to, Electron2D.Color color, System.Single width, System.Boolean antialiased)

Summary

Draws a line between two local-space points.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • from: The local-space start point.
  • to: The local-space end point.
  • color: The line color.
  • width: The line width. Negative values represent a thin non-scaling primitive line.
  • antialiased: Whether the line should request antialiasing when supported.

Thread Safety

This method is not synchronized. Call it only from Electron2D.CanvasItem._Draw on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

DrawPolygon(Electron2D.Vector2[], Electron2D.Color[], Electron2D.Vector2[], Electron2D.Texture2D)

Kind: Method

public System.Void DrawPolygon(Electron2D.Vector2[], Electron2D.Color[], Electron2D.Vector2[], Electron2D.Texture2D)(Electron2D.Vector2[] points, Electron2D.Color[] colors, Electron2D.Vector2[] uvs, Electron2D.Texture2D texture)

Summary

Draws a solid polygon using per-point colors.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • points: The local-space polygon points. At least three points are required.
  • colors: The colors for each point. The array length must match points.
  • uvs: Optional texture coordinates. When provided, the array length must match points.
  • texture: An optional texture sampled by the polygon.

Exceptions

  • System.ArgumentException: Thrown when the point, color or UV arrays do not describe a valid polygon.

Thread Safety

This method is not synchronized. Call it only from Electron2D.CanvasItem._Draw on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

DrawRect(Electron2D.Rect2, Electron2D.Color, System.Boolean, System.Single, System.Boolean)

Kind: Method

public System.Void DrawRect(Electron2D.Rect2, Electron2D.Color, System.Boolean, System.Single, System.Boolean)(Electron2D.Rect2 rect, Electron2D.Color color, System.Boolean filled, System.Single width, System.Boolean antialiased)

Summary

Draws a filled or stroked rectangle in local space.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • rect: The local-space rectangle.
  • color: The rectangle color.
  • filled: Whether the rectangle should be filled.
  • width: The stroke width used when filled is false.
  • antialiased: Whether the stroke should request antialiasing when supported.

Thread Safety

This method is not synchronized. Call it only from Electron2D.CanvasItem._Draw on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

DrawString(Electron2D.Font, Electron2D.Vector2, System.String, Electron2D.HorizontalAlignment, System.Single, System.Int32, Electron2D.Color?)

Kind: Method

public System.Void DrawString(Electron2D.Font, Electron2D.Vector2, System.String, Electron2D.HorizontalAlignment, System.Single, System.Int32, Electron2D.Color?)(Electron2D.Font font, Electron2D.Vector2 position, System.String text, Electron2D.HorizontalAlignment alignment, System.Single width, System.Int32 fontSize, Electron2D.Color? modulate)

Summary

Draws text using a font at a local-space baseline position.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • font: The font resource used to draw the text.
  • position: The local-space baseline position.
  • text: The text to draw.
  • alignment: The horizontal alignment used when width is non-negative.
  • width: The optional clipping/alignment width. Negative values mean no width limit.
  • fontSize: The requested font size in pixels.
  • modulate: The optional color multiplied into the text. The default is Electron2D.Color.White.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it only from Electron2D.CanvasItem._Draw on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Font

DrawTexture(Electron2D.Texture2D, Electron2D.Vector2, Electron2D.Color?)

Kind: Method

public System.Void DrawTexture(Electron2D.Texture2D, Electron2D.Vector2, Electron2D.Color?)(Electron2D.Texture2D texture, Electron2D.Vector2 position, Electron2D.Color? modulate)

Summary

Draws a texture at a local-space position.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Parameters

  • texture: The texture to draw.
  • position: The local-space top-left draw position.
  • modulate: The optional color multiplied into the texture. The default is Electron2D.Color.White.

Thread Safety

This method is not synchronized. Call it only from Electron2D.CanvasItem._Draw on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

GetWorld2D()

Kind: Method

public Electron2D.World2D GetWorld2D()()

Summary

Gets the 2D world associated with this canvas item.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Returns

A Electron2D.World2D object whose direct space state can query the current Electron2D.SceneTree, or an empty world when this item is not inside a tree.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

Hide()

Kind: Method

public System.Void Hide()()

Summary

Hides this canvas item.

Remarks

This is equivalent to setting Electron2D.CanvasItem.Visible to false. Direct canvas descendants become hidden through the inherited canvas chain.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.Show

IsVisibleInTree()

Kind: Method

public System.Boolean IsVisibleInTree()()

Summary

Checks whether this canvas item is visible after direct canvas ancestors are considered.

Remarks

This method follows the validation and lifetime rules of its declaring type.

Returns

true when this item and its direct CanvasItem ancestor chain are visible; otherwise, false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem

QueueRedraw()

Kind: Method

public System.Void QueueRedraw()()

Summary

Queues this canvas item to redraw during the next processed frame.

Remarks

Multiple calls before the next frame are coalesced into one Electron2D.CanvasItem._Draw callback. Cached draw commands remain active until the callback runs again.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem._Draw

Show()

Kind: Method

public System.Void Show()()

Summary

Shows this canvas item.

Remarks

This is equivalent to setting Electron2D.CanvasItem.Visible to true. Ancestor visibility can still make Electron2D.CanvasItem.IsVisibleInTree return false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.Hide

_Draw()

Kind: Method

public System.Void _Draw()()

Summary

Called when this canvas item has been requested to redraw.

Remarks

Override this method and call the Draw* methods from inside the override. Draw commands are cached and reused until Electron2D.CanvasItem.QueueRedraw requests another draw callback.

Thread Safety

This callback is invoked on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.CanvasItem.QueueRedraw

Clone this wiki locally