diff options
author | kylo252 <[email protected]> | 2021-10-09 22:17:30 +0200 |
---|---|---|
committer | kylo252 <[email protected]> | 2021-10-09 22:17:30 +0200 |
commit | caf62bcfed4fc6cfed26164e39d22a568d21f9d0 (patch) | |
tree | 47f7ddcbe7ef10b6cffd8398dbfc215d94fc2fae /lua/interface | |
parent | 4126e5765d69840660fab2a05bbc664ad0117b95 (diff) | |
parent | 82b7a35858479223c1e34bea2f64451ecf1e5f66 (diff) |
Merge remote-tracking branch 'origin/rolling'
Diffstat (limited to 'lua/interface')
-rw-r--r-- | lua/interface/text.lua | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lua/interface/text.lua b/lua/interface/text.lua index f68cc491..6bf280e8 100644 --- a/lua/interface/text.lua +++ b/lua/interface/text.lua @@ -13,20 +13,36 @@ local function max_len_line(lines) return max_len end ---- Center align lines relatively to the parent container +--- Left align lines relatively to the parent container -- @param container The container where lines will be displayed -- @param lines The text to align -- @param alignment The alignment value, range: [0-1] -function M.align(container, lines, alignment) +function M.align_left(container, lines, alignment) local max_len = max_len_line(lines) local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment) - return M.shift_left(lines, indent_amount) + return M.shift_right(lines, indent_amount) +end + +--- Center align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align_center(container, lines, alignment) + local output = {} + local max_len = max_len_line(lines) + + for _, line in ipairs(lines) do + local padding = string.rep(" ", (math.max(container.width, max_len) - line:len()) * alignment) + table.insert(output, padding .. line) + end + + return output end --- Shift lines by a given amount -- @params lines The lines the shift -- @param amount The amount of spaces to add -function M.shift_left(lines, amount) +function M.shift_right(lines, amount) local output = {} local padding = string.rep(" ", amount) |