CanvasGroup

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Child CanvasItem nodes of a CanvasGroup are drawn as a single object. It allows to e.g. draw overlapping translucent 2D nodes without blending (set CanvasItem.SelfModulate property of CanvasGroup to achieve this effect).

Note: The CanvasGroup uses a custom shader to read from the backbuffer to draw its children. Assigning a Material to the CanvasGroup overrides the builtin shader. To duplicate the behavior of the builtin shader in a custom Shader use the following:

package main

import (
	"graphics.gd/shaders/bool"
	"graphics.gd/shaders/float"
	"graphics.gd/shaders/pipeline/CanvasItem"
	"graphics.gd/shaders/rgba"
	"graphics.gd/shaders/texture"
	"graphics.gd/shaders/vec4"
)

type CanvasGroupShader struct {
	CanvasItem.Shader[CanvasGroupShader]

	ScreenTexture texture.Sampler2D[vec4.RGBA]
}

func (sl *CanvasGroupShader) RenderMode() []CanvasItem.RenderMode {
	return []CanvasItem.RenderMode{CanvasItem.Unshaded}
}

func (sl *CanvasGroupShader) Fragment(vertex CanvasItem.Vertex) CanvasItem.Fragment {
	var c = sl.ScreenTexture.SampleLOD(vertex.ScreenUV, float.New(0))
	var threshold = float.Gt(c.A, float.New(0.0001))
	c.R = bool.Mix(c.R, float.Div(c.R, c.A), threshold)
	c.G = bool.Mix(c.G, float.Div(c.G, c.A), threshold)
	c.B = bool.Mix(c.B, float.Div(c.B, c.A), threshold)
	return CanvasItem.Fragment{
		Color: rgba.Mul(vertex.Color, c),
	}
}

Note: Since CanvasGroup and CanvasItem.ClipChildren both utilize the backbuffer, children of a CanvasGroup who have their CanvasItem.ClipChildren set to anything other than [Canvasitem.ClipChildrenDisabled] will not function correctly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsCanvasGroup() Instance
}

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsCanvasGroup

func (self *Extension[T]) AsCanvasGroup() Instance

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsNode2D

func (self *Extension[T]) AsNode2D() Node2D.Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.CanvasGroup

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsCanvasGroup

func (self Instance) AsCanvasGroup() Instance

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsNode2D

func (self Instance) AsNode2D() Node2D.Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ClearMargin

func (self Instance) ClearMargin() Float.X

Sets the size of the margin used to expand the clearing rect of this CanvasGroup. This expands the area of the backbuffer that will be used by the CanvasGroup. A smaller margin will reduce the area of the backbuffer used which can increase performance, however if UseMipmaps is enabled, a small margin may result in mipmap errors at the edge of the CanvasGroup. Accordingly, this should be left as small as possible, but should be increased if artifacts appear along the edges of the canvas group.

func (Instance) FitMargin

func (self Instance) FitMargin() Float.X

Sets the size of a margin used to expand the drawable rect of this CanvasGroup. The size of the CanvasGroup is determined by fitting a rect around its children then expanding that rect by FitMargin. This increases both the backbuffer area used and the area covered by the CanvasGroup both of which can reduce performance. This should be kept as small as possible and should only be expanded when an increased size is needed (e.g. for custom shader effects).

func (Instance) ID

func (self Instance) ID() ID

func (Instance) SetClearMargin

func (self Instance) SetClearMargin(value Float.X)

SetClearMargin sets the property returned by [GetClearMargin].

func (Instance) SetFitMargin

func (self Instance) SetFitMargin(value Float.X)

SetFitMargin sets the property returned by [GetFitMargin].

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetUseMipmaps

func (self Instance) SetUseMipmaps(value bool)

SetUseMipmaps sets the property returned by [IsUsingMipmaps].

func (Instance) UseMipmaps

func (self Instance) UseMipmaps() bool

If true, calculates mipmaps for the backbuffer before drawing the CanvasGroup so that mipmaps can be used in a custom ShaderMaterial attached to the CanvasGroup. Generating mipmaps has a performance cost so this should not be enabled unless required.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL