1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Expose FileDialog callbacks for getting custom icons

This commit is contained in:
kobewi
2025-06-30 19:07:12 +02:00
parent d705613db3
commit f88b51995b
6 changed files with 138 additions and 13 deletions

View File

@@ -131,6 +131,34 @@
[b]Note:[/b] [FileDialog] will update its internal [ItemList] of favorites when its visibility changes. Be sure to call this method earlier if you want your changes to have effect.
</description>
</method>
<method name="set_get_icon_callback" qualifiers="static">
<return type="void" />
<param index="0" name="callback" type="Callable" />
<description>
Sets the callback used by the [FileDialog] nodes to get a file icon, when [constant DISPLAY_LIST] mode is used. The callback should take a single [String] argument (file path), and return a [Texture2D]. If an invalid texture is returned, the [theme_item file] icon will be used instead.
</description>
</method>
<method name="set_get_thumbnail_callback" qualifiers="static">
<return type="void" />
<param index="0" name="callback" type="Callable" />
<description>
Sets the callback used by the [FileDialog] nodes to get a file icon, when [constant DISPLAY_THUMBNAILS] mode is used. The callback should take a single [String] argument (file path), and return a [Texture2D]. If an invalid texture is returned, the [theme_item file_thumbnail] icon will be used instead.
Thumbnails are usually more complex and may take a while to load. To avoid stalling the application, you can use [ImageTexture] to asynchronously create the thumbnail.
[codeblock]
func _ready():
FileDialog.set_get_thumbnail_callback(thumbnail_method)
func thumbnail_method(path):
var image_texture = ImageTexture.new()
make_thumbnail_async(path, image_texture)
return image_texture
func make_thumbnail_async(path, image_texture):
var thumbnail_texture = await generate_thumbnail(path) # Some method that generates a thumbnail.
image_texture.set_image(thumbnail_texture.get_image())
[/codeblock]
</description>
</method>
<method name="set_option_default">
<return type="void" />
<param index="0" name="option" type="int" />