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
path: root/source
diff options
context:
space:
mode:
authorNathan Craddock <nzcraddock@gmail.com>2021-07-12 19:45:24 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-07-15 17:12:36 +0300
commit8edcb3af963113e37490288876419e8f50d4f1e8 (patch)
tree7c84fdd1921698036fc53dce12568c93d2e8191e /source
parentae1dc8f5f98d045b11312401d6f93d0eae15ddc5 (diff)
UI: Support left-right arrow key walk navigation in UI lists
Add improved arrow key walk navigation in grid layout UI List templates. Pressing up or down walks the active item to the adjacent row in that direction, while left and right walk through the items along the columns wrapping at the rows. Note from Julian: In combination with the following commit, this has the important limitation that the list's custom activate operator won't be called when "walking over" an item that is scrolled out of the list. That is because we don't actually create any buttons for those that could be used for the handling logic. For our purposes of the pose libraries that should be fine since the asset view list is always made big enough to display all items. Solving this might be difficult, we don't properly support nesting boxes with proper scrolling in regular layouts. It's all just hacked a bit for UI-lists to work. Overlaps quite a bit with T86149. Differential Revision: https://developer.blender.org/D11063
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/interface_handlers.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 14fd9025c8f..2f03539873f 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -9469,6 +9469,27 @@ static void ui_list_activate_row_from_index(
ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM;
}
+static int ui_list_get_increment(const uiList *ui_list, const int type, const int columns)
+{
+ int increment = 0;
+
+ /* Handle column offsets for grid layouts. */
+ if (ELEM(type, EVT_UPARROWKEY, EVT_DOWNARROWKEY) &&
+ ELEM(ui_list->layout_type, UILST_LAYOUT_GRID, UILST_LAYOUT_BIG_PREVIEW_GRID)) {
+ increment = (type == EVT_UPARROWKEY) ? -columns : columns;
+ }
+ else {
+ /* Left or right in grid layouts or any direction in single column layouts increments by 1. */
+ increment = ELEM(type, EVT_UPARROWKEY, EVT_LEFTARROWKEY, WHEELUPMOUSE) ? -1 : 1;
+ }
+
+ if ((ui_list->filter_sort_flag & UILST_FLT_SORT_REVERSE) != 0) {
+ increment *= -1;
+ }
+
+ return increment;
+}
+
static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *region, uiBut *listbox)
{
int retval = WM_UI_HANDLER_CONTINUE;
@@ -9506,21 +9527,15 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi
retval = ui_list_handle_click_drag(C, ui_list, region, event);
}
else if (val == KM_PRESS) {
- if ((ELEM(type, EVT_UPARROWKEY, EVT_DOWNARROWKEY) &&
+ if ((ELEM(type, EVT_UPARROWKEY, EVT_DOWNARROWKEY, EVT_LEFTARROWKEY, EVT_RIGHTARROWKEY) &&
!IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) ||
((ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->ctrl &&
!IS_EVENT_MOD(event, shift, alt, oskey)))) {
const int value_orig = RNA_property_int_get(&listbox->rnapoin, listbox->rnaprop);
- int value, min, max, inc;
+ int value, min, max;
- /* activate up/down the list */
value = value_orig;
- if ((ui_list->filter_sort_flag & UILST_FLT_SORT_REVERSE) != 0) {
- inc = ELEM(type, EVT_UPARROWKEY, WHEELUPMOUSE) ? 1 : -1;
- }
- else {
- inc = ELEM(type, EVT_UPARROWKEY, WHEELUPMOUSE) ? -1 : 1;
- }
+ const int inc = ui_list_get_increment(ui_list, type, dyn_data->columns);
if (dyn_data->items_filter_neworder || dyn_data->items_filter_flags) {
/* If we have a display order different from