UI: Asset Shelf (Experimental Feature) #104831
|
@ -23,13 +23,14 @@ struct wmWindowManager;
|
|||
/* Asset Shelf Regions */
|
||||
|
||||
/** Only needed for #RGN_TYPE_ASSET_SHELF (not #RGN_TYPE_ASSET_SHELF_FOOTER). */
|
||||
void ED_asset_shelf_region_init(ARegion *region);
|
||||
int ED_asset_shelf_region_snap(const ARegion *region, int size, int axis);
|
||||
void ED_asset_shelf_region_init(struct wmWindowManager *wm, struct ARegion *region);
|
||||
int ED_asset_shelf_region_snap(const struct ARegion *region, int size, int axis);
|
||||
void ED_asset_shelf_region_listen(const struct wmRegionListenerParams *params);
|
||||
void ED_asset_shelf_region_draw(const bContext *C,
|
||||
struct ARegion *region,
|
||||
struct AssetShelfSettings *shelf_settings);
|
||||
int ED_asset_shelf_region_default_tile_height(void);
|
||||
int ED_asset_shelf_default_tile_width(void);
|
||||
int ED_asset_shelf_default_tile_height(void);
|
||||
int ED_asset_shelf_region_prefsizey(void);
|
||||
|
||||
void ED_asset_shelf_footer_region_init(struct wmWindowManager *wm, struct ARegion *region);
|
||||
|
|
|
@ -80,14 +80,9 @@ void ED_asset_shelf_region_listen(const wmRegionListenerParams *params)
|
|||
}
|
||||
}
|
||||
|
||||
void ED_asset_shelf_region_init(ARegion *region)
|
||||
void ED_asset_shelf_region_init(wmWindowManager *wm, ARegion *region)
|
||||
{
|
||||
View2D &v2d = region->v2d;
|
||||
|
||||
UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_LIST, region->winx, region->winy);
|
||||
/* Only allow scrolling in vertical direction. */
|
||||
v2d.scroll = V2D_SCROLL_RIGHT;
|
||||
v2d.keepofs = V2D_LOCKOFS_X;
|
||||
ED_region_panels_init(wm, region);
|
||||
}
|
||||
|
||||
static constexpr int main_region_padding_y_not_scaled()
|
||||
|
@ -114,30 +109,33 @@ int ED_asset_shelf_region_snap(const ARegion *region, const int size, const int
|
|||
|
||||
const int size_scaled = size * UI_SCALE_FAC;
|
||||
|
||||
/* Using X axis avoids slight feedback loop when adjusting Y. */
|
||||
const float aspect = BLI_rctf_size_x(®ion->v2d.cur) /
|
||||
(BLI_rcti_size_x(®ion->v2d.mask) + 1);
|
||||
const float tile_size = ED_asset_shelf_region_default_tile_height() / aspect;
|
||||
const float tile_height = ED_asset_shelf_default_tile_height() *
|
||||
UI_view2d_scale_get_y(®ion->v2d);
|
||||
const int region_padding = main_region_padding_y_scaled();
|
||||
|
||||
/* How many rows fit into the region (accounting for padding). */
|
||||
const int rows = std::max(1, int((size_scaled - 2 * region_padding) / tile_size));
|
||||
const int rows = std::max(1, int((size_scaled - 2 * region_padding) / tile_height));
|
||||
|
||||
const int new_size_scaled = (rows * tile_size + 2 * region_padding);
|
||||
const int new_size_scaled = (rows * tile_height + 2 * region_padding);
|
||||
return new_size_scaled / UI_SCALE_FAC;
|
||||
}
|
||||
|
||||
int ED_asset_shelf_region_default_tile_height()
|
||||
int ED_asset_shelf_default_tile_width()
|
||||
{
|
||||
return UI_preview_tile_size_x() * 0.8f;
|
||||
}
|
||||
|
||||
int ED_asset_shelf_default_tile_height()
|
||||
{
|
||||
return UI_preview_tile_size_y() * 0.8f;
|
||||
}
|
||||
|
||||
int ED_asset_shelf_region_prefsizey()
|
||||
{
|
||||
/* Can't account for DPI here since this is expected to be called on region type initialization
|
||||
* at startup, when #U isn't available yet. */
|
||||
|
||||
return ED_asset_shelf_region_default_tile_height() + 2 * main_region_padding_y_not_scaled();
|
||||
return ED_asset_shelf_default_tile_width() + 2 * main_region_padding_y_not_scaled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,12 +175,13 @@ void ED_asset_shelf_region_draw(const bContext *C,
|
|||
const uiStyle *style = UI_style_get();
|
||||
const float padding_y = main_region_padding_y_scaled();
|
||||
const float padding_x = main_region_padding_x_scaled();
|
||||
const float scale_x = UI_view2d_scale_get_x(®ion->v2d);
|
||||
uiLayout *layout = UI_block_layout(block,
|
||||
UI_LAYOUT_VERTICAL,
|
||||
UI_LAYOUT_PANEL,
|
||||
padding_x,
|
||||
-padding_y,
|
||||
region->winx - 2 * padding_x,
|
||||
(region->winx - 2 * padding_x) / scale_x,
|
||||
1,
|
||||
0,
|
||||
style);
|
||||
|
|
|
@ -185,13 +185,12 @@ void build_asset_view(uiLayout &layout,
|
|||
return;
|
||||
}
|
||||
|
||||
/* TODO deduplicate from #ED_asset_shelf_region_snap() */
|
||||
const float aspect = BLI_rctf_size_x(®ion.v2d.cur) / (BLI_rcti_size_x(®ion.v2d.mask) + 1);
|
||||
const float tile_size = ED_asset_shelf_region_default_tile_height() / aspect;
|
||||
const float tile_width = ED_asset_shelf_default_tile_width();
|
||||
const float tile_height = ED_asset_shelf_default_tile_height();
|
||||
|
||||
std::unique_ptr asset_view = std::make_unique<AssetView>(library_ref, const_cast<bContext &>(C));
|
||||
asset_view->set_catalog_filter(catalog_filter_from_shelf_settings(shelf_settings, *library));
|
||||
asset_view->set_tile_size(tile_size, tile_size);
|
||||
asset_view->set_tile_size(tile_width, tile_height);
|
||||
|
||||
uiBlock *block = uiLayoutGetBlock(&layout);
|
||||
ui::AbstractGridView *grid_view = UI_block_add_view(
|
||||
JulianEisel marked this conversation as resolved
Outdated
|
||||
|
|
|
@ -1306,7 +1306,10 @@ static void region_rect_recursive(
|
|||
}
|
||||
}
|
||||
|
||||
if (const int snap_flags = ED_region_snap_size_test(region)) {
|
||||
if (region->flag & RGN_FLAG_HIDDEN) {
|
||||
/* Pass. */
|
||||
}
|
||||
else if (const int snap_flags = ED_region_snap_size_test(region)) {
|
||||
/* Apply snapping, which updates #ARegion.sizex/sizey values. */
|
||||
ED_region_snap_size_apply(region, snap_flags);
|
||||
}
|
||||
|
|
|
@ -1928,7 +1928,7 @@ static void view3d_asset_shelf_region_init(wmWindowManager *wm, ARegion *region)
|
|||
wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
|
||||
WM_event_add_keymap_handler(®ion->handlers, keymap);
|
||||
|
||||
ED_asset_shelf_region_init(region);
|
||||
ED_asset_shelf_region_init(wm, region);
|
||||
}
|
||||
|
||||
/* area (not region) level listener */
|
||||
|
@ -2256,8 +2256,7 @@ void ED_spacetype_view3d()
|
|||
art = MEM_cnew<ARegionType>("spacetype view3d asset shelf region");
|
||||
art->regionid = RGN_TYPE_ASSET_SHELF;
|
||||
art->prefsizey = ED_asset_shelf_region_prefsizey();
|
||||
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES |
|
||||
ED_KEYMAP_HEADER;
|
||||
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_ASSET_SHELF | ED_KEYMAP_FRAMES;
|
||||
art->listener = ED_asset_shelf_region_listen;
|
||||
art->snap_size = ED_asset_shelf_region_snap;
|
||||
art->context = view3d_asset_shelf_context;
|
||||
|
|
Loading…
Reference in New Issue
If the dynamic_cast isn't meant to fail in some cases, it's probably better to use
static_cast
to avoid bloating the code with dynamic casting.Also, class methods should generally be accessed with
this->
Not a fan of using
static_cast
for down casting. It removes type safety for virtually (pun intended) no benefit. Sure it's unlikely to cause issues here, but if it does it's good to get an exception thrown. There's a language feature designed for this, so I rather use it.https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-dynamic_cast
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c147-use-dynamic_cast-to-a-reference-type-when-failure-to-find-the-required-class-is-considered-an-error
Hard to argue with the code guidelines I guess.. Still though, I'd find it clearer to use
static_cast
, sincedynamic_cast
gives the impression that the author thinks the cast might fail. But using a reference for the variable negates that impression, making the whole thing confusing. Not a big deal though