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",
"colors",
"fs",
"shell"
"shell",
"window"
]
}

View file

@ -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,
}
setTerm = setTerm,
addTab = addTab,
showTab = showTab,
switchTab = switchTab,
updateSize = updateSize,
onTouch = onTouch,
currentTab = getCurrentTab,
allTabs = getAllTabs,
}

View file

@ -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