Add texture as item in OptionButton, without using images

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LaraUnderCat

So I wanna create an OptionButton with items and item icons as coloured circle,
But without using an image of a circle.

So I try to write a class derived from CanvasItem and named it MyCanvas:

extends CanvasItem

var color = Color.antiquewhite

func _ready():
func _init():
func _draw():
	draw_circle( Vector2(0,0), 50, color)

And then load this class in the project:

extends Panel

onready var opt = $OptionButton
var my_canvas = load("res://res/MyNodes/") 

func _ready():

	var circle =

But item icon isn’t showing anything.
Thanks for reading and helping.

:bust_in_silhouette: Reply From: jgodfrey

Looking at the docs, the OptionButton.add_icon_item() method expects a Texture as the first argument, not a CanvasItem as you appear to be passing it. I guess I wouldn’t expect that to work. Does it not give you an error?

Also, I wonder why you’re trying to do this without using a images? Maybe because you want to dynamically generate the icon content? If that’s the case, is it just the color you want to be dynamic? If so, you could make a white circle image and use the the modulate property to colorize it dynamically.

Not sure if that’s helpful or not…

Thanks. Texture and ImageTexture doesn’t have the property modulate?
At least I can not find it on the documentation.
And yes, I wanna make icons dynamically:)

And there isn’t an error if you use other classes then Texture.

LaraUnderCat | 2022-04-13 05:59