From 6eb540dc055cdf32ebeae020c51c7d792d7247bc Mon Sep 17 00:00:00 2001 From: Zeng <76579810+Bekaboo@users.noreply.github.com> Date: Sun, 15 Jan 2023 12:18:45 -0600 Subject: feat(ui): customizable window height and width (#906) --- lua/mason-core/ui/display.lua | 26 +++++++++++++++++--------- lua/mason/settings.lua | 10 ++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'lua') diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua index 85e73523..bc685cda 100644 --- a/lua/mason-core/ui/display.lua +++ b/lua/mason-core/ui/display.lua @@ -1,5 +1,6 @@ local log = require "mason-core.log" local state = require "mason-core.ui.state" +local settings = require "mason.settings" local M = {} @@ -167,22 +168,29 @@ M._render_node = render_node ---@alias WindowOpts { effects?: table, winhighlight?: string[], border?: string|table } +---@param size integer | float +---@param viewport integer +local function calc_size(size, viewport) + if size <= 1 then + return math.ceil(size * viewport) + end + return math.min(size, viewport) +end + ---@param opts WindowOpts ---@param sizes_only boolean Whether to only return properties that control the window size. local function create_popup_window_opts(opts, sizes_only) + local lines = vim.o.lines - vim.o.cmdheight local columns = vim.o.columns - local top_offset = 1 - local bottom_offset = 1 + vim.o.cmdheight - if vim.o.laststatus == 0 then - bottom_offset = math.max(bottom_offset - 1, 1) - end - local height = vim.o.lines - bottom_offset - top_offset - local width = math.floor(columns * 0.8) + local height = calc_size(settings.current.ui.height, lines) + local width = calc_size(settings.current.ui.width, columns) + local row = math.floor((lines - height) / 2) + local col = math.floor((columns - width) / 2) local popup_layout = { height = height, width = width, - row = top_offset, - col = math.floor((columns - width) / 2), + row = row, + col = col, relative = "editor", style = "minimal", zindex = 45, diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua index 9bdc0f9c..09726a5c 100644 --- a/lua/mason/settings.lua +++ b/lua/mason/settings.lua @@ -58,6 +58,16 @@ local DEFAULT_SETTINGS = { -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. border = "none", + -- Width of the window. Accepts: + -- - Integer greater than 1 for fixed width. + -- - Float in the range of 0-1 for a percentage of screen width. + width = 0.8, + + -- Height of the window. Accepts: + -- - Integer greater than 1 for fixed height. + -- - Float in the range of 0-1 for a percentage of screen height. + height = 0.9, + icons = { -- The list icon to use for installed packages. package_installed = "◍", -- cgit v1.2.3-70-g09d2