Fix touch method, window offset and return value
This commit is contained in:
parent
92134a8129
commit
de031915f3
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -4,6 +4,7 @@
|
|||
"term",
|
||||
"colors",
|
||||
"fs",
|
||||
"shell"
|
||||
"shell",
|
||||
"window"
|
||||
]
|
||||
}
|
14
tabview.lua
14
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
|
||||
|
@ -26,7 +26,7 @@ local function addTab(tab, order_idx)
|
|||
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,10 +79,12 @@ 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
|
||||
|
||||
|
||||
|
|
5
test.lua
5
test.lua
|
@ -54,9 +54,12 @@ local function on_touch(touch_x, touch_y)
|
|||
tabview.switchTab()
|
||||
return true
|
||||
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
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue