[Bf-blender-cvs] [f7490543e94] temp-asset-browser-poselib-merge: UI: Support left-right arrow key walk navigation in UI lists

Nathan Craddock noreply at git.blender.org
Wed Jul 14 22:53:10 CEST 2021


Commit: f7490543e94bc95a2dad1ba8922878965646c1ff
Author: Nathan Craddock
Date:   Mon Jul 12 18:45:24 2021 +0200
Branches: temp-asset-browser-poselib-merge
https://developer.blender.org/rBf7490543e94bc95a2dad1ba8922878965646c1ff

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

===================================================================

M	source/blender/editors/interface/interface_handlers.c

===================================================================

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index f619e7ca08e..3e164457036 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



More information about the Bf-blender-cvs mailing list