Skip to main content

ILine2D

Trait ILine2D 

pub trait ILine2D: GodotClass<Base = Line2D> + You_forgot_the_attribute__godot_api {
Show 21 methods // Provided methods fn init(base: Base<Self::Base>) -> Self { ... } fn enter_tree(&mut self) { ... } fn ready(&mut self) { ... } fn exit_tree(&mut self) { ... } fn process(&mut self, delta: f64) { ... } fn physics_process(&mut self, delta: f64) { ... } fn input(&mut self, event: Gd<InputEvent>) { ... } fn shortcut_input(&mut self, event: Gd<InputEvent>) { ... } fn unhandled_key_input(&mut self, event: Gd<InputEvent>) { ... } fn unhandled_input(&mut self, event: Gd<InputEvent>) { ... } fn on_notification(&mut self, what: CanvasItemNotification) { ... } fn on_get(&self, property: StringName) -> Option<Variant> { ... } fn on_set(&mut self, property: StringName, value: Variant) -> bool { ... } fn on_validate_property(&self, property: &mut PropertyInfo) { ... } fn on_get_property_list(&mut self) -> Vec<PropertyInfo> { ... } fn on_property_get_revert(&self, property: StringName) -> Option<Variant> { ... } fn to_string(&self) -> GString { ... } fn draw(&mut self) { ... } fn get_configuration_warnings(&self) -> PackedArray<GString> { ... } fn get_accessibility_configuration_warnings(&self) -> PackedArray<GString> { ... } fn get_focused_accessibility_element(&self) -> Rid { ... }
}
Expand description

§Interface trait for class Line2D.

Functions in this trait represent constructors (init) or virtual method callbacks invoked by the engine.

Base interfaces: INode2D > ICanvasItem > INode > IObject.
(Strike-through means some intermediate Godot classes are marked final, and can thus not be inherited by GDExtension.)

See also Godot docs for Line2D methods.

Provided Methods§

fn init(base: Base<Self::Base>) -> Self

Godot constructor, accepting an injected base object.

base refers to the base instance of the class, which can either be stored in a Base<T> field or discarded. This method returns a fully-constructed instance, which will then be moved into a Gd<T> pointer.

If the class has a #[class(init)] attribute, this method will be auto-generated and must not be overridden.

fn enter_tree(&mut self)

Called when the node enters the SceneTree (e.g. upon instantiating, scene changing, or after calling add_child in a script). If the node has children, its enter_tree callback will be called first, and then that of the children.

Corresponds to the NodeNotification::ENTER_TREE notification in on_notification.

fn ready(&mut self)

Called when the node is “ready”, i.e. when both the node and its children have entered the scene tree. If the node has children, their ready callbacks get triggered first, and the parent node will receive the ready notification afterwards.

Corresponds to the NodeNotification::READY notification in on_notification. See also the @onready annotation for variables.

Usually used for initialization. For even earlier initialization, init may be used. See also enter_tree.

Note: This method may be called only once for each node. After removing a node from the scene tree and adding it again, ready will not be called a second time. This can be bypassed by requesting another call with request_ready, which may be called anywhere before adding the node again.

fn exit_tree(&mut self)

Called when the node is about to leave the SceneTree (e.g. upon freeing, scene changing, or after calling remove_child in a script). If the node has children, its exit_tree callback will be called last, after all its children have left the tree.

Corresponds to the NodeNotification::EXIT_TREE notification in on_notification and signal tree_exiting. To get notified when the node has already left the active tree, connect to the tree_exited.

fn process(&mut self, delta: f64)

Called on each idle frame, prior to rendering, and after physics ticks have been processed. delta is the time between frames in seconds.

It is only called if processing is enabled for this Node, which is done automatically if this method is overridden, and can be toggled with set_process.

Processing happens in order of [member process_priority], lower priority values are called first. Nodes with the same priority are processed in tree order, or top to bottom as seen in the editor (also known as pre-order traversal).

