Fix touch method, window offset and return value

This commit is contained in:
Ben 2024-06-01 17:13:03 +02:00
parent 92134a8129
commit de031915f3
Signed by: ben
GPG key ID: 0F54A7ED232D3319
3 changed files with 27 additions and 21 deletions

View file

@ -4,6 +4,7 @@
"term", "term",
"colors", "colors",
"fs", "fs",
"shell" "shell",
"window"
] ]
} }

View file

@ -4,11 +4,11 @@ local allTabs = {}
local tabOrder = {} local tabOrder = {}
local currentTab = nil local currentTab = nil
local function setTerm(new_term) local function setTerm(newTerm)
parent = new_term parent = newTerm
end end
local function addTab(tab, order_idx) local function addTab(tab, orderIdx)
assert(tab.name, "tab needs a unique name") assert(tab.name, "tab needs a unique name")
local isCurrentTab = currentTab == nil local isCurrentTab = currentTab == nil
if isCurrentTab then if isCurrentTab then
@ -17,16 +17,16 @@ local function addTab(tab, order_idx)
local tw, th = parent.getSize() local tw, th = parent.getSize()
tab.window = window.create(parent, 1, 1, tw, th, isCurrentTab) tab.window = window.create(parent, 1, 1, tw, th, isCurrentTab)
tab.scrollPos = 1 tab.scrollPos = 1
tab.pageDown = function () tab.pageDown = function()
local tw, th = tab.window.getSize() local tw, th = tab.window.getSize()
tab.scrollPos = tab.scrollPos + th tab.scrollPos = tab.scrollPos + th
end end
tab.pageUp = function () tab.pageUp = function()
local tw, th = tab.window.getSize() local tw, th = tab.window.getSize()
tab.scrollPos = math.max(1, tab.scrollPos-th) tab.scrollPos = math.max(1, tab.scrollPos - th)
end end
allTabs[tab.name] = tab allTabs[tab.name] = tab
tabOrder[order_idx] = tab.name tabOrder[orderIdx] = tab.name
tabCount = tabCount + 1 tabCount = tabCount + 1
return tab return tab
end end
@ -79,20 +79,22 @@ local function updateSize()
end end
end end
local function onTouch(touch_x, touch_y) local function onTouch(touchX, touchY)
if currentTab ~= nil then 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 end
return false
end end
return { return {
setTerm=setTerm, setTerm = setTerm,
addTab=addTab, addTab = addTab,
showTab=showTab, showTab = showTab,
switchTab=switchTab, switchTab = switchTab,
updateSize=updateSize, updateSize = updateSize,
onTouch=onTouch, onTouch = onTouch,
currentTab=getCurrentTab, currentTab = getCurrentTab,
allTabs=getAllTabs, allTabs = getAllTabs,
} }

View file

@ -54,9 +54,12 @@ local function on_touch(touch_x, touch_y)
tabview.switchTab() tabview.switchTab()
return true return true
end end
elseif tabview.onTouch(touch_x, touch_y) then 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 return true
end end
end
return false return false
end end