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 parent = term.current()
local tabCount = 0 local tabCount = 0
local allTabs = {} local allTabs = {}
@ -80,9 +82,10 @@ local function updateSize()
end end
local function onTouch(touchX, touchY) local function onTouch(touchX, touchY)
if currentTab ~= nil then if currentTab ~= nil and
local winx, winy = currentTab.window.getPosition() winhlp.contains(currentTab.window, touchX, touchY) and
return currentTab.onTouch(currentTab, touchX - winx + 1, touchY - winy + 1) currentTab.onTouch(currentTab, winhlp.translate(currentTab.window, touchX, touchY)) then
return true
end end
return false return false
end end

View file

@ -1,5 +1,7 @@
local config = require "config" local config = require "config"
local tabview = require "tabview" local tabview = require "tabview"
local winhlp = require "winhlp"
local header_lines = 2 local header_lines = 2
-- display working state -- display working state
@ -54,12 +56,11 @@ local function on_touch(touch_x, touch_y)
tabview.switchTab() tabview.switchTab()
return true return true
end end
elseif tabview_window ~= nil then elseif tabview_window ~= nil and
local winx, winy = tabview_window.getPosition() winhlp.contains(tabview_window, touch_x, touch_y) and
if tabview.onTouch(touch_x-winx+1, touch_y-winy+1) then tabview.onTouch(winhlp.translate(tabview_window, touch_x, touch_y)) then
return true return true
end end
end
return false return false
end end

View file

@ -29,6 +29,7 @@ end
if update_update() then if update_update() then
download_file("permset.lua") download_file("permset.lua")
download_file("winhlp.lua")
download_file("tabview.lua") download_file("tabview.lua")
download_file("requests.lua") download_file("requests.lua")
download_file("orders.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,
}