feat: layout anchor (#1582)
* feat: add `anchor` option to some `layout_strategies` * tests: improve tests for `resolve_height/width`
This commit is contained in:
@@ -213,6 +213,35 @@ resolver.resolve_width = function(val)
|
||||
error("invalid configuration option for width:" .. tostring(val))
|
||||
end
|
||||
|
||||
--- Calculates the adjustment required to move the picker from the middle of the screen to
|
||||
--- an edge or corner. <br>
|
||||
--- The `anchor` can be any of the following strings:
|
||||
--- - "", "CENTER", "NW", "N", "NE", "E", "SE", "S", "SW", "W"
|
||||
--- The anchors have the following meanings:
|
||||
--- - "" or "CENTER":<br>
|
||||
--- the picker will remain in the middle of the screen.
|
||||
--- - Compass directions:<br>
|
||||
--- the picker will move to the corresponding edge/corner
|
||||
--- e.g. "NW" -> "top left corner", "E" -> "right edge", "S" -> "bottom edge"
|
||||
resolver.resolve_anchor_pos = function(anchor, p_width, p_height, max_columns, max_lines)
|
||||
anchor = anchor:upper()
|
||||
local pos = { 0, 0 }
|
||||
if anchor == "CENTER" then
|
||||
return pos
|
||||
end
|
||||
if anchor:find "W" then
|
||||
pos[1] = math.ceil((p_width - max_columns) / 2) + 1
|
||||
elseif anchor:find "E" then
|
||||
pos[1] = math.ceil((max_columns - p_width) / 2) - 1
|
||||
end
|
||||
if anchor:find "N" then
|
||||
pos[2] = math.ceil((p_height - max_lines) / 2) + 1
|
||||
elseif anchor:find "S" then
|
||||
pos[2] = math.ceil((max_lines - p_height) / 2) - 1
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
-- Win option always returns a table with preview, results, and prompt.
|
||||
-- It handles many different ways. Some examples are as follows:
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user