[Bf-blender-cvs] [3df2e4e8886] asset-browser-grid-view: Display a basic list of assets, set up scrolling and notifier listening
Julian Eisel
noreply at git.blender.org
Thu Feb 3 15:39:29 CET 2022
Commit: 3df2e4e888648166905737658d89fcfeff60dcf4
Author: Julian Eisel
Date: Thu Feb 3 15:30:55 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rB3df2e4e888648166905737658d89fcfeff60dcf4
Display a basic list of assets, set up scrolling and notifier listening
* Display a non-interactive list of assets, updates as assets get
loaded.
* Notifier listening happens via the view, so the grid-view supports
listening to notifiers. This is what triggers regular redraws as
assets get loaded.
* Scrolling may need more fine tuning, so that scroll-bars are
hidden if they don't apply (e.g. don't show horizontal scroll-bar for
the vertically expanding grid-view layout).
===================================================================
A source/blender/editors/include/UI_grid_view.hh
M source/blender/editors/include/UI_interface.h
M source/blender/editors/include/UI_interface.hh
M source/blender/editors/interface/CMakeLists.txt
A source/blender/editors/interface/grid_view.cc
M source/blender/editors/interface/interface_view.cc
M source/blender/editors/screen/area.c
M source/blender/editors/space_assets/asset_browser_draw.cc
M source/blender/editors/space_assets/asset_view.cc
M source/blender/editors/space_assets/asset_view.hh
M source/blender/editors/space_assets/space_assets.cc
M source/blender/editors/util/CMakeLists.txt
===================================================================
diff --git a/source/blender/editors/space_assets/asset_view.hh b/source/blender/editors/include/UI_grid_view.hh
similarity index 56%
copy from source/blender/editors/space_assets/asset_view.hh
copy to source/blender/editors/include/UI_grid_view.hh
index 80ae99f2884..945c9444db7 100644
--- a/source/blender/editors/space_assets/asset_view.hh
+++ b/source/blender/editors/include/UI_grid_view.hh
@@ -15,28 +15,35 @@
*/
/** \file
- * \ingroup spassets
+ * \ingroup editorui
+ *
+ * API for simple creation of grid UIs, supporting typically needed features.
+ * https://wiki.blender.org/wiki/Source/Interface/Views/Grid_Views
*/
#pragma once
-struct bContext;
-struct AssetLibraryReference;
-struct uiLayout;
-
-namespace blender::ed::asset_browser {
+struct wmNotifier;
-class AssetGridView {
- AssetLibraryReference asset_library_ref_;
+namespace blender::ui {
+class AbstractGridViewItem {
public:
- AssetGridView(const AssetLibraryReference &);
+ virtual ~AbstractGridViewItem() = default;
- void build();
+ protected:
+ AbstractGridViewItem() = default;
};
-void asset_view_create_in_layout(const bContext &C,
- const AssetLibraryReference &asset_library_ref,
- uiLayout &layout);
+class AbstractGridView {
+ public:
+ virtual ~AbstractGridView() = default;
+
+ /** Listen to a notifier, returning true if a redraw is needed. */
+ virtual bool listen(const wmNotifier &) const;
+
+ // protected:
+ virtual void build() = 0;
+};
-} // namespace blender::ed::asset_browser
+} // namespace blender::ui
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index ae4c2ff16fd..cdc7eb25b4c 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -80,6 +80,7 @@ struct wmKeyMapItem;
struct wmMsgBus;
struct wmOperator;
struct wmOperatorType;
+struct wmRegionListenerParams;
struct wmWindow;
typedef struct uiBlock uiBlock;
@@ -91,6 +92,8 @@ typedef struct uiPopupBlockHandle uiPopupBlockHandle;
typedef struct uiTreeViewHandle uiTreeViewHandle;
/* C handle for C++ #ui::AbstractTreeViewItem type. */
typedef struct uiTreeViewItemHandle uiTreeViewItemHandle;
+/* C handle for C++ #ui::AbstractGridView type. */
+typedef struct uiGridViewHandle uiGridViewHandle;
/* Defines */
@@ -3163,6 +3166,9 @@ void UI_interface_tag_script_reload(void);
/* Support click-drag motion which presses the button and closes a popover (like a menu). */
#define USE_UI_POPOVER_ONCE
+void UI_block_views_listen(const uiBlock *block,
+ const struct wmRegionListenerParams *listener_params);
+
bool UI_tree_view_item_is_active(const uiTreeViewItemHandle *item);
bool UI_tree_view_item_matches(const uiTreeViewItemHandle *a, const uiTreeViewItemHandle *b);
/**
@@ -3201,6 +3207,11 @@ uiTreeViewItemHandle *UI_block_tree_view_find_item_at(const struct ARegion *regi
const int xy[2]) ATTR_NONNULL(1, 2);
uiTreeViewItemHandle *UI_block_tree_view_find_active_item(const struct ARegion *region);
+/**
+ * Listen to \a notifier, returning true if the region should redraw.
+ */
+bool UI_grid_view_listen_should_redraw(const uiGridViewHandle *view, const wmNotifier *notifier);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/include/UI_interface.hh b/source/blender/editors/include/UI_interface.hh
index 8d1ca54b7a1..37858adafae 100644
--- a/source/blender/editors/include/UI_interface.hh
+++ b/source/blender/editors/include/UI_interface.hh
@@ -37,6 +37,7 @@ struct uiSearchItems;
namespace blender::ui {
+class AbstractGridView;
class AbstractTreeView;
/**
@@ -69,6 +70,10 @@ void attribute_search_add_items(
/**
* Override this for all available tree types.
*/
+blender::ui::AbstractGridView *UI_block_add_view(
+ uiBlock &block,
+ blender::StringRef idname,
+ std::unique_ptr<blender::ui::AbstractGridView> tree_view);
blender::ui::AbstractTreeView *UI_block_add_view(
uiBlock &block,
blender::StringRef idname,
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 95c9f7cc8b2..db7d53e2e0d 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -38,6 +38,7 @@ set(INC
)
set(SRC
+ grid_view.cc
interface.c
interface_align.c
interface_anim.c
diff --git a/source/blender/editors/space_assets/asset_view.hh b/source/blender/editors/interface/grid_view.cc
similarity index 51%
copy from source/blender/editors/space_assets/asset_view.hh
copy to source/blender/editors/interface/grid_view.cc
index 80ae99f2884..5315bd1447e 100644
--- a/source/blender/editors/space_assets/asset_view.hh
+++ b/source/blender/editors/interface/grid_view.cc
@@ -15,28 +15,34 @@
*/
/** \file
- * \ingroup spassets
+ * \ingroup edinterface
*/
-#pragma once
+#include "WM_types.h"
-struct bContext;
-struct AssetLibraryReference;
-struct uiLayout;
+#include "UI_interface.h"
-namespace blender::ed::asset_browser {
+#include "UI_grid_view.hh"
-class AssetGridView {
- AssetLibraryReference asset_library_ref_;
+namespace blender::ui {
- public:
- AssetGridView(const AssetLibraryReference &);
+/* ---------------------------------------------------------------------- */
- void build();
-};
+bool AbstractGridView::listen(const wmNotifier &) const
+{
+ /* Nothing by default. */
+ return false;
+}
-void asset_view_create_in_layout(const bContext &C,
- const AssetLibraryReference &asset_library_ref,
- uiLayout &layout);
+} // namespace blender::ui
-} // namespace blender::ed::asset_browser
+using namespace blender::ui;
+
+/* ---------------------------------------------------------------------- */
+
+bool UI_grid_view_listen_should_redraw(const uiGridViewHandle *view_handle,
+ const wmNotifier *notifier)
+{
+ const AbstractGridView &view = *reinterpret_cast<const AbstractGridView *>(view_handle);
+ return view.listen(*notifier);
+}
diff --git a/source/blender/editors/interface/interface_view.cc b/source/blender/editors/interface/interface_view.cc
index 81b24c75020..96b9d974ae7 100644
--- a/source/blender/editors/interface/interface_view.cc
+++ b/source/blender/editors/interface/interface_view.cc
@@ -24,15 +24,22 @@
*/
#include <memory>
+#include <type_traits>
#include <variant>
#include "DNA_screen_types.h"
+#include "BKE_screen.h"
+
#include "BLI_listbase.h"
+#include "ED_screen.h"
+
#include "interface_intern.h"
#include "UI_interface.hh"
+
+#include "UI_grid_view.hh"
#include "UI_tree_view.hh"
using namespace blender;
@@ -44,10 +51,11 @@ using namespace blender::ui;
*/
struct ViewLink : public Link {
using TreeViewPtr = std::unique_ptr<AbstractTreeView>;
+ using GridViewPtr = std::unique_ptr<AbstractGridView>;
std::string idname;
/* NOTE: Can't use std::get() on this until minimum macOS deployment target is 10.14. */
- std::variant<TreeViewPtr> view;
+ std::variant<TreeViewPtr, GridViewPtr> view;
};
template<class T> T *get_view_from_link(ViewLink &link)
@@ -56,17 +64,32 @@ template<class T> T *get_view_from_link(ViewLink &link)
return t_uptr ? t_uptr->get() : nullptr;
}
-AbstractTreeView *UI_block_add_view(uiBlock &block,
- StringRef idname,
- std::unique_ptr<AbstractTreeView> tree_view)
+template<class T>
+static T *ui_block_add_view_impl(uiBlock &block, StringRef idname, std::unique_ptr<T> view)
{
+ static_assert(std::is_same_v<T, AbstractTreeView> || std::is_same_v<T, AbstractGridView>,
+ "Unsupported view type");
ViewLink *view_link = MEM_new<ViewLink>(__func__);
BLI_addtail(&block.views, view_link);
- view_link->view = std::move(tree_view);
+ view_link->view = std::move(view);
view_link->idname = idname;
- return get_view_from_link<AbstractTreeView>(*view_link);
+ return get_view_from_link<T>(*view_link);
+}
+
+AbstractGridView *UI_block_add_view(uiBlock &block,
+ StringRef idname,
+ std::unique_ptr<AbstractGridView> tree_view)
+{
+ return ui_block_add_view_impl<AbstractGridView>(block, idname, std::move(tree_view));
+}
+
+AbstractTreeView *UI_block_add_view(uiBlock &block,
+ StringRef idname,
+ std::unique_ptr<AbstractTreeView> tree_view)
+{
+ return ui_block_add_view_impl<AbstractTreeView>(block, idname, std::move(tree_view));
}
void ui_block_free_views(uiBlock *block)
@@ -76,6 +99,19 @@ void ui_block_free_views(uiBlock *block)
}
}
+void UI_block_views_listen(const uiBlock *block, const wmRegionListenerParams *listener_params)
+{
+ LISTBASE_FOREACH (ViewLink *, view_link, &block->views) {
+ /* TODO only grid views, should this be supported by all views? */
+ if (AbstractGridView *grid_view = get_view_from_link<AbstractGridView>(*view_link)) {
+ if (UI_grid_view_listen_should_redraw(reinterpret_cast<uiGridViewHandle *>(grid_view),
+ listener_params->notifier)) {
+ ED_region_tag_redraw(listener_params->region);
+ }
+ }
+ }
+}
+
uiTreeViewItemHandle *UI_block_tree_view_find_item_at(const ARegion *region, const int xy[2])
{
uiButTreeRow *tree_row_but = (uiButTreeRow *)ui_tree_row_find_mouse_over(region, xy);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index c6834c84794..b98ea274d07 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -161,6 +161,10 @@ void ED_region_do_listen(wmRegionListenerParams *params)
region->type->listener(params);
}
+ LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) {
+ UI_block_views_listen(block, params);
+ }
+
LISTBASE_FOREACH (uiList *, list, ®ion->ui_lists) {
if (list->type && list->type->listener) {
list->type->listener(list, par
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list