UI: Dynamic File Browser Tooltips #104547

Merged
Harley Acheson merged 27 commits from Harley/blender:FileTooltips into main 2024-01-03 03:56:23 +01:00
1 changed files with 21 additions and 14 deletions
Showing only changes of commit ba76fada61 - Show all commits

View File

@ -114,10 +114,10 @@ void ED_file_path_button(bScreen *screen,
UI_block_func_set(block, nullptr, nullptr, nullptr);
}
typedef struct file_tooltip_data {
struct file_tooltip_data {
Harley marked this conversation as resolved Outdated
struct FileTooltipData {
  const SpaceFile *sfile;
  const FileDirEntry *file;
};
```c++ struct FileTooltipData { const SpaceFile *sfile; const FileDirEntry *file; }; ```
const SpaceFile *sfile;
const FileDirEntry *file;
} file_tooltip_data;
};
static file_tooltip_data *file_tooltip_data_create(const SpaceFile *sfile,
const FileDirEntry *file)
@ -136,11 +136,14 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData
const FileList *files = sfile->files;
const FileSelectParams *params = ED_fileselect_get_active_params(sfile);
const FileDirEntry *file = file_data->file;
ImBuf *thumb = nullptr;
if (file->asset) {
return;
}
BLI_assert_msg(!file->asset, "Asset tooltip should never be overridden here.");
Harley marked this conversation as resolved Outdated

I'd rather assert here, since when this is called, it would mean any asset tooltip callback was overridden by a file one.

I'd rather assert here, since when this is called, it would mean any asset tooltip callback was overridden by a file one.
/* Check the FileDirEntry first to see if the preview is already loaded. */
ImBuf *thumb = filelist_file_getimage(file);
/* Only free if it is loaded later. */
bool free_imbuf = (thumb == nullptr);
UI_tooltip_text_field_add(
tip, BLI_strdup(file->name), nullptr, UI_TIP_STYLE_HEADER, UI_TIP_LC_MAIN);
@ -190,7 +193,10 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData
if (file->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP))

Why is this only using _read(), instead of _manage()?

Why is this only using `_read()`, instead of `_manage()`?

In this case I don't want to create a new preview if one doesn't exist. Getting the version from the file is faster.

In this case I don't want to create a new preview if one doesn't exist. Getting the version from the file is faster.
{
char version_st[128] = {0};
thumb = IMB_thumb_read(full_path, THB_LARGE);
if (!thumb) {
/* Load the thumbnail from cache if existing, but don't create if not. */
thumb = IMB_thumb_read(full_path, THB_LARGE);
}
if (thumb) {
Harley marked this conversation as resolved Outdated

It's sightly suboptimal to open a file as part of tooltip drawing. On a slow network driver this could lead to a noticeable delay in display the tooltip when quickly scanning across multiple files quickly.

It's sightly suboptimal to open a file as part of tooltip drawing. On a slow network driver this could lead to a noticeable delay in display the tooltip when quickly scanning across multiple files quickly.
/* Look for version in existing thumbnail if available. */
IMB_metadata_get_field(
@ -214,9 +220,10 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData
}
}
else if (file->typeflag & FILE_TYPE_IMAGE) {
thumb = (file->attributes & FILE_ATTR_OFFLINE) ?
IMB_thumb_read(full_path, THB_LARGE) :
IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE);
if (!thumb) {
/* Load the thumbnail from cache if existing, create if not. */
thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_IMAGE);
}
if (thumb) {
char value1[128];
char value2[128];
@ -235,9 +242,9 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData
}
}
else if (file->typeflag & FILE_TYPE_MOVIE) {
thumb = (file->attributes & FILE_ATTR_OFFLINE) ?
IMB_thumb_read(full_path, THB_LARGE) :
IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE);
if (!thumb) {
thumb = IMB_thumb_manage(full_path, THB_LARGE, THB_SOURCE_MOVIE);
}
if (thumb) {
char value1[128];
char value2[128];
@ -320,7 +327,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, struct uiTooltipData
UI_tooltip_image_field_add(tip, thumb, size);
}
if (thumb) {
if (thumb && free_imbuf) {
IMB_freeImBuf(thumb);
}
}