From b300def18cbe4776401720e2a205c3a8aa094a4e Mon Sep 17 00:00:00 2001 From: Ksaper Date: Sat, 25 Feb 2023 03:18:33 +0200 Subject: [PATCH] Formatting --- widget/app_launcher/init.lua | 76 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index 7e744cf..530e6c2 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -82,6 +82,44 @@ local function has_value(tab, val) return false end +local function scroll(self, dir) + if #self:get_grid().children < 1 then + self._private.active_widget = nil + return + end + + local pos = self:get_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:get_grid():index(self._private.active_widget) > 1 + step_size = -1 + if_cant_scroll_func = function() self:page_backward("up") end + elseif dir == "down" then + can_scroll = self:get_grid():index(self._private.active_widget) < #self:get_grid().children + step_size = 1 + if_cant_scroll_func = function() self:page_forward("down") end + elseif dir == "left" then + can_scroll = self:get_grid():get_widgets_at(pos.row, pos.col - 1) ~= nil + step_size = -self:get_grid().forced_num_rows + if_cant_scroll_func = function() self:page_backward("left") end + elseif dir == "right" then + can_scroll = self:get_grid():get_widgets_at(pos.row, pos.col + 1) ~= nil + step_size = self:get_grid().forced_num_cols + if_cant_scroll_func = function() self:page_forward("right") end + end + + if can_scroll then + local app = gtable.cycle_value(self:get_grid().children, self._private.active_widget, step_size) + app:select() + self:emit_signal("scroll", dir) + else + if_cant_scroll_func() + end +end + local function app_widget(self, app) local widget = nil @@ -229,44 +267,6 @@ local function app_widget(self, app) return widget end -local function scroll(self, dir) - if #self:get_grid().children < 1 then - self._private.active_widget = nil - return - end - - local pos = self:get_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:get_grid():index(self._private.active_widget) > 1 - step_size = -1 - if_cant_scroll_func = function() self:page_backward("up") end - elseif dir == "down" then - can_scroll = self:get_grid():index(self._private.active_widget) < #self:get_grid().children - step_size = 1 - if_cant_scroll_func = function() self:page_forward("down") end - elseif dir == "left" then - can_scroll = self:get_grid():get_widgets_at(pos.row, pos.col - 1) ~= nil - step_size = -self:get_grid().forced_num_rows - if_cant_scroll_func = function() self:page_backward("left") end - elseif dir == "right" then - can_scroll = self:get_grid():get_widgets_at(pos.row, pos.col + 1) ~= nil - step_size = self:get_grid().forced_num_cols - if_cant_scroll_func = function() self:page_forward("right") end - end - - if can_scroll then - local app = gtable.cycle_value(self:get_grid().children, self._private.active_widget, step_size) - app:select() - self:emit_signal("scroll", dir) - else - if_cant_scroll_func() - end -end - local function generate_apps(self) self._private.all_apps = {} self._private.matched_apps = {}