UI: Horizontal list view for asset browser
Part of #134755 / #134766. The asset browser currently lacks a compact view that leaves names readable. Especially when managing asset libraries (e.g. to prepare it for sharing or set up a production library), this is quite a usability issue. A column view like the file browser has can solve this, allowing a quick overview and fast browsing of libraries, while keeping names readable. Adds a new "Horizontal List" display mode to the asset browser that distributes assets over multiple columns, with horizontal scrolling. Asset previews are shown in this mode, plus an asset type icon if there's enough space. The size of previews and the columns can be configured next to the display mode, for optimizing the display. Pull Request: https://projects.blender.org/blender/blender/pulls/135306
This commit is contained in:
committed by
Julian Eisel
parent
0ebce03d41
commit
4499fad40e
@@ -607,14 +607,19 @@ class ASSETBROWSER_PT_display(asset_utils.AssetBrowserPanel, Panel):
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False # No animation.
|
||||
|
||||
if params.display_type == 'THUMBNAIL':
|
||||
layout.prop(params, "display_size", text="Size")
|
||||
else:
|
||||
col = layout.column(heading="Columns", align=True)
|
||||
col.prop(params, "show_details_size", text="Size")
|
||||
col.prop(params, "show_details_datetime", text="Date")
|
||||
col = layout.column()
|
||||
col.prop(params, "display_type", expand=True)
|
||||
|
||||
layout.column().prop(params, "sort_method", text="Sort By", expand=True)
|
||||
if params.display_type == 'THUMBNAIL':
|
||||
col.prop(params, "display_size", text="Size")
|
||||
else:
|
||||
col.prop(params, "list_display_size", text="Preview Size")
|
||||
if params.display_type == 'LIST_HORIZONTAL':
|
||||
col.prop(params, "list_column_size", text="Column Size")
|
||||
|
||||
col.separator()
|
||||
|
||||
col.prop(params, "sort_method", text="Sort By", expand=True)
|
||||
|
||||
|
||||
class ASSETBROWSER_PT_filter(asset_utils.AssetBrowserPanel, Panel):
|
||||
|
||||
@@ -3864,6 +3864,37 @@ static void version_sequencer_update_overdrop(Main *bmain)
|
||||
}
|
||||
}
|
||||
|
||||
static void asset_browser_add_list_view(Main *bmain)
|
||||
{
|
||||
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
||||
if (sl->spacetype != SPACE_FILE) {
|
||||
continue;
|
||||
}
|
||||
SpaceFile *sfile = reinterpret_cast<SpaceFile *>(sl);
|
||||
if (sfile->params) {
|
||||
if (sfile->params->list_thumbnail_size == 0) {
|
||||
sfile->params->list_thumbnail_size = 16;
|
||||
}
|
||||
if (sfile->params->list_column_size == 0) {
|
||||
sfile->params->list_column_size = 500;
|
||||
}
|
||||
}
|
||||
if (sfile->asset_params) {
|
||||
if (sfile->asset_params->base_params.list_thumbnail_size == 0) {
|
||||
sfile->asset_params->base_params.list_thumbnail_size = 32;
|
||||
}
|
||||
if (sfile->asset_params->base_params.list_column_size == 0) {
|
||||
sfile->asset_params->base_params.list_column_size = 220;
|
||||
}
|
||||
sfile->asset_params->base_params.details_flags = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
{
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 1)) {
|
||||
@@ -6004,6 +6035,8 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
rename_mesh_uv_seam_attribute(*mesh);
|
||||
}
|
||||
|
||||
asset_browser_add_list_view(bmain);
|
||||
|
||||
/**
|
||||
* Always bump subversion in BKE_blender_version.h when adding versioning
|
||||
* code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check.
|
||||
|
||||
@@ -338,6 +338,8 @@ enum {
|
||||
UI_BUT_HAS_TOOLTIP_LABEL = 1 << 5,
|
||||
/** Do not add the usual horizontal padding for text drawing. */
|
||||
UI_BUT_NO_TEXT_PADDING = 1 << 6,
|
||||
/** Do not add the usual padding around preview image drawing, use the size of the button. */
|
||||
UI_BUT_NO_PREVIEW_PADDING = 1 << 7,
|
||||
|
||||
/* Button align flag, for drawing groups together.
|
||||
* Used in 'uiBlock.flag', take care! */
|
||||
@@ -1360,6 +1362,18 @@ uiBut *uiDefIconButO_ptr(uiBlock *block,
|
||||
short width,
|
||||
short height,
|
||||
std::optional<blender::StringRef> tip);
|
||||
uiBut *uiDefIconPreviewBut(uiBlock *block,
|
||||
int type,
|
||||
int retval,
|
||||
int icon,
|
||||
int x,
|
||||
int y,
|
||||
short width,
|
||||
short height,
|
||||
void *poin,
|
||||
float min,
|
||||
float max,
|
||||
std::optional<blender::StringRef> tip);
|
||||
uiBut *uiDefButImage(
|
||||
uiBlock *block, void *imbuf, int x, int y, short width, short height, const uchar color[4]);
|
||||
uiBut *uiDefButAlert(uiBlock *block, int icon, int x, int y, short width, short height);
|
||||
|
||||
@@ -5532,6 +5532,31 @@ uiBut *uiDefIconBut(uiBlock *block,
|
||||
ui_but_update_and_icon_set(but, icon);
|
||||
return but;
|
||||
}
|
||||
uiBut *uiDefIconPreviewBut(uiBlock *block,
|
||||
int type,
|
||||
int retval,
|
||||
int icon,
|
||||
int x,
|
||||
int y,
|
||||
short width,
|
||||
short height,
|
||||
void *poin,
|
||||
float min,
|
||||
float max,
|
||||
const std::optional<StringRef> tip)
|
||||
{
|
||||
uiBut *but = ui_def_but(block, type, retval, "", x, y, width, height, poin, min, max, tip);
|
||||
if (icon) {
|
||||
ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
|
||||
|
||||
/* Use the exact button size for the preview. Or do we need to let the caller control this? */
|
||||
but->drawflag |= UI_BUT_NO_PREVIEW_PADDING;
|
||||
but->drawflag &= ~UI_BUT_ICON_LEFT;
|
||||
}
|
||||
|
||||
ui_but_update(but);
|
||||
return but;
|
||||
}
|
||||
static uiBut *uiDefIconButBit(uiBlock *block,
|
||||
int type,
|
||||
int bit,
|
||||
|
||||
@@ -1337,7 +1337,8 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
|
||||
blender::StringRef name,
|
||||
int iconid,
|
||||
const uchar text_col[4],
|
||||
eFontStyle_Align text_align);
|
||||
eFontStyle_Align text_align,
|
||||
const bool add_padding);
|
||||
|
||||
#define UI_TEXT_MARGIN_X 0.4f
|
||||
#define UI_POPUP_MARGIN (UI_SCALE_FAC * 12)
|
||||
|
||||
@@ -165,7 +165,7 @@ int ui_but_icon(const uiBut *but)
|
||||
const bool is_preview = (but->flag & UI_BUT_ICON_PREVIEW) != 0;
|
||||
|
||||
/* While icon is loading, show loading icon at the normal icon size. */
|
||||
if (is_preview && ui_icon_is_preview_deferred_loading(but->icon, true)) {
|
||||
if (ui_icon_is_preview_deferred_loading(but->icon, is_preview)) {
|
||||
return ICON_PREVIEW_LOADING;
|
||||
}
|
||||
|
||||
|
||||
@@ -1258,8 +1258,12 @@ static void widget_draw_icon_centered(const BIFIconID icon,
|
||||
* multiplied by #UI_INV_SCALE_FAC).
|
||||
* \param mono_color: Only for drawing monochrome icons.
|
||||
*/
|
||||
static void widget_draw_preview_icon(
|
||||
BIFIconID icon, float alpha, float aspect, const rcti *rect, const uchar mono_color[4])
|
||||
static void widget_draw_preview_icon(BIFIconID icon,
|
||||
float alpha,
|
||||
float aspect,
|
||||
const bool add_padding,
|
||||
const rcti *rect,
|
||||
const uchar mono_color[4])
|
||||
{
|
||||
if (icon == ICON_NONE) {
|
||||
return;
|
||||
@@ -1272,7 +1276,7 @@ static void widget_draw_preview_icon(
|
||||
|
||||
const int w = BLI_rcti_size_x(rect);
|
||||
const int h = BLI_rcti_size_y(rect);
|
||||
const int size = std::min(w, h) - PREVIEW_PAD * 2;
|
||||
const int size = std::min(w, h) - (add_padding ? (PREVIEW_PAD * 2) : 0);
|
||||
|
||||
if (size > 0) {
|
||||
const int x = rect->xmin + w / 2 - size / 2;
|
||||
@@ -1294,7 +1298,12 @@ static void widget_draw_icon(
|
||||
{
|
||||
if (but->flag & UI_BUT_ICON_PREVIEW) {
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
widget_draw_preview_icon(icon, alpha, but->block->aspect, rect, mono_color);
|
||||
widget_draw_preview_icon(icon,
|
||||
alpha,
|
||||
but->block->aspect,
|
||||
!(but->drawflag & UI_BUT_NO_PREVIEW_PADDING),
|
||||
rect,
|
||||
mono_color);
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
return;
|
||||
}
|
||||
@@ -1365,7 +1374,8 @@ static void widget_draw_icon(
|
||||
/* Get theme color. */
|
||||
uchar color[4] = {mono_color[0], mono_color[1], mono_color[2], mono_color[3]};
|
||||
const bTheme *btheme = UI_GetTheme();
|
||||
const bool has_theme = UI_icon_get_theme_color(int(icon), color);
|
||||
/* Only use theme colors if the button doesn't override the color. */
|
||||
const bool has_theme = !but->col[3] && UI_icon_get_theme_color(int(icon), color);
|
||||
const bool outline = btheme->tui.icon_border_intensity > 0.0f && has_theme;
|
||||
|
||||
/* to indicate draggable */
|
||||
@@ -2288,7 +2298,12 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
|
||||
/* draw icon in rect above the space reserved for the label */
|
||||
rect->ymin += text_size;
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
widget_draw_preview_icon(icon, alpha, but->block->aspect, rect, icon_color);
|
||||
widget_draw_preview_icon(icon,
|
||||
alpha,
|
||||
but->block->aspect,
|
||||
!(but->drawflag & UI_BUT_NO_PREVIEW_PADDING),
|
||||
rect,
|
||||
icon_color);
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
|
||||
/* offset rect to draw label in */
|
||||
@@ -4268,8 +4283,13 @@ static void widget_preview_tile(uiBut *but,
|
||||
}
|
||||
|
||||
const BIFIconID icon = ui_but_icon(but);
|
||||
ui_draw_preview_item_stateless(
|
||||
&UI_style_get()->widget, rect, but->drawstr, icon, wcol->text, UI_STYLE_TEXT_CENTER);
|
||||
ui_draw_preview_item_stateless(&UI_style_get()->widget,
|
||||
rect,
|
||||
but->drawstr,
|
||||
icon,
|
||||
wcol->text,
|
||||
UI_STYLE_TEXT_CENTER,
|
||||
!(but->drawflag & UI_BUT_NO_PREVIEW_PADDING));
|
||||
}
|
||||
|
||||
static void widget_optionbut(uiWidgetColors *wcol,
|
||||
@@ -5657,7 +5677,8 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
|
||||
const blender::StringRef name,
|
||||
int iconid,
|
||||
const uchar text_col[4],
|
||||
eFontStyle_Align text_align)
|
||||
eFontStyle_Align text_align,
|
||||
const bool add_padding)
|
||||
{
|
||||
rcti trect = *rect;
|
||||
const float text_size = UI_UNIT_Y;
|
||||
@@ -5670,7 +5691,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
|
||||
rect->ymin += text_size;
|
||||
}
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
widget_draw_preview_icon(iconid, alpha, 1.0f, rect, text_col);
|
||||
widget_draw_preview_icon(iconid, alpha, 1.0f, add_padding, rect, text_col);
|
||||
GPU_blend(GPU_BLEND_NONE);
|
||||
|
||||
if (!has_text) {
|
||||
@@ -5679,9 +5700,11 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
|
||||
|
||||
/* text rect */
|
||||
trect.ymax = trect.ymin + text_size;
|
||||
trect.ymin += PREVIEW_PAD;
|
||||
trect.xmin += PREVIEW_PAD;
|
||||
trect.xmax -= PREVIEW_PAD;
|
||||
if (add_padding) {
|
||||
trect.ymin += PREVIEW_PAD;
|
||||
trect.xmin += PREVIEW_PAD;
|
||||
trect.xmax -= PREVIEW_PAD;
|
||||
}
|
||||
|
||||
{
|
||||
char drawstr[UI_MAX_DRAW_STR];
|
||||
@@ -5715,7 +5738,7 @@ void ui_draw_preview_item(const uiFontStyle *fstyle,
|
||||
wt->state(wt, &state, UI_EMBOSS_UNDEFINED);
|
||||
wt->draw(&wt->wcol, rect, &STATE_INFO_NULL, 0, 1.0f);
|
||||
|
||||
ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align);
|
||||
ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align, true);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -387,6 +387,17 @@ static void file_but_enable_drag(uiBut *but,
|
||||
}
|
||||
}
|
||||
|
||||
static void file_but_tooltip_func_set(const SpaceFile *sfile, const FileDirEntry *file, uiBut *but)
|
||||
{
|
||||
if (file->asset) {
|
||||
UI_but_func_tooltip_custom_set(but, file_draw_asset_tooltip_custom_func, file->asset, nullptr);
|
||||
}
|
||||
else {
|
||||
UI_but_func_tooltip_custom_set(
|
||||
but, file_draw_tooltip_custom_func, file_tooltip_data_create(sfile, file), MEM_freeN);
|
||||
}
|
||||
}
|
||||
|
||||
static uiBut *file_add_icon_but(const SpaceFile *sfile,
|
||||
uiBlock *block,
|
||||
const char * /*path*/,
|
||||
@@ -401,21 +412,56 @@ static uiBut *file_add_icon_but(const SpaceFile *sfile,
|
||||
uiBut *but;
|
||||
|
||||
const int x = tile_draw_rect->xmin + padx;
|
||||
const int y = tile_draw_rect->ymax - sfile->layout->tile_border_y - height;
|
||||
const int y = tile_draw_rect->ymax - sfile->layout->tile_border_y -
|
||||
round_fl_to_int((sfile->layout->tile_h + height) / 2.0f);
|
||||
|
||||
/* Small built-in icon. Draw centered in given width. */
|
||||
but = uiDefIconBut(
|
||||
block, UI_BTYPE_LABEL, 0, icon, x, y, width, height, nullptr, 0.0f, 0.0f, std::nullopt);
|
||||
/* Center the icon. */
|
||||
UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT);
|
||||
UI_but_label_alpha_factor_set(but, dimmed ? 0.3f : 1.0f);
|
||||
if (file->asset) {
|
||||
UI_but_func_tooltip_custom_set(but, file_draw_asset_tooltip_custom_func, file->asset, nullptr);
|
||||
if (icon < BIFICONID_LAST_STATIC) {
|
||||
/* Small built-in icon. Draw centered in given width. */
|
||||
but = uiDefIconBut(block,
|
||||
UI_BTYPE_LABEL,
|
||||
0,
|
||||
icon,
|
||||
x,
|
||||
y + 1,
|
||||
width,
|
||||
height,
|
||||
nullptr,
|
||||
0.0f,
|
||||
0.0f,
|
||||
std::nullopt);
|
||||
/* Center the icon. */
|
||||
UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT);
|
||||
}
|
||||
else {
|
||||
UI_but_func_tooltip_custom_set(
|
||||
but, file_draw_tooltip_custom_func, file_tooltip_data_create(sfile, file), MEM_freeN);
|
||||
/* Larger preview icon. Fills available width/height. */
|
||||
but = uiDefIconPreviewBut(
|
||||
block, UI_BTYPE_LABEL, 0, icon, x, y, width, height, nullptr, 0.0f, 0.0f, std::nullopt);
|
||||
}
|
||||
UI_but_label_alpha_factor_set(but, dimmed ? 0.3f : 1.0f);
|
||||
file_but_tooltip_func_set(sfile, file, but);
|
||||
|
||||
return but;
|
||||
}
|
||||
|
||||
static uiBut *file_add_overlay_icon_but(uiBlock *block, int pos_x, int pos_y, int icon)
|
||||
{
|
||||
uiBut *but = uiDefIconBut(block,
|
||||
UI_BTYPE_LABEL,
|
||||
0,
|
||||
icon,
|
||||
pos_x,
|
||||
pos_y,
|
||||
ICON_DEFAULT_WIDTH_SCALE,
|
||||
ICON_DEFAULT_HEIGHT_SCALE,
|
||||
nullptr,
|
||||
0.0f,
|
||||
0.0f,
|
||||
std::nullopt);
|
||||
/* Otherwise a left hand padding will be added. */
|
||||
UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT);
|
||||
UI_but_label_alpha_factor_set(but, 0.6f);
|
||||
const uchar light[4] = {255, 255, 255, 255};
|
||||
UI_but_color_set(but, light);
|
||||
|
||||
return but;
|
||||
}
|
||||
@@ -584,14 +630,7 @@ static void file_add_preview_drag_but(const SpaceFile *sfile,
|
||||
const auto [scaled_width, scaled_height, scale] = preview_image_scaled_dimensions_get(
|
||||
drag_image->x, drag_image->y, *layout);
|
||||
file_but_enable_drag(but, sfile, file, path, drag_image, file_type_icon, scale);
|
||||
|
||||
if (file->asset) {
|
||||
UI_but_func_tooltip_custom_set(but, file_draw_asset_tooltip_custom_func, file->asset, nullptr);
|
||||
}
|
||||
else {
|
||||
UI_but_func_tooltip_custom_set(
|
||||
but, file_draw_tooltip_custom_func, file_tooltip_data_create(sfile, file), MEM_freeN);
|
||||
}
|
||||
file_but_tooltip_func_set(sfile, file, but);
|
||||
}
|
||||
|
||||
static void file_draw_preview(const FileDirEntry *file,
|
||||
@@ -1316,9 +1355,20 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
}
|
||||
}
|
||||
else {
|
||||
const int icon = filelist_geticon_file_type(files, i, true);
|
||||
const bool filelist_loading = !filelist_is_ready(files);
|
||||
const BIFIconID icon = [&]() {
|
||||
if (file->asset) {
|
||||
file->asset->ensure_previewable();
|
||||
|
||||
icon_ofs += ICON_DEFAULT_WIDTH_SCALE + 2 * padx;
|
||||
if (filelist_loading) {
|
||||
return BIFIconID(ICON_PREVIEW_LOADING);
|
||||
}
|
||||
return blender::ed::asset::asset_preview_or_icon(*file->asset);
|
||||
}
|
||||
return filelist_geticon_file_type(files, i, true);
|
||||
}();
|
||||
|
||||
icon_ofs += layout->prv_w + 2 * padx;
|
||||
|
||||
/* Add dummy draggable button covering the icon and the label. */
|
||||
if (do_drag) {
|
||||
@@ -1341,10 +1391,7 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
std::nullopt);
|
||||
UI_but_dragflag_enable(drag_but, UI_BUT_DRAG_FULL_BUT);
|
||||
file_but_enable_drag(drag_but, sfile, file, path, nullptr, icon, UI_SCALE_FAC);
|
||||
UI_but_func_tooltip_custom_set(drag_but,
|
||||
file_draw_tooltip_custom_func,
|
||||
file_tooltip_data_create(sfile, file),
|
||||
MEM_freeN);
|
||||
file_but_tooltip_func_set(sfile, file, drag_but);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1355,8 +1402,8 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
file,
|
||||
&tile_draw_rect,
|
||||
icon,
|
||||
ICON_DEFAULT_WIDTH_SCALE,
|
||||
ICON_DEFAULT_HEIGHT_SCALE,
|
||||
layout->prv_w,
|
||||
layout->prv_h,
|
||||
padx,
|
||||
is_hidden);
|
||||
if (do_drag) {
|
||||
@@ -1364,6 +1411,14 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
* enable dragging, even though the dummy drag button above covers the same area. */
|
||||
file_but_enable_drag(icon_but, sfile, file, path, nullptr, icon, UI_SCALE_FAC);
|
||||
}
|
||||
|
||||
if (layout->prv_w >= round_fl_to_int(ICON_DEFAULT_WIDTH_SCALE * 2) &&
|
||||
(filelist_loading || icon >= BIFICONID_LAST_STATIC))
|
||||
{
|
||||
const BIFIconID type_icon = filelist_geticon_file_type(files, i, true);
|
||||
file_add_overlay_icon_but(
|
||||
block, tile_draw_rect.xmin + padx - 2, tile_draw_rect.ymin - 1, type_icon);
|
||||
}
|
||||
}
|
||||
|
||||
if (file_selflag & FILE_SEL_EDITING) {
|
||||
@@ -1377,7 +1432,8 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
1,
|
||||
"",
|
||||
tile_draw_rect.xmin + icon_ofs,
|
||||
tile_draw_rect.ymin + layout->tile_border_y - 0.15f * UI_UNIT_X,
|
||||
tile_draw_rect.ymin + layout->tile_border_y +
|
||||
((layout->tile_h - textheight) / 2.0f) - 0.15f * UI_UNIT_X,
|
||||
width - icon_ofs,
|
||||
textheight,
|
||||
params->renamefile,
|
||||
@@ -1414,7 +1470,9 @@ void file_draw_list(const bContext *C, ARegion *region)
|
||||
const int twidth = (params->display == FILE_IMGDISPLAY) ?
|
||||
column_width :
|
||||
column_width - 1 - icon_ofs - padx - layout->tile_border_x;
|
||||
file_draw_string(txpos, typos, file->name, float(twidth), textheight, align, text_col);
|
||||
const int theight = (params->display == FILE_IMGDISPLAY) ? textheight : layout->tile_h;
|
||||
|
||||
file_draw_string(txpos, typos, file->name, float(twidth), theight, align, text_col);
|
||||
}
|
||||
|
||||
if (params->display != FILE_IMGDISPLAY) {
|
||||
|
||||
@@ -67,8 +67,6 @@
|
||||
#include "file_intern.hh"
|
||||
#include "filelist.hh"
|
||||
|
||||
#define VERTLIST_MAJORCOLUMN_WIDTH (25 * UI_UNIT_X)
|
||||
|
||||
static void fileselect_initialize_params_common(SpaceFile *sfile, FileSelectParams *params)
|
||||
{
|
||||
const char *blendfile_path = BKE_main_blendfile_path_from_global();
|
||||
@@ -122,11 +120,15 @@ static void fileselect_ensure_updated_asset_params(SpaceFile *sfile)
|
||||
base_params->filter_id = FILTER_ID_ALL;
|
||||
base_params->display = FILE_IMGDISPLAY;
|
||||
base_params->sort = FILE_SORT_ASSET_CATALOG;
|
||||
/* No details columns supported for assets (wouldn't contain anything), disable them all. */
|
||||
base_params->details_flags = 0;
|
||||
/* Asset libraries include all sub-directories, so enable maximal recursion. */
|
||||
base_params->recursion_level = FILE_SELECT_MAX_RECURSIONS;
|
||||
/* 'SMALL' size by default. More reasonable since this is typically used as regular editor,
|
||||
* space is more of an issue here. */
|
||||
base_params->thumbnail_size = 96;
|
||||
base_params->list_thumbnail_size = 32;
|
||||
base_params->list_column_size = 220;
|
||||
|
||||
fileselect_initialize_params_common(sfile, base_params);
|
||||
}
|
||||
@@ -158,6 +160,8 @@ static FileSelectParams *fileselect_ensure_updated_file_params(SpaceFile *sfile)
|
||||
sfile->params->thumbnail_size = U_default.file_space_data.thumbnail_size;
|
||||
sfile->params->details_flags = U_default.file_space_data.details_flags;
|
||||
sfile->params->filter_id = U_default.file_space_data.filter_id;
|
||||
sfile->params->list_thumbnail_size = 16;
|
||||
sfile->params->list_column_size = 500;
|
||||
}
|
||||
|
||||
params = sfile->params;
|
||||
@@ -987,9 +991,15 @@ static void file_attribute_columns_widths(const FileSelectParams *params, FileLa
|
||||
}
|
||||
|
||||
/* Biggest possible reasonable values... */
|
||||
columns[COLUMN_DATETIME].width = file_string_width(compact ? "23/08/89" : "23 Dec 6789, 23:59") +
|
||||
pad;
|
||||
columns[COLUMN_SIZE].width = file_string_width(compact ? "369G" : "098.7 MiB") + pad;
|
||||
if (file_attribute_column_type_enabled(params, COLUMN_DATETIME, layout)) {
|
||||
columns[COLUMN_DATETIME].width = file_string_width(compact ? "23/08/89" :
|
||||
"23 Dec 6789, 23:59") +
|
||||
pad;
|
||||
}
|
||||
if (file_attribute_column_type_enabled(params, COLUMN_SIZE, layout)) {
|
||||
columns[COLUMN_SIZE].width = file_string_width(compact ? "369G" : "098.7 MiB") + pad;
|
||||
}
|
||||
|
||||
if (params->display == FILE_IMGDISPLAY) {
|
||||
columns[COLUMN_NAME].width = (float(params->thumbnail_size) / 8.0f) * UI_UNIT_X;
|
||||
}
|
||||
@@ -1033,8 +1043,6 @@ static void file_attribute_columns_init(const FileSelectParams *params, FileLayo
|
||||
void ED_fileselect_init_layout(SpaceFile *sfile, ARegion *region)
|
||||
{
|
||||
FileSelectParams *params = ED_fileselect_get_active_params(sfile);
|
||||
/* Request a slightly more compact layout for asset browsing. */
|
||||
const bool compact = ED_fileselect_is_asset_browser(sfile);
|
||||
FileLayout *layout = nullptr;
|
||||
View2D *v2d = ®ion->v2d;
|
||||
int numfiles;
|
||||
@@ -1054,7 +1062,8 @@ void ED_fileselect_init_layout(SpaceFile *sfile, ARegion *region)
|
||||
layout->textheight = textheight;
|
||||
|
||||
if (params->display == FILE_IMGDISPLAY) {
|
||||
const float pad_fac = compact ? 0.15f : 0.3f;
|
||||
/* More compact spacing for asset browser. */
|
||||
const float pad_fac = ED_fileselect_is_asset_browser(sfile) ? 0.15f : 0.3f;
|
||||
/* Matches UI_preview_tile_size_x()/_y() by default. */
|
||||
layout->prv_w = (float(params->thumbnail_size) / 20.0f) * UI_UNIT_X;
|
||||
layout->prv_h = (float(params->thumbnail_size) / 20.0f) * UI_UNIT_Y;
|
||||
@@ -1082,9 +1091,8 @@ void ED_fileselect_init_layout(SpaceFile *sfile, ARegion *region)
|
||||
else if (params->display == FILE_VERTICALDISPLAY) {
|
||||
int rowcount;
|
||||
|
||||
/* Matches UI_preview_tile_size_x()/_y() by default. */
|
||||
layout->prv_w = (float(params->thumbnail_size) / 20.0f) * UI_UNIT_X;
|
||||
layout->prv_h = (float(params->thumbnail_size) / 20.0f) * UI_UNIT_Y;
|
||||
layout->prv_w = ICON_DEFAULT_WIDTH_SCALE;
|
||||
layout->prv_h = ICON_DEFAULT_HEIGHT_SCALE;
|
||||
layout->tile_border_x = 0.4f * UI_UNIT_X;
|
||||
layout->tile_border_y = 0.1f * UI_UNIT_Y;
|
||||
layout->tile_h = textheight * 3 / 2;
|
||||
@@ -1106,19 +1114,19 @@ void ED_fileselect_init_layout(SpaceFile *sfile, ARegion *region)
|
||||
layout->flag = FILE_LAYOUT_VER;
|
||||
}
|
||||
else if (params->display == FILE_HORIZONTALDISPLAY) {
|
||||
/* Matches UI_preview_tile_size_x()/_y() by default. */
|
||||
layout->prv_w = (float(params->thumbnail_size) / 20.0f) * UI_UNIT_X;
|
||||
layout->prv_h = (float(params->thumbnail_size) / 20.0f) * UI_UNIT_Y;
|
||||
layout->prv_w = params->list_thumbnail_size * UI_SCALE_FAC;
|
||||
layout->prv_h = params->list_thumbnail_size * UI_SCALE_FAC;
|
||||
layout->tile_border_x = 0.4f * UI_UNIT_X;
|
||||
layout->tile_border_y = 0.1f * UI_UNIT_Y;
|
||||
layout->tile_h = textheight * 3 / 2;
|
||||
layout->tile_h = std::max(textheight * 3 / 2, layout->prv_h);
|
||||
layout->attribute_column_header_h = 0;
|
||||
layout->offset_top = layout->attribute_column_header_h;
|
||||
layout->height = int(BLI_rctf_size_y(&v2d->cur) - 2 * layout->tile_border_y);
|
||||
/* Padding by full scroll-bar H is too much, can overlap tile border Y. */
|
||||
layout->rows = (layout->height - V2D_SCROLL_HEIGHT + layout->tile_border_y) /
|
||||
(layout->tile_h + 2 * layout->tile_border_y);
|
||||
layout->tile_w = VERTLIST_MAJORCOLUMN_WIDTH;
|
||||
|
||||
layout->tile_w = params->list_column_size * UI_SCALE_FAC;
|
||||
file_attribute_columns_init(params, layout);
|
||||
|
||||
if (layout->rows > 0) {
|
||||
@@ -1128,8 +1136,10 @@ void ED_fileselect_init_layout(SpaceFile *sfile, ARegion *region)
|
||||
layout->rows = 1;
|
||||
layout->flow_columns = numfiles;
|
||||
}
|
||||
layout->width = sfile->layout->flow_columns * (layout->tile_w + 2 * layout->tile_border_x) +
|
||||
layout->tile_border_x * 2;
|
||||
layout->width = (numfiles > 0) ? (sfile->layout->flow_columns *
|
||||
(layout->tile_w + 2 * layout->tile_border_x) +
|
||||
layout->tile_border_x * 2) :
|
||||
int(BLI_rctf_size_x(&v2d->cur) - 2 * layout->tile_border_x);
|
||||
layout->flag = FILE_LAYOUT_HOR;
|
||||
}
|
||||
layout->dirty = false;
|
||||
|
||||
@@ -831,7 +831,8 @@ typedef struct FileSelectParams {
|
||||
int sel_first;
|
||||
int sel_last;
|
||||
unsigned short thumbnail_size;
|
||||
char _pad1[2];
|
||||
unsigned short list_thumbnail_size;
|
||||
unsigned short list_column_size;
|
||||
|
||||
/* short */
|
||||
/** XXX: for now store type here, should be moved to the operator. */
|
||||
@@ -844,7 +845,7 @@ typedef struct FileSelectParams {
|
||||
short display;
|
||||
/** Details toggles (file size, creation date, etc.) */
|
||||
char details_flags;
|
||||
char _pad2[3];
|
||||
char _pad1;
|
||||
|
||||
/** Filter when (flags & FILE_FILTER) is true. */
|
||||
int filter;
|
||||
@@ -852,7 +853,7 @@ typedef struct FileSelectParams {
|
||||
/** Max number of levels in directory tree to show at once, 0 to disable recursion. */
|
||||
short recursion_level;
|
||||
|
||||
char _pad4[2];
|
||||
char _pad2[2];
|
||||
} FileSelectParams;
|
||||
|
||||
/**
|
||||
|
||||
@@ -511,6 +511,21 @@ static const EnumPropertyItem fileselectparams_recursion_level_items[] = {
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem fileselectparams_display_type_items[] = {
|
||||
{FILE_VERTICALDISPLAY,
|
||||
"LIST_VERTICAL",
|
||||
ICON_LONGDISPLAY,
|
||||
"Vertical List",
|
||||
"Display files as a vertical list"},
|
||||
{FILE_HORIZONTALDISPLAY,
|
||||
"LIST_HORIZONTAL",
|
||||
ICON_SHORTDISPLAY,
|
||||
"Horizontal List",
|
||||
"Display files as a horizontal list"},
|
||||
{FILE_IMGDISPLAY, "THUMBNAIL", ICON_IMGDISPLAY, "Thumbnails", "Display files as thumbnails"},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem rna_enum_curve_display_handle_items[] = {
|
||||
{CURVE_HANDLE_NONE, "NONE", 0, "None", ""},
|
||||
{CURVE_HANDLE_SELECTED, "SELECTED", 0, "Selected", ""},
|
||||
@@ -2887,6 +2902,31 @@ static bool rna_FileSelectParams_use_lib_get(PointerRNA *ptr)
|
||||
return params && (params->type == FILE_LOADLIB);
|
||||
}
|
||||
|
||||
static const EnumPropertyItem *rna_FileSelectParams_display_type_itemf(bContext * /*C*/,
|
||||
PointerRNA *ptr,
|
||||
PropertyRNA * /*prop*/,
|
||||
bool *r_free)
|
||||
{
|
||||
if (RNA_struct_is_a(ptr->type, &RNA_FileAssetSelectParams)) {
|
||||
EnumPropertyItem *items = nullptr;
|
||||
int totitem = 0;
|
||||
|
||||
/* Only expose preview and column view for asset browsing. */
|
||||
RNA_enum_items_add_value(
|
||||
&items, &totitem, fileselectparams_display_type_items, FILE_HORIZONTALDISPLAY);
|
||||
RNA_enum_items_add_value(
|
||||
&items, &totitem, fileselectparams_display_type_items, FILE_IMGDISPLAY);
|
||||
|
||||
RNA_enum_item_end(&items, &totitem);
|
||||
*r_free = true;
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
*r_free = false;
|
||||
return fileselectparams_display_type_items;
|
||||
}
|
||||
|
||||
static const EnumPropertyItem *rna_FileSelectParams_recursion_level_itemf(bContext * /*C*/,
|
||||
PointerRNA *ptr,
|
||||
PropertyRNA * /*prop*/,
|
||||
@@ -7048,21 +7088,6 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
static const EnumPropertyItem file_display_items[] = {
|
||||
{FILE_VERTICALDISPLAY,
|
||||
"LIST_VERTICAL",
|
||||
ICON_LONGDISPLAY,
|
||||
"Vertical List",
|
||||
"Display files as a vertical list"},
|
||||
{FILE_HORIZONTALDISPLAY,
|
||||
"LIST_HORIZONTAL",
|
||||
ICON_SHORTDISPLAY,
|
||||
"Horizontal List",
|
||||
"Display files as a horizontal list"},
|
||||
{FILE_IMGDISPLAY, "THUMBNAIL", ICON_IMGDISPLAY, "Thumbnails", "Display files as thumbnails"},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem display_size_items[] = {
|
||||
{32, "TINY", 0, "Tiny", ""},
|
||||
{64, "SMALL", 0, "Small", ""},
|
||||
@@ -7103,7 +7128,8 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
|
||||
|
||||
prop = RNA_def_property(srna, "display_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, nullptr, "display");
|
||||
RNA_def_property_enum_items(prop, file_display_items);
|
||||
RNA_def_property_enum_items(prop, fileselectparams_display_type_items);
|
||||
RNA_def_property_enum_funcs(prop, nullptr, nullptr, "rna_FileSelectParams_display_type_itemf");
|
||||
RNA_def_property_ui_text(prop, "Display Mode", "Display mode for the file list");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, nullptr);
|
||||
|
||||
@@ -7262,6 +7288,21 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Display Size", "Change the size of thumbnails in discrete steps");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_LIST, nullptr);
|
||||
|
||||
prop = RNA_def_property(srna, "list_display_size", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_int_sdna(prop, nullptr, "list_thumbnail_size");
|
||||
RNA_def_property_ui_text(prop, "Display Size", "Change the size of thumbnails in list views");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_LIST, nullptr);
|
||||
RNA_def_property_int_default(prop, 32);
|
||||
RNA_def_property_range(prop, 16, 128);
|
||||
RNA_def_property_ui_range(prop, 16, 128, 1, 0);
|
||||
|
||||
prop = RNA_def_property(srna, "list_column_size", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_ui_text(prop, "Columns Size", "The width of columns in horizontal list views");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_LIST, nullptr);
|
||||
RNA_def_property_int_default(prop, 32);
|
||||
RNA_def_property_range(prop, 32, 750);
|
||||
RNA_def_property_ui_range(prop, 32, 750, 1, 0);
|
||||
}
|
||||
|
||||
static void rna_def_fileselect_asset_params(BlenderRNA *brna)
|
||||
|
||||
Reference in New Issue
Block a user