From e435ecc6f367a2d0f7159bd3c7c0f1aca8dbb982 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 29 Aug 2018 03:03:32 +0200 Subject: menuconfig: Add a _center_vertically() helper Used in two spots. --- menuconfig.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/menuconfig.py b/menuconfig.py index 7e1160b..3ebf44e 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -750,8 +750,7 @@ def _jump_to(node): _shown = _shown_nodes(_cur_menu) _sel_node_i = _shown.index(node) - # Center the jumped-to node vertically, if possible - _menu_scroll = max(_sel_node_i - _menu_win_height()//2, 0) + _center_vertically() def _leave_menu(): # Jumps to the parent menu of the current menu. Does nothing if we're in @@ -780,8 +779,8 @@ def _leave_menu(): _menu_scroll = max(_sel_node_i - screen_row, 0) else: # No saved parent menu locations, meaning we jumped directly to some - # node earlier. Just center the node vertically if possible. - _menu_scroll = max(_sel_node_i - _menu_win_height()//2, 0) + # node earlier + _center_vertically() def _select_next_menu_entry(): # Selects the menu entry after the current one, adjusting the scroll if @@ -881,6 +880,13 @@ def _toggle_show_all(): # might be impossible if too many nodes have disappeared above the node. _menu_scroll = max(_sel_node_i - old_row, 0) +def _center_vertically(): + # Centers the selected node vertically, if possible + + global _menu_scroll + + _menu_scroll = max(_sel_node_i - _menu_win_height()//2, 0) + def _draw_main(): # Draws the "main" display, with the list of symbols, the header, and the # footer. -- cgit v1.2.3