–1 vote

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():
    update()

func _init():
    _draw()

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/MyCanvas.gd") 

func _ready():

    var circle = my_canvas.new()
    opt.add_icon_item(circle,"",0)

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

Godot version latest
in Engine by (11 points)

1 Answer

+1 vote

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...

by (21,732 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.