Skip to content

Commit

Permalink
Fix popup menu info float positioning on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-px2 committed Nov 1, 2021
1 parent fb5f29f commit 1069bfe
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,11 @@ void EditorArea::win_float_pos(std::span<NeovimObj> objs)
}
if (!popup_menu.hidden() && popup_menu.selected_idx() != -1)
{
QPoint pum_tr = popupmenu_rect().topRight();
const auto [font_w, font_h] = font_dimensions();
const QPoint pum_tr = popupmenu_rect().topRight();
// Don't let the grid get clipped by the popup menu
float pum_rx = std::round(pum_tr.x() / font_width);
float pum_ty = std::ceil(pum_tr.y() / font_height);
const float pum_rx = std::round(pum_tr.x() / font_w);
const float pum_ty = std::ceil(pum_tr.y() / font_h);
anchor_pos = QPoint(pum_rx, pum_ty);
}
bool were_animations_enabled = animations_enabled();
Expand Down Expand Up @@ -575,9 +576,9 @@ void EditorArea::paintEvent(QPaintEvent* event)
} else popup_menu.setVisible(false);
}

std::tuple<float, float> EditorArea::font_dimensions() const
FontDimensions EditorArea::font_dimensions() const
{
return std::make_tuple(font_width, font_height);
return {font_width, font_height};
}

void EditorArea::resized(QSize sz)
Expand Down
2 changes: 1 addition & 1 deletion src/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class EditorArea : public QWidget
/**
* Returns the font width and font height.
*/
virtual std::tuple<float, float> font_dimensions() const;
virtual FontDimensions font_dimensions() const;
/**
* Ignores the next paintEvent call.
* This is really only called after the window is moved.
Expand Down
7 changes: 7 additions & 0 deletions src/font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ class Font
QRawFont raw_;
};

/// Font dimensions of a monospace font,
/// stores the width and height of a single character.
struct FontDimensions
{
float width;
float height;
};
#endif // NVUI_FONT_HPP
4 changes: 2 additions & 2 deletions src/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ void QPaintGrid::draw(QPainter& p, QRect r, const double offset)
const auto& fonts = editor_area->fallback_list();
QFont cur_font = editor_area->main_font();
auto font_dims = editor_area->font_dimensions();
auto font_width = std::get<0>(font_dims);
auto font_height = std::get<1>(font_dims);
auto font_width = font_dims.width;
auto font_height = font_dims.height;
//int start_x = r.left();
//int end_x = r.right();
int start_y = r.top();
Expand Down
4 changes: 2 additions & 2 deletions src/platform/windows/direct2dpaintgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ void D2DPaintGrid::draw(
//const int start_x = r.left(), end_x = r.right();
const int start_y = r.top(), end_y = r.bottom();
const auto font_dims = editor_area->font_dimensions();
const float font_width = std::get<0>(font_dims);
const float font_height = std::get<1>(font_dims);
const float font_width = font_dims.width;
const float font_height = font_dims.height;
const HLState* s = editor_area->hl_state();
QString buffer;
buffer.reserve(100);
Expand Down
4 changes: 2 additions & 2 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Window::Window(QWidget* parent, Nvim* nv, int width, int height, bool custom_tit
setMouseTracking(true);
QObject::connect(this, &Window::resize_done, &editor_area, &EditorArea::resized);
prev_state = windowState();
const auto font_dims = editor_area.font_dimensions();
resize(width * std::get<0>(font_dims), height * std::get<1>(font_dims));
const auto [font_width, font_height] = editor_area.font_dimensions();
resize(width * font_width, height * font_height);
emit resize_done(size());
if (custom_titlebar)
{
Expand Down
2 changes: 1 addition & 1 deletion src/wineditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class WinEditorArea : public EditorArea
return nullptr;
}

std::tuple<float, float> font_dimensions() const override
FontDimensions font_dimensions() const override
{
if (font_width_f <= 0.f)
{
Expand Down

0 comments on commit 1069bfe

Please sign in to comment.