From c822f16f1424954c9bb1bd4f242c3fb8ab3b45f1 Mon Sep 17 00:00:00 2001 From: Ksaper Date: Sun, 5 Feb 2023 15:45:13 +0200 Subject: [PATCH] Formatting --- widget/app_launcher/init.lua | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index cf21625..1fcd883 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -426,6 +426,43 @@ local function page_backward(self, direction) end end +local function scroll(self, dir) + if #self._private.grid.children < 1 then + self._private.active_widget = nil + return + end + + local pos = self._private.grid:get_widget_position(self._private.active_widget) + local can_scroll = false + local step_size = 0 + local if_cant_scroll_func = nil + + if dir == "up" then + can_scroll = self._private.grid:index(self._private.active_widget) > 1 + step_size = -1 + if_cant_scroll_func = function() page_backward(self, "up") end + elseif dir == "down" then + can_scroll = self._private.grid:index(self._private.active_widget) < #self._private.grid.children + step_size = 1 + if_cant_scroll_func = function() page_forward(self, "down") end + elseif dir == "left" then + can_scroll = self._private.grid:get_widgets_at(pos.row, pos.col - 1) ~= nil + step_size = -self.apps_per_row + if_cant_scroll_func = function() page_backward(self, "left") end + elseif dir == "right" then + can_scroll = self._private.grid:get_widgets_at(pos.row, pos.col + 1) ~= nil + step_size = self.apps_per_row + if_cant_scroll_func = function() page_forward(self, "right") end + end + + if can_scroll then + local app = gtable.cycle_value(self._private.grid.children, self._private.active_widget, step_size) + app:select() + else + if_cant_scroll_func() + end +end + local function reset(self) self._private.grid:reset() self._private.matched_entries = self._private.all_entries @@ -536,43 +573,6 @@ local function generate_apps(self) end end -local function scroll(self, dir) - if #self._private.grid.children < 1 then - self._private.active_widget = nil - return - end - - local pos = self._private.grid:get_widget_position(self._private.active_widget) - local can_scroll = false - local step_size = 0 - local if_cant_scroll_func = nil - - if dir == "up" then - can_scroll = self._private.grid:index(self._private.active_widget) > 1 - step_size = -1 - if_cant_scroll_func = function() page_backward(self, "up") end - elseif dir == "down" then - can_scroll = self._private.grid:index(self._private.active_widget) < #self._private.grid.children - step_size = 1 - if_cant_scroll_func = function() page_forward(self, "down") end - elseif dir == "left" then - can_scroll = self._private.grid:get_widgets_at(pos.row, pos.col - 1) ~= nil - step_size = -self.apps_per_row - if_cant_scroll_func = function() page_backward(self, "left") end - elseif dir == "right" then - can_scroll = self._private.grid:get_widgets_at(pos.row, pos.col + 1) ~= nil - step_size = self.apps_per_row - if_cant_scroll_func = function() page_forward(self, "right") end - end - - if can_scroll then - local app = gtable.cycle_value(self._private.grid.children, self._private.active_widget, step_size) - app:select() - else - if_cant_scroll_func() - end -end - --- Scrolls up function app_launcher:scroll_up() scroll(self, "up")