diff options
Diffstat (limited to 'source/blender/editors/include/UI_grid_view.hh')
-rw-r--r-- | source/blender/editors/include/UI_grid_view.hh | 55 |
1 files changed, 10 insertions, 45 deletions
diff --git a/source/blender/editors/include/UI_grid_view.hh b/source/blender/editors/include/UI_grid_view.hh index 6f553f4fad1..402c0c8512f 100644 --- a/source/blender/editors/include/UI_grid_view.hh +++ b/source/blender/editors/include/UI_grid_view.hh @@ -13,12 +13,13 @@ #include "BLI_map.hh" #include "BLI_vector.hh" +#include "UI_abstract_view.hh" #include "UI_resources.h" struct bContext; struct PreviewImage; struct uiBlock; -struct uiButGridTile; +struct uiButViewItem; struct uiLayout; struct View2D; struct wmNotifier; @@ -31,43 +32,29 @@ class AbstractGridView; /** \name Grid-View Item Type * \{ */ -class AbstractGridViewItem { +class AbstractGridViewItem : public AbstractViewItem { friend class AbstractGridView; friend class GridViewLayoutBuilder; - const AbstractGridView *view_; - - bool is_active_ = false; - protected: /** Reference to a string that uniquely identifies this item in the view. */ StringRef identifier_{}; - /** Every visible item gets a button of type #UI_BTYPE_GRID_TILE during the layout building. */ - uiButGridTile *grid_tile_but_ = nullptr; + /** Every visible item gets a button of type #UI_BTYPE_VIEW_ITEM during the layout building. */ + uiButViewItem *view_item_but_ = nullptr; public: virtual ~AbstractGridViewItem() = default; virtual void build_grid_tile(uiLayout &layout) const = 0; - /** - * Compare this item's identifier to \a other to check if they represent the same data. - * Used to recognize an item from a previous redraw, to be able to keep its state (e.g. active, - * renaming, etc.). - */ - bool matches(const AbstractGridViewItem &other) const; - const AbstractGridView &get_view() const; - /** - * Requires the tree to have completed reconstruction, see #is_reconstructed(). Otherwise we - * can't be sure about the item state. - */ - bool is_active() const; - protected: AbstractGridViewItem(StringRef identifier); + /** See AbstractViewItem::matches(). */ + virtual bool matches(const AbstractViewItem &other) const override; + /** Called when the item's state changes from inactive to active. */ virtual void on_activate(); /** @@ -77,13 +64,6 @@ class AbstractGridViewItem { virtual std::optional<bool> should_be_active() const; /** - * Copy persistent state (e.g. active, selection, etc.) from a matching item of - * the last redraw to this item. If sub-classes introduce more advanced state they should - * override this and make it update their state accordingly. - */ - virtual void update_from_old(const AbstractGridViewItem &old); - - /** * Activates this item, deactivates other items, and calls the * #AbstractGridViewItem::on_activate() function. * Requires the tree to have completed reconstruction, see #is_reconstructed(). Otherwise the @@ -111,7 +91,7 @@ struct GridViewStyle { int tile_height = 0; }; -class AbstractGridView { +class AbstractGridView : public AbstractView { friend class AbstractGridViewItem; friend class GridViewBuilder; friend class GridViewLayoutBuilder; @@ -122,7 +102,6 @@ class AbstractGridView { * #update_from_old(). */ Map<StringRef, AbstractGridViewItem *> item_map_; GridViewStyle style_; - bool is_reconstructed_ = false; public: AbstractGridView(); @@ -131,9 +110,6 @@ class AbstractGridView { using ItemIterFn = FunctionRef<void(AbstractGridViewItem &)>; void foreach_item(ItemIterFn iter_fn) const; - /** Listen to a notifier, returning true if a redraw is needed. */ - virtual bool listen(const wmNotifier &) const; - /** * Convenience wrapper constructing the item by forwarding given arguments to the constructor of * the type (\a ItemT). @@ -154,19 +130,8 @@ class AbstractGridView { protected: virtual void build_items() = 0; - /** - * Check if the view is fully (re-)constructed. That means, both #build_items() and - * #update_from_old() have finished. - */ - bool is_reconstructed() const; - private: - /** - * Match the grid-view against an earlier version of itself (if any) and copy the old UI state - * (e.g. active, selected, renaming, etc.) to the new one. See - * #AbstractGridViewItem.update_from_old(). - */ - void update_from_old(uiBlock &new_block); + void update_children_from_old(const AbstractView &old_view) override; AbstractGridViewItem *find_matching_item(const AbstractGridViewItem &item_to_match, const AbstractGridView &view_to_search_in) const; /** |