blob: 82f81f1702be42f8a47f2e6c13b92b32f244bf78 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup editorui
*
* Base for all views (UIs to display data sets), supporting common features.
* https://wiki.blender.org/wiki/Source/Interface/Views
*
* One of the most important responsibilities of the base class is managing reconstruction,
* enabling state that is persistent over reconstructions/redraws.
*/
#pragma once
#include <array>
#include <memory>
#include "BLI_span.hh"
struct wmNotifier;
namespace blender::ui {
class AbstractView {
bool is_reconstructed_ = false;
/**
* Only one item can be renamed at a time. So rather than giving each item an own rename buffer
* (which just adds unused memory in most cases), have one here that is managed by the view.
*
* This fixed-size buffer is needed because that's what the rename button requires. In future we
* may be able to bind the button to a `std::string` or similar.
*/
std::unique_ptr<std::array<char, MAX_NAME>> rename_buffer_;
public:
virtual ~AbstractView() = default;
/** Listen to a notifier, returning true if a redraw is needed. */
virtual bool listen(const wmNotifier &) const;
/** Only one item can be renamed at a time. */
bool is_renaming() const;
/** \return If renaming was started successfully. */
bool begin_renaming();
void end_renaming();
Span<char> get_rename_buffer() const;
MutableSpan<char> get_rename_buffer();
protected:
AbstractView() = default;
virtual void update_children_from_old(const AbstractView &old_view) = 0;
/**
* Match the view and its items against an earlier version of itself (if any) and copy the old UI
* state (e.g. collapsed, active, selected, renaming, etc.) to the new one. See
* #AbstractViewItem.update_from_old().
* After this, reconstruction is complete (see #is_reconstructed()).
*/
void update_from_old(uiBlock &new_block);
/**
* Check if the view is fully (re-)constructed. That means, both the build function and
* #update_from_old() have finished.
*/
bool is_reconstructed() const;
};
} // namespace blender::ui
|