From 630ec6cfb8670607ddfc67dd4e56e98c17746ca6 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Mon, 24 Feb 2020 16:40:58 +0800 Subject: API/UI: Allow UI to set PUM position and size, and pass the position to CompleteChanged --- src/nvim/api/ui.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 75ee05761b..d2d1355207 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -109,7 +109,12 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, UI *ui = xcalloc(1, sizeof(UI)); ui->width = (int)width; ui->height = (int)height; + ui->pum_nlines = 0; + ui->pum_pos = false; + ui->pum_width = 0; ui->pum_height = 0; + ui->pum_row = -1; + ui->pum_col = -1; ui->rgb = true; ui->override = false; ui->grid_resize = remote_ui_grid_resize; @@ -340,7 +345,69 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) "It must support the ext_popupmenu option"); return; } + + ui->pum_nlines = (int)height; +} + +/// Tells Nvim the geometry of the popumenu, to align floating +/// windows with an external popup menu. Note that this method +/// is not to be confused with |nvim_ui_pum_set_height()|, which +/// sets the number of visible items in the popup menu, while +/// this function sets the bounding box of the popup menu, +/// including visual decorations such as boarders and sliders. +/// +/// @param channel_id +/// @param width Popupmenu width, must be greater than zero. +/// @param height Popupmenu height, must be greater than zero. +/// @param row Popupmenu row, must be greater or equal to zero. +/// @param col Popupmenu height, must be greater or equal to zero. +/// @param[out] err Error details, if any. On error, suspend pum position reporting for the current UI. +void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, + Integer row, Integer col, Error *err) + FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY +{ + if (!pmap_has(uint64_t)(connected_uis, channel_id)) { + api_set_error(err, kErrorTypeException, + "UI not attached to channel: %" PRId64, channel_id); + return; + } + + UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); + if (!ui->ui_ext[kUIPopupmenu]) { + api_set_error(err, kErrorTypeValidation, + "It must support the ext_popupmenu option"); + return; + } + + if (row < 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); + ui->pum_pos = false; + return; + } + + if (col < 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); + ui->pum_pos = false; + return; + } + + if (width <= 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); + ui->pum_pos = false; + return; + } + + if (height <= 0) { + api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); + ui->pum_pos = false; + return; + } + + ui->pum_row = (int)row; + ui->pum_col = (int)col; + ui->pum_width = (int)width; ui->pum_height = (int)height; + ui->pum_pos = true; } /// Pushes data into UI.UIData, to be consumed later by remote_ui_flush(). -- cgit From 9c85caa390ccf6295233c4201a60ccfa66417816 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 17:43:02 +0800 Subject: ui_pum_get_pos: return internal pum position if external pum pos not found --- src/nvim/api/ui.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index d2d1355207..430be920e2 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -357,11 +357,11 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) /// including visual decorations such as boarders and sliders. /// /// @param channel_id -/// @param width Popupmenu width, must be greater than zero. -/// @param height Popupmenu height, must be greater than zero. -/// @param row Popupmenu row, must be greater or equal to zero. -/// @param col Popupmenu height, must be greater or equal to zero. -/// @param[out] err Error details, if any. On error, suspend pum position reporting for the current UI. +/// @param width Popupmenu width. +/// @param height Popupmenu height. +/// @param row Popupmenu row. +/// @param col Popupmenu height. +/// @param[out] err Error details, if any. void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, Integer row, Integer col, Error *err) FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY @@ -375,31 +375,21 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); if (!ui->ui_ext[kUIPopupmenu]) { api_set_error(err, kErrorTypeValidation, - "It must support the ext_popupmenu option"); + "UI must support the ext_popupmenu option"); return; } if (row < 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); - ui->pum_pos = false; return; - } - - if (col < 0) { + } else if (col < 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); - ui->pum_pos = false; return; - } - - if (width <= 0) { + } else if (width <= 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); - ui->pum_pos = false; return; - } - - if (height <= 0) { + } else if (height <= 0) { api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); - ui->pum_pos = false; return; } -- cgit From 6da16ac931eec7be2487ee98e7f605fa12b0171d Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 18:17:37 +0800 Subject: external pum: use floating point geometry; typval: add tv_dict_add_float --- src/nvim/api/ui.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 430be920e2..b10434428c 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -111,10 +111,10 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height, ui->height = (int)height; ui->pum_nlines = 0; ui->pum_pos = false; - ui->pum_width = 0; - ui->pum_height = 0; - ui->pum_row = -1; - ui->pum_col = -1; + ui->pum_width = 0.0; + ui->pum_height = 0.0; + ui->pum_row = -1.0; + ui->pum_col = -1.0; ui->rgb = true; ui->override = false; ui->grid_resize = remote_ui_grid_resize; @@ -349,12 +349,15 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) ui->pum_nlines = (int)height; } -/// Tells Nvim the geometry of the popumenu, to align floating +/// Tells Nvim the geometry of the popumenu, to align floating /// windows with an external popup menu. Note that this method /// is not to be confused with |nvim_ui_pum_set_height()|, which /// sets the number of visible items in the popup menu, while -/// this function sets the bounding box of the popup menu, +/// this function sets the bounding box of the popup menu, /// including visual decorations such as boarders and sliders. +/// Floats need not use the same font size, nor be anchored to +/// exact grid corners, so one can set floating-point numbers +/// to the popup menu geometry. /// /// @param channel_id /// @param width Popupmenu width. @@ -362,9 +365,9 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) /// @param row Popupmenu row. /// @param col Popupmenu height. /// @param[out] err Error details, if any. -void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, - Integer row, Integer col, Error *err) - FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY +void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, + Float row, Float col, Error *err) + FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(err, kErrorTypeException, @@ -393,10 +396,10 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, return; } - ui->pum_row = (int)row; - ui->pum_col = (int)col; - ui->pum_width = (int)width; - ui->pum_height = (int)height; + ui->pum_row = (double)row; + ui->pum_col = (double)col; + ui->pum_width = (double)width; + ui->pum_height = (double)height; ui->pum_pos = true; } -- cgit From d372c804aa33a272f6659f6d08d5dfee704d30d9 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:27:49 +0800 Subject: api/ui: allow set bounds row and col to be less than 0; ui_pum_get_pos: return first extui bounds information instead of reducing --- src/nvim/api/ui.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index b10434428c..300f409a0f 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -382,17 +382,11 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height, return; } - if (row < 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); - return; - } else if (col < 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); - return; - } else if (width <= 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); + if (width <= 0) { + api_set_error(err, kErrorTypeValidation, "Expected width > 0"); return; } else if (height <= 0) { - api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); + api_set_error(err, kErrorTypeValidation, "Expected height > 0"); return; } -- cgit From e34684b2ad02e759dec39c0f0958c7882120ecdc Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:53:45 +0800 Subject: api/ui: simplify popup menu position get/set logic; fix test --- src/nvim/api/ui.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/ui.c') diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 300f409a0f..717713b948 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -349,15 +349,15 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) ui->pum_nlines = (int)height; } -/// Tells Nvim the geometry of the popumenu, to align floating -/// windows with an external popup menu. Note that this method -/// is not to be confused with |nvim_ui_pum_set_height()|, which -/// sets the number of visible items in the popup menu, while -/// this function sets the bounding box of the popup menu, -/// including visual decorations such as boarders and sliders. -/// Floats need not use the same font size, nor be anchored to -/// exact grid corners, so one can set floating-point numbers -/// to the popup menu geometry. +/// Tells Nvim the geometry of the popumenu, to align floating windows with an +/// external popup menu. +/// +/// Note that this method is not to be confused with |nvim_ui_pum_set_height()|, +/// which sets the number of visible items in the popup menu, while this +/// function sets the bounding box of the popup menu, including visual +/// decorations such as boarders and sliders. Floats need not use the same font +/// size, nor be anchored to exact grid corners, so one can set floating-point +/// numbers to the popup menu geometry. /// /// @param channel_id /// @param width Popupmenu width. -- cgit