Skip to content

Commit

Permalink
feat: allow scaling the floating window width and height separately
Browse files Browse the repository at this point in the history
Now you can have e.g. a wide screen yazi.nvim experience by setting
`floating_window_scaling_factor = { width = 0.95, height = 0.70 }` in
your configuration 😄
  • Loading branch information
mikavilpas committed Sep 16, 2024
1 parent 571ce9f commit db38803
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lua/yazi/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

---@module "plenary.path"

---@alias YaziFloatingWindowScaling { height: number, width: number }

---@class (exact) YaziConfig
---@field public open_for_directories? boolean
---@field public chosen_file_path? string "the path to a temporary file that will be created by yazi to store the chosen file path"
Expand All @@ -13,7 +15,7 @@
---@field public hooks? YaziConfigHooks
---@field public highlight_groups? YaziConfigHighlightGroups
---@field public integrations? YaziConfigIntegrations
---@field public floating_window_scaling_factor? number "the scaling factor for the floating window. 1 means 100%, 0.9 means 90%, etc."
---@field public floating_window_scaling_factor? number | YaziFloatingWindowScaling "the scaling factor for the floating window. 1 means 100%, 0.9 means 90%, etc."
---@field public yazi_floating_window_winblend? number "the transparency of the yazi floating window (0-100). See :h winblend"
---@field public yazi_floating_window_border? any "the type of border to use. See nvim_open_win() for the values your neovim version supports"
---@field public log_level? yazi.LogLevel
Expand Down
16 changes: 14 additions & 2 deletions lua/yazi/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ local function get_window_dimensions(config)
return value > 1 and math.min(value, max) or math.floor(max * value)
end

local height = size(vim.o.lines, config.floating_window_scaling_factor)
local width = size(vim.o.columns, config.floating_window_scaling_factor)
local height
local width

if type(config.floating_window_scaling_factor) == "number" then
height = size(vim.o.lines, config.floating_window_scaling_factor)
width = size(vim.o.columns, config.floating_window_scaling_factor)
else
assert(
type(config.floating_window_scaling_factor) == "table",
"floating_window_scaling_factor must be a number or a table"
)
height = size(vim.o.lines, config.floating_window_scaling_factor.height)
width = size(vim.o.columns, config.floating_window_scaling_factor.width)
end

local row = math.floor((vim.o.lines - height) / 2)
local col = math.floor((vim.o.columns - width) / 2)
Expand Down

0 comments on commit db38803

Please sign in to comment.