Corresponds to the NodeNotification::PROCESS notification in on_notification.

Note: This method is only called if the node is present in the scene tree (i.e. if it’s not an orphan).

Note: When the engine is struggling and the frame rate is lowered, delta will increase. When delta is increased, it’s capped at a maximum of [member Engine.time_scale] * [member Engine.max_physics_steps_per_frame] / [member Engine.physics_ticks_per_second]. As a result, accumulated delta may not represent real world time.

Note: When --fixed-fps is enabled or the engine is running in Movie Maker mode (see MovieWriter), process delta will always be the same for every frame, regardless of how much time the frame took to render.

Note: Frame delta may be post-processed by [member OS.delta_smoothing] if this is enabled for the project.

fn physics_process(&mut self, delta: f64)

Called once on each physics tick, and allows Nodes to synchronize their logic with physics ticks. delta is the logical time between physics ticks in seconds and is equal to [member Engine.time_scale] / [member Engine.physics_ticks_per_second].

It is only called if physics processing is enabled for this Node, which is done automatically if this method is overridden, and can be toggled with set_physics_process.

Processing happens in order of [member process_physics_priority], lower priority values are called first. Nodes with the same priority are processed in tree order, or top to bottom as seen in the editor (also known as pre-order traversal).

Corresponds to the NodeNotification::PHYSICS_PROCESS notification in on_notification.

Note: This method is only called if the node is present in the scene tree (i.e. if it’s not an orphan).

Note: Accumulated delta may diverge from real world seconds.

fn input(&mut self, event: Gd<InputEvent>)

Called when there is an input event. The input event propagates up through the node tree until a node consumes it.

It is only called if input processing is enabled, which is done automatically if this method is overridden, and can be toggled with set_process_input.

To consume the input event and stop it propagating further to other nodes, set_input_as_handled can be called.

For gameplay input, unhandled_input and unhandled_key_input are usually a better fit as they allow the GUI to intercept the events first.

Note: This method is only called if the node is present in the scene tree (i.e. if it’s not an orphan).

fn shortcut_input(&mut self, event: Gd<InputEvent>)

Called when an InputEventKey, InputEventShortcut, or InputEventJoypadButton hasn’t been consumed by input or any GUI Control item. It is called before unhandled_key_input and unhandled_input. The input event propagates up through the node tree until a node consumes it.

It is only called if shortcut processing is enabled, which is done automatically if this method is overridden, and can be toggled with set_process_shortcut_input.

To consume the input event and stop it propagating further to other nodes, set_input_as_handled can be called.

This method can be used to handle shortcuts. For generic GUI events, use input instead. Gameplay events should usually be handled with either unhandled_input or unhandled_key_input.

Note: This method is only called if the node is present in the scene tree (i.e. if it’s not orphan).

fn unhandled_key_input(&mut self, event: Gd<InputEvent>)

Called when an InputEventKey hasn’t been consumed by input or any GUI Control item. It is called after shortcut_input but before unhandled_input. The input event propagates up through the node tree until a node consumes it.

It is only called if unhandled key input processing is enabled, which is done automatically if this method is overridden, and can be toggled with set_process_unhandled_key_input.

To consume the input event and stop it propagating further to other nodes, set_input_as_handled can be called.

This method can be used to handle Unicode character input with Alt, Alt + Ctrl, and Alt + Shift modifiers, after shortcuts were handled.

For gameplay input, this and unhandled_input are usually a better fit than input, as GUI events should be handled first. This method also performs better than unhandled_input, since unrelated events such as InputEventMouseMotion are automatically filtered. For shortcuts, consider using shortcut_input instead.

Note: This method is only called if the node is present in the scene tree (i.e. if it’s not an orphan).

fn unhandled_input(&mut self, event: Gd<InputEvent>)

Called when an InputEvent hasn’t been consumed by input or any GUI Control item. It is called after shortcut_input and after unhandled_key_input. The input event propagates up through the node tree until a node consumes it.

