Skip to content

Add example project for how to use CanvasItemGizmoPlugins#1305

Draft
derkork wants to merge 2 commits intogodotengine:masterfrom
derkork:proposal-1910
Draft

Add example project for how to use CanvasItemGizmoPlugins#1305
derkork wants to merge 2 commits intogodotengine:masterfrom
derkork:proposal-1910

Conversation

@derkork
Copy link
Copy Markdown

@derkork derkork commented Mar 17, 2026

This PR adds an example project for the new 2D gizmo plugins introduced in: godotengine/godot#112979. I'll keep this a draft until the PR is in a state to be merged.

func _get_gizmo_name() -> String:
return "Circle"

## This function tells the editor whether this node has a bounding rectangle.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## This function tells the editor whether this node has a bounding rectangle.
## This function tells the editor whether this node has a bounding rectangle.

Everywhere, two empty lines between methods

## This is only called if _edit_use_rect returns true.
func _edit_get_rect(gizmo: EditorCanvasItemGizmo) -> Rect2:
# First we get the node we're editing
var circle:Circle = gizmo.get_canvas_item()
Copy link
Copy Markdown
Member

@AThousandShips AThousandShips Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var circle:Circle = gizmo.get_canvas_item()
var circle: Circle = gizmo.get_canvas_item()

Everywhere for var

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the GDScript style guide, no space before the standalone colon.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I thought we did the opposite recently, will correct

## This function tells the editor what the bounding rectangle of the node is.
## This is only called if _edit_use_rect returns true.
func _edit_get_rect(gizmo: EditorCanvasItemGizmo) -> Rect2:
# First we get the node we're editing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# First we get the node we're editing
# First we get the node we're editing.

For all

# the base state (transform, etc.) is automatically saved from the
# underlying node, so we only need to add what is custom to our node. In our case
# this is just the pivot field.
return {"pivot" : circle.pivot }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return {"pivot" : circle.pivot }
return { "pivot" : circle.pivot }

Trailing whitespace needs to be removed everywhere

var _circle_gizmo_plugin:CircleGizmoPlugin
var _flower_gizmo_plugin:FlowerGizmoPlugin

## Registers the gizmo plugins with the editor.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Registers the gizmo plugins with the editor.
## Registers the gizmo plugins with the editor.

Same here

return

var undo_redo:EditorUndoRedoManager = EditorInterface.get_editor_undo_redo()
undo_redo.create_action("Set radius ")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
undo_redo.create_action("Set radius ")
undo_redo.create_action("Set radius")

func _edit_get_rect(gizmo: EditorCanvasItemGizmo) -> Rect2:
# First we get the node we're editing
var circle:Circle = gizmo.get_canvas_item()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty lines should be fully empty with no trailing whitespace, everywhere


# Otherwise, we need to create an undo/redo action for the change:
var undo_redo:EditorUndoRedoManager = EditorInterface.get_editor_undo_redo()
undo_redo.create_action("Set radius ")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
undo_redo.create_action("Set radius ")
undo_redo.create_action("Set radius")

## The radius of the flower disk.
@export var radius:float = 100:
set(value):
radius = max(0, value)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
radius = max(0, value)
radius = maxf(0, value)

@export var radius:float = 100:
set(value):
# don't allow negative values
radius = max(0, value)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
radius = max(0, value)
radius = maxf(0, value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants