Refactor winhlp for contains and translate to windows

This commit is contained in:
Ben 2024-06-01 18:08:57 +02:00
parent de031915f3
commit 7de3aefb8f
Signed by: ben
GPG key ID: 0F54A7ED232D3319
4 changed files with 28 additions and 8 deletions

View file

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

View file

@ -1,5 +1,7 @@
local config = require "config"
local tabview = require "tabview"
local winhlp = require "winhlp"
local header_lines = 2
-- display working state
@ -54,12 +56,11 @@ 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
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
end
return false
end

View file

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

15
winhlp.lua Normal file
View file

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