From de031915f3672e2e669467c9630f454976d80f22 Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sat, 1 Jun 2024 17:13:03 +0200 Subject: [PATCH] Fix touch method, window offset and return value --- .vscode/settings.json | 3 ++- tabview.lua | 38 ++++++++++++++++++++------------------ test.lua | 7 +++++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 778a635..fa3ad2a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "term", "colors", "fs", - "shell" + "shell", + "window" ] } \ No newline at end of file diff --git a/tabview.lua b/tabview.lua index f1c89ec..4975367 100644 --- a/tabview.lua +++ b/tabview.lua @@ -4,11 +4,11 @@ local allTabs = {} local tabOrder = {} local currentTab = nil -local function setTerm(new_term) - parent = new_term +local function setTerm(newTerm) + parent = newTerm end -local function addTab(tab, order_idx) +local function addTab(tab, orderIdx) assert(tab.name, "tab needs a unique name") local isCurrentTab = currentTab == nil if isCurrentTab then @@ -17,16 +17,16 @@ local function addTab(tab, order_idx) local tw, th = parent.getSize() tab.window = window.create(parent, 1, 1, tw, th, isCurrentTab) tab.scrollPos = 1 - tab.pageDown = function () + tab.pageDown = function() local tw, th = tab.window.getSize() tab.scrollPos = tab.scrollPos + th end - tab.pageUp = function () + tab.pageUp = function() local tw, th = tab.window.getSize() - tab.scrollPos = math.max(1, tab.scrollPos-th) + tab.scrollPos = math.max(1, tab.scrollPos - th) end allTabs[tab.name] = tab - tabOrder[order_idx] = tab.name + tabOrder[orderIdx] = tab.name tabCount = tabCount + 1 return tab end @@ -79,20 +79,22 @@ local function updateSize() end end -local function onTouch(touch_x, touch_y) +local function onTouch(touchX, touchY) if currentTab ~= nil then - currentTab.onTouch(currentTab, touch_x, touch_y) + local winx, winy = currentTab.window.getPosition() + return currentTab.onTouch(currentTab, touchX - winx + 1, touchY - winy + 1) end + return false end return { - setTerm=setTerm, - addTab=addTab, - showTab=showTab, - switchTab=switchTab, - updateSize=updateSize, - onTouch=onTouch, - currentTab=getCurrentTab, - allTabs=getAllTabs, -} \ No newline at end of file + setTerm = setTerm, + addTab = addTab, + showTab = showTab, + switchTab = switchTab, + updateSize = updateSize, + onTouch = onTouch, + currentTab = getCurrentTab, + allTabs = getAllTabs, +} diff --git a/test.lua b/test.lua index cc86c2f..af27a31 100644 --- a/test.lua +++ b/test.lua @@ -54,8 +54,11 @@ local function on_touch(touch_x, touch_y) tabview.switchTab() return true end - elseif tabview.onTouch(touch_x, touch_y) then - return true + elseif tabview_window ~= nil then + local winx, winy = tabview_window.getPosition() + if tabview.onTouch(touch_x-winx+1, touch_y-winy+1) then + return true + end end return false end