It is only called if unhandled input processing is enabled, which is done automatically if this method is overridden, and can be toggled with set_process_unhandled_input.

To consume the input event and stop it propagating further to other nodes, set_input_as_handled can be called.

For gameplay input, this method is usually a better fit than input, as GUI events need a higher priority. For keyboard shortcuts, consider using shortcut_input instead, as it is called before this method. Finally, to handle keyboard events, consider using unhandled_key_input for performance reasons.

Note: This method is only called if the node is present in the scene tree (i.e. if it’s not an orphan).

fn on_notification(&mut self, what: CanvasItemNotification)

Called when the object receives a Godot notification.

The type of notification can be identified through what. The enum is designed to hold all possible NOTIFICATION_* constants that the current class can handle. However, this is not validated in Godot, so an enum variant Unknown exists to represent integers out of known constants (mistakes or future additions).

This method is named _notification in Godot, but on_notification in Rust. To send notifications, use the Object::notify method.

See also in Godot docs:

fn on_get(&self, property: StringName) -> Option<Variant>

Called whenever get() is called or Godot gets the value of a property.

Should return the given property’s value as Some(value), or None if the property should be handled normally.

See also in Godot docs:

fn on_set(&mut self, property: StringName, value: Variant) -> bool

Called whenever Godot set() is called or Godot sets the value of a property.

Should set property to the given value and return true, or return false to indicate the property should be handled normally.

See also in Godot docs:

fn on_validate_property(&self, property: &mut PropertyInfo)

Called whenever Godot retrieves value of property. Allows to customize existing properties. Every property info goes through this method, except properties added with on_get_property_list().

Exposed property here is a shared mutable reference obtained (and returned to) from Godot.

See also in the Godot docs:

fn on_get_property_list(&mut self) -> Vec<PropertyInfo>

Available on since_api=4.3 only.

Called whenever Godot get_property_list() is called, the returned vector here is appended to the existing list of properties.

This should mainly be used for advanced purposes, such as dynamically updating the property list in the editor.

See also in Godot docs:

fn on_property_get_revert(&self, property: StringName) -> Option<Variant>

Called by Godot to tell if a property has a custom revert or not.

Return None for no custom revert, and return Some(value) to specify the custom revert.

This is a combination of Godot’s Object::_property_get_revert and Object::_property_can_revert. This means that this function will usually be called twice by Godot to find the revert.

Note that this should be a pure function. That is, it should always return the same value for a property as long as self remains unchanged. Otherwise, this may lead to unexpected (safe) behavior.

fn to_string(&self) -> GString

String representation of the Godot instance.

Override this method to define how the instance is represented as a string. Used by impl Display for Gd<T>, as well as str() and print() in GDScript.

fn draw(&mut self)

Called when CanvasItem has been requested to redraw (after queue_redraw is called, either manually or by the engine).

Corresponds to the CanvasItemNotification::DRAW notification in on_notification.

fn get_configuration_warnings(&self) -> PackedArray<GString>

The elements in the array returned from this method are displayed as warnings in the Scene dock if the script that overrides it is a tool script.

Returning an empty array produces no warnings.

Call update_configuration_warnings when the warnings need to be updated for this node.

@export var energy = 0:
	set(value):
		energy = value
		update_configuration_warnings()

func _get_configuration_warnings():
	if energy < 0:
		return ["Energy must be 0 or greater."]
	else:
		return []

fn get_accessibility_configuration_warnings(&self) -> PackedArray<GString>

The elements in the array returned from this method are displayed as warnings in the Scene dock if the script that overrides it is a tool script, and accessibility warnings are enabled in the editor settings.

Returning an empty array produces no warnings.

fn get_focused_accessibility_element(&self) -> Rid

Called during accessibility information updates to determine the currently focused sub-element, should return a sub-element RID or the value returned by get_accessibility_element.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§