Refactor winhlp for contains and translate to windows
This commit is contained in:
parent
de031915f3
commit
7de3aefb8f
|
@ -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
|
||||
|
|
11
test.lua
11
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
|
||||
|
|
|
@ -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
15
winhlp.lua
Normal 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,
|
||||
}
|
Loading…
Reference in a new issue