浏览代码

WindowServer: make menus wrap vertically

This commit adds vertical wrap to menus. The first item is focused if
Key_Down is pressed on the last item and the last item is focused if
Key_up is pressed on the first item.
Oliver Kraitschy 5 年之前
父节点
当前提交
5aa37f6f5c
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      Servers/WindowServer/WSMenu.cpp

+ 10 - 4
Servers/WindowServer/WSMenu.cpp

@@ -393,9 +393,12 @@ void WSMenu::event(CEvent& event)
                 return;
                 return;
 
 
             do {
             do {
-                if (m_hovered_item_index <= 0)
+                if (m_hovered_item_index == 0)
+                    m_hovered_item_index = m_items.size() - 1;
+                else if (m_hovered_item_index < 0)
                     return;
                     return;
-                --m_hovered_item_index;
+                else
+                    --m_hovered_item_index;
             } while (hovered_item()->type() == WSMenuItem::Separator);
             } while (hovered_item()->type() == WSMenuItem::Separator);
 
 
             if (is_scrollable() && m_hovered_item_index < m_scroll_offset)
             if (is_scrollable() && m_hovered_item_index < m_scroll_offset)
@@ -412,9 +415,12 @@ void WSMenu::event(CEvent& event)
                 return;
                 return;
 
 
             do {
             do {
-                if (m_hovered_item_index >= m_items.size() - 1)
+                if (m_hovered_item_index == m_items.size() - 1)
+                    m_hovered_item_index = 0;
+                else if (m_hovered_item_index > m_items.size() - 1)
                     return;
                     return;
-                ++m_hovered_item_index;
+                else
+                    ++m_hovered_item_index;
             } while (hovered_item()->type() == WSMenuItem::Separator);
             } while (hovered_item()->type() == WSMenuItem::Separator);
 
 
             if (is_scrollable() && m_hovered_item_index >= (m_scroll_offset + visible_item_count()))
             if (is_scrollable() && m_hovered_item_index >= (m_scroll_offset + visible_item_count()))