2024-06-02 14:49:53 +00:00
|
|
|
local function translate(win, x, y)
|
|
|
|
local winX, winY = win.getPosition()
|
2024-06-01 16:08:57 +00:00
|
|
|
return x-winX+1, y-winY+1
|
|
|
|
end
|
|
|
|
|
2024-06-02 14:49:53 +00:00
|
|
|
local function contains(win, x, y)
|
|
|
|
local winX, winY = win.getPosition()
|
|
|
|
local width, height = win.getSize()
|
2024-06-01 16:08:57 +00:00
|
|
|
return x >= winX and y >= winY and x-winX < width and y-winY < height
|
|
|
|
end
|
|
|
|
|
2024-06-02 14:49:53 +00:00
|
|
|
local function setHeight(win, height)
|
|
|
|
local winX, winY = win.getPosition()
|
|
|
|
local sizeX, sizeY = win.getSize()
|
|
|
|
win.reposition(winX, winY, sizeX, height)
|
|
|
|
end
|
|
|
|
|
2024-06-02 14:58:30 +00:00
|
|
|
local function alignRightPadding(termlike, length)
|
2024-06-01 23:10:16 +00:00
|
|
|
local tw, th = termlike.getSize()
|
|
|
|
local x, y = termlike.getCursorPos()
|
|
|
|
termlike.setCursorPos(math.min(x, tw-length+1), y)
|
2024-06-02 01:16:18 +00:00
|
|
|
return math.max(0, tw-length-x+1)
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-06-01 16:08:57 +00:00
|
|
|
return {
|
|
|
|
translate=translate,
|
|
|
|
contains=contains,
|
2024-06-02 14:49:53 +00:00
|
|
|
setHeight=setHeight,
|
2024-06-02 14:58:30 +00:00
|
|
|
alignRightPadding=alignRightPadding,
|
2024-06-01 16:08:57 +00:00
|
|
|
}
|