Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-07-02 22:49:21 +0300
committerJulian Eisel <julian@blender.org>2022-07-03 02:55:38 +0300
commitc355be6faeacef6a65afbce97f9776d2a2c7f54c (patch)
treee68bff81fa87b208ed433ade2b8fce7c522ed59a /source/blender/editors/interface/abstract_view.cc
parent4ffee9a48d1bc01442e554d44a1f55dfc459a221 (diff)
UI: Add AbstractView base class for views, unify reconstruction in there
No user visible changes expected. There's plenty of duplicated code in the grid and the tree view, and I expect this to become more. This starts the process of unifying these parts, which should also make it easier to add new views. Complexity in the view classes is reduced, and some type shenanigans for C compatibility and general view management can be removed, since there is now a common base type. For the start this ports some of the view reconstruction, where the view and its items are compared to the version of itself in the previous redraw, so that state (highlighted, active, renaming, collapsed, ...) can be preserved. Notifier listening is also ported.
Diffstat (limited to 'source/blender/editors/interface/abstract_view.cc')
-rw-r--r--source/blender/editors/interface/abstract_view.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/editors/interface/abstract_view.cc b/source/blender/editors/interface/abstract_view.cc
new file mode 100644
index 00000000000..542d82a56a3
--- /dev/null
+++ b/source/blender/editors/interface/abstract_view.cc
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup edinterface
+ */
+
+#include "interface_intern.h"
+
+#include "UI_abstract_view.hh"
+
+namespace blender::ui {
+
+/* ---------------------------------------------------------------------- */
+/** \name View Reconstruction
+ * \{ */
+
+bool AbstractView::is_reconstructed() const
+{
+ return is_reconstructed_;
+}
+
+void AbstractView::update_from_old(uiBlock &new_block)
+{
+ uiBlock *old_block = new_block.oldblock;
+ if (!old_block) {
+ is_reconstructed_ = true;
+ return;
+ }
+
+ const uiViewHandle *old_view_handle = ui_block_view_find_matching_in_old_block(
+ &new_block, reinterpret_cast<uiViewHandle *>(this));
+ if (old_view_handle == nullptr) {
+ /* Initial construction, nothing to update. */
+ is_reconstructed_ = true;
+ return;
+ }
+
+ update_children_from_old(reinterpret_cast<const AbstractView &>(*old_view_handle));
+
+ /* Finished (re-)constructing the tree. */
+ is_reconstructed_ = true;
+}
+
+/** \} */
+
+bool AbstractView::listen(const wmNotifier & /*notifier*/) const
+{
+ /* Nothing by default. */
+ return false;
+}
+
+} // namespace blender::ui