diff --git a/tabview.lua b/tabview.lua index 4975367..353c6bd 100644 --- a/tabview.lua +++ b/tabview.lua @@ -1,3 +1,5 @@ +local winhlp = require "winhlp" + local parent = term.current() local tabCount = 0 local allTabs = {} @@ -80,9 +82,10 @@ local function updateSize() end local function onTouch(touchX, touchY) - if currentTab ~= nil then - local winx, winy = currentTab.window.getPosition() - return currentTab.onTouch(currentTab, touchX - winx + 1, touchY - winy + 1) + if currentTab ~= nil and + winhlp.contains(currentTab.window, touchX, touchY) and + currentTab.onTouch(currentTab, winhlp.translate(currentTab.window, touchX, touchY)) then + return true end return false end diff --git a/test.lua b/test.lua index af27a31..bcd6efd 100644 --- a/test.lua +++ b/test.lua @@ -1,5 +1,7 @@ local config = require "config" local tabview = require "tabview" +local winhlp = require "winhlp" + local header_lines = 2 -- display working state @@ -54,11 +56,10 @@ local function on_touch(touch_x, touch_y) tabview.switchTab() return true end - 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 + elseif tabview_window ~= nil and + winhlp.contains(tabview_window, touch_x, touch_y) and + tabview.onTouch(winhlp.translate(tabview_window, touch_x, touch_y)) then + return true end return false end diff --git a/update.lua b/update.lua index 078500e..cb188c6 100644 --- a/update.lua +++ b/update.lua @@ -29,6 +29,7 @@ end if update_update() then download_file("permset.lua") + download_file("winhlp.lua") download_file("tabview.lua") download_file("requests.lua") download_file("orders.lua") diff --git a/winhlp.lua b/winhlp.lua new file mode 100644 index 0000000..d57762e --- /dev/null +++ b/winhlp.lua @@ -0,0 +1,15 @@ +local function translate(window, x, y) + local winX, winY = window.getPosition() + return x-winX+1, y-winY+1 +end + +local function contains(window, x, y) + local winX, winY = window.getPosition() + local width, height = window.getSize() + return x >= winX and y >= winY and x-winX < width and y-winY < height +end + +return { + translate=translate, + contains=contains, +}