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-04-26 23:26:15 +0300
committerJulian Eisel <julian@blender.org>2022-04-26 23:26:15 +0300
commit83c8f996f1618a51496100dc680a877a89be7a4e (patch)
treed4592e88ad598c18084489940fcc79c5a3fa4bcc /source/blender/editors/include
parent5fe1624b0eba8267325f166de8e75c4d2dd6989b (diff)
UI: Add callback for comparing button identity
The code to compare buttons from the previous to the current frame, to see if they match (an thus should keep the same state) was quite generic, and didn't allow much flexibility/customization. For some cases this isn't enough, and a more specific comparison is needed. Say if some buttons don't actually store comparable data themselves, only via the button context. This was the case in D14653.
Diffstat (limited to 'source/blender/editors/include')
-rw-r--r--source/blender/editors/include/UI_interface.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 94453ef5fac..1b817d06564 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -508,6 +508,10 @@ typedef void (*uiButHandleNFunc)(struct bContext *C, void *argN, void *arg2);
typedef void (*uiButHandleHoldFunc)(struct bContext *C, struct ARegion *butregion, uiBut *but);
typedef int (*uiButCompleteFunc)(struct bContext *C, char *str, void *arg);
+/** Function to compare the identity of two buttons over redraws, to check if they represent the
+ * same data, and thus should be considered the same button over redraws. */
+typedef bool (*uiButIdentityCompareFunc)(const uiBut *a, const uiBut *b);
+
/* Search types. */
typedef struct ARegion *(*uiButSearchCreateFn)(struct bContext *C,
struct ARegion *butregion,
@@ -1650,6 +1654,18 @@ eAutoPropButsReturn uiDefAutoButsRNA(uiLayout *layout,
bool compact);
/**
+ * Callback to compare the identity of two buttons, used to identify buttons over redraws. If the
+ * callback returns true, the given buttons are considered to be matching and relevant state is
+ * preserved (copied from the old to the new button). If it returns false, it's considered
+ * non-matching and no further checks are done.
+ *
+ * If this is set, it is always executed instead of the default comparisons. However it is only
+ * executed for buttons that have the same type and the same callback. So callbacks can assume the
+ * button types match.
+ */
+void UI_but_func_identity_compare_set(uiBut *but, uiButIdentityCompareFunc cmp_fn);
+
+/**
* Public function exported for functions that use #UI_BTYPE_SEARCH_MENU.
*
* Use inside searchfunc to add items.