feat(ui): make the windoww size configurable. Fixes #34

This commit is contained in:
Folke Lemaitre 2022-12-20 19:29:28 +01:00
parent 52984419ff
commit 941df31a41
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 11 additions and 4 deletions

View File

@ -263,6 +263,8 @@ return {
colorscheme = { "habamax" }, colorscheme = { "habamax" },
}, },
ui = { ui = {
-- a number <1 is a percentage., >1 is a fixed size
size = { width = 0.8, height = 0.8 },
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none", border = "none",
icons = { icons = {

View File

@ -32,6 +32,8 @@ M.defaults = {
colorscheme = { "habamax" }, colorscheme = { "habamax" },
}, },
ui = { ui = {
-- a number <1 is a percentage., >1 is a fixed size
size = { width = 0.8, height = 0.8 },
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none", border = "none",
icons = { icons = {

View File

@ -56,16 +56,19 @@ function M.show(mode)
local buf = vim.api.nvim_create_buf(false, false) local buf = vim.api.nvim_create_buf(false, false)
M._buf = buf M._buf = buf
local vpad = 6
local hpad = 20 local function size(max, value)
return value > 1 and math.min(value, max) or math.floor(max * value)
end
local opts = { local opts = {
relative = "editor", relative = "editor",
style = "minimal", style = "minimal",
border = Config.options.ui.border, border = Config.options.ui.border,
width = math.min(vim.o.columns - hpad * 2, 200), width = size(vim.o.columns, Config.options.ui.size.width),
height = math.min(vim.o.lines - vpad * 2, 70), height = size(vim.o.lines, Config.options.ui.size.height),
noautocmd = true, noautocmd = true,
} }
opts.row = (vim.o.lines - opts.height) / 2 opts.row = (vim.o.lines - opts.height) / 2
opts.col = (vim.o.columns - opts.width) / 2 opts.col = (vim.o.columns - opts.width) / 2
local win = vim.api.nvim_open_win(buf, true, opts) local win = vim.api.nvim_open_win(buf, true, opts)