diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-04 22:09:57 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-09-04 22:38:33 +0300 |
commit | 36e23c95e8f341883fdb5e0933e9430b9f7bdb41 (patch) | |
tree | dcc711f6108f5db67121f8ae9be3f7f4e22a706f /source/blender/blenlib | |
parent | e52ad1835a6aaefab389b173728b9bb7ef2e754a (diff) |
Python API: add methods for reordering constraints.
Order matters for constraints, but there was no way to change it.
The API follows other collections like idprops and node sockets.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index b8b62dd3451..b027acb88da 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -93,6 +93,7 @@ void BLI_listbase_sort_r(ListBase *listbase, int (*cmp)(void *, const void *, const void *), void *thunk) ATTR_NONNULL(1, 2); bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL(); +bool BLI_listbase_move_index(ListBase *listbase, int from, int to) ATTR_NONNULL(); void BLI_freelist(struct ListBase *listbase) ATTR_NONNULL(1); int BLI_listbase_count_at_most(const struct ListBase *listbase, const int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 31d372945c6..631978f60fe 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -504,6 +504,27 @@ bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) } /** + * Move the link at the index \a from to the position at index \a to. + * + * @return If the move was successful. + */ +bool BLI_listbase_move_index(ListBase *listbase, int from, int to) +{ + if (from == to) { + return false; + } + + /* Find the link to move. */ + void *link = BLI_findlink(listbase, from); + + if (!link) { + return false; + } + + return BLI_listbase_link_move(listbase, link, to - from); +} + +/** * Removes and disposes of the entire contents of listbase using direct free(3). */ void BLI_freelist(ListBase *listbase) |