cc/winhlp.lua

32 lines
830 B
Lua
Raw Normal View History

2024-06-02 14:49:53 +00:00
local function translate(win, x, y)
local winX, winY = win.getPosition()
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()
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
local function alignRightPadding(termlike, length)
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)
end
return {
translate=translate,
contains=contains,
2024-06-02 14:49:53 +00:00
setHeight=setHeight,
alignRightPadding=alignRightPadding,
}