Skip to content

Commit 15a4756

Browse files
committed
feat: add customizable window alignment system
Replace row/col positioning with intuitive align options: - center, top-left, top-right, bottom-left, bottom-right - top, bottom, left, right - Defaults to 'center' for backward compatibility
1 parent fec8c2d commit 15a4756

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

doc/configuration.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ All options are optional with sensible defaults. See below for each option in de
3737
window = {
3838
width = 0.8, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
3939
height = 0.8, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
40+
align = "center", -- "center", "top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom", "left", "right"
4041
relative = "editor",
4142
zindex = 50,
4243
border = "rounded", -- "none", "single", "double", "rounded", "solid", "shadow"
@@ -196,6 +197,7 @@ Default:
196197
window = {
197198
width = 0.85, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
198199
height = 0.85, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
200+
align = "center", -- "center", "top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom", "left", "right"
199201
border = "rounded", -- "none", "single", "double", "rounded", "solid", "shadow"
200202
relative = "editor",
201203
zindex = 50,
@@ -210,6 +212,11 @@ Default:
210212
Controls the appearance and behavior of the MCPHub UI window:
211213
- `width`: Window width (0-1 for ratio, "50%" for percentage, or raw number)
212214
- `height`: Window height (same format as width)
215+
- `align`: Window alignment position. Options:
216+
- `"center"`: Center the window (default)
217+
- `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`: Corner positions
218+
- `"top"`, `"bottom"`: Top/bottom edge, centered horizontally
219+
- `"left"`, `"right"`: Left/right edge, centered vertically
213220
- `relative`: Window placement relative to ("editor", "win", or "cursor")
214221
- `zindex`: Window stacking order
215222
- `border`: Border style ("none", "single", "double", "rounded", "solid", "shadow")
@@ -246,3 +253,6 @@ Logging configuration options:
246253
- `file_path`: Custom log file path
247254
- `prefix`: Prefix for log messages
248255

256+
257+
258+

lua/mcphub/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ local defaults = {
3030
window = {
3131
width = 0.85, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
3232
height = 0.85, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
33+
align = "center", -- "center", "top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom", "left", "right"
3334
border = "rounded", -- "none", "single", "double", "rounded", "solid", "shadow"
3435
relative = "editor",
3536
zindex = 50,

lua/mcphub/ui/init.lua

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ local defaults = {
2424
window = {
2525
width = 0.8, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
2626
height = 0.8, -- 0-1 (ratio); "50%" (percentage); 50 (raw number)
27+
align = "center", -- "center", "top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom", "left", "right"
2728
border = "rounded", -- "none", "single", "double", "rounded", "solid", "shadow"
2829
relative = "editor",
2930
zindex = 50,
@@ -195,9 +196,42 @@ function UI:calculate_window_dimensions()
195196
local height = parse_size(win_opts.height, vim.o.lines)
196197
height = math.max(min_height, height)
197198

198-
-- Calculate center position
199-
local row = math.floor((vim.o.lines - height) / 2)
200-
local col = math.floor((vim.o.columns - width) / 2)
199+
-- Calculate position based on alignment
200+
local row, col
201+
local align = win_opts.align or "center"
202+
203+
if align == "center" then
204+
row = math.floor((vim.o.lines - height) / 2)
205+
col = math.floor((vim.o.columns - width) / 2)
206+
elseif align == "top-left" then
207+
row = 1
208+
col = 1
209+
elseif align == "top-right" then
210+
row = 1
211+
col = vim.o.columns - width
212+
elseif align == "bottom-left" then
213+
row = vim.o.lines - height
214+
col = 1
215+
elseif align == "bottom-right" then
216+
row = vim.o.lines - height
217+
col = vim.o.columns - width
218+
elseif align == "top" then
219+
row = 1
220+
col = math.floor((vim.o.columns - width) / 2)
221+
elseif align == "bottom" then
222+
row = vim.o.lines - height
223+
col = math.floor((vim.o.columns - width) / 2)
224+
elseif align == "left" then
225+
row = math.floor((vim.o.lines - height) / 2)
226+
col = 1
227+
elseif align == "right" then
228+
row = math.floor((vim.o.lines - height) / 2)
229+
col = vim.o.columns - width
230+
else
231+
-- Default to center for unknown alignment
232+
row = math.floor((vim.o.lines - height) / 2)
233+
col = math.floor((vim.o.columns - width) / 2)
234+
end
201235

202236
return {
203237
width = width,

0 commit comments

Comments
 (0)