Make cursor width depend on current font

This makes the cursor more visible wrt current font.

Moreover make the cursor width scalable by default.
This commit is contained in:
Jean-Marc Lasgouttes 2020-10-01 14:24:21 +02:00
parent 310c94c48c
commit c516c86d19
4 changed files with 13 additions and 10 deletions

View File

@ -3067,18 +3067,16 @@ void BufferView::caretPosAndDim(Point & p, Dimension & dim) const
Cursor const & cur = cursor(); Cursor const & cur = cursor();
if (cur.inMathed()) { if (cur.inMathed()) {
MathRow const & mrow = mathRow(&cur.cell()); MathRow const & mrow = mathRow(&cur.cell());
dim.asc = mrow.caret_ascent; dim = mrow.caret_dim;
dim.des = mrow.caret_descent;
} else { } else {
Font const font = cur.real_current_font; Font const font = cur.real_current_font;
frontend::FontMetrics const & fm = theFontMetrics(font); frontend::FontMetrics const & fm = theFontMetrics(font);
dim.wid = fm.lineWidth();
dim.asc = fm.maxAscent(); dim.asc = fm.maxAscent();
dim.des = fm.maxDescent(); dim.des = fm.maxDescent();
} }
if (lyxrc.cursor_width > 0) if (lyxrc.cursor_width > 0)
dim.wid = lyxrc.cursor_width; dim.wid = lyxrc.cursor_width;
else
dim.wid = 1 + int((lyxrc.currentZoom + 50) / 200.0);
p = getPos(cur); p = getPos(cur);
p.y_ -= dim.asc; p.y_ -= dim.asc;

View File

@ -560,7 +560,7 @@ public:
ScrollWheelZoom scroll_wheel_zoom = SCROLL_WHEEL_ZOOM_CTRL; ScrollWheelZoom scroll_wheel_zoom = SCROLL_WHEEL_ZOOM_CTRL;
// FIXME: should be caret_width // FIXME: should be caret_width
/// ///
int cursor_width = 1; int cursor_width = 0;
/// One of: yes, no, ask /// One of: yes, no, ask
std::string close_buffer_with_last_view = "yes"; std::string close_buffer_with_last_view = "yes";
}; };

View File

@ -295,10 +295,12 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
// This is one of the the few points where the drawing font is known, // This is one of the the few points where the drawing font is known,
// so that we can set the caret vertical dimensions. // so that we can set the caret vertical dimensions.
mrow.caret_ascent = min(dim.asc, fm.maxAscent()); mrow.caret_dim.asc = min(dim.asc, fm.maxAscent());
mrow.caret_descent = min(dim.des, fm.maxDescent()); mrow.caret_dim.des = min(dim.des, fm.maxDescent());
mrow.caret_dim.wid = fm.lineWidth();
/// do the same for math cells linearized in the row /// do the same for math cells linearized in the row
MathRow caret_row = MathRow(mrow.caret_ascent, mrow.caret_descent); MathRow caret_row = MathRow(mrow.caret_dim);
for (auto const & e : mrow) for (auto const & e : mrow)
if (e.type == MathRow::BEGIN && e.ar) if (e.type == MathRow::BEGIN && e.ar)
bv->setMathRow(e.ar, caret_row); bv->setMathRow(e.ar, caret_row);

View File

@ -16,6 +16,7 @@
#include "MathClass.h" #include "MathClass.h"
#include "ColorCode.h" #include "ColorCode.h"
#include "Dimension.h"
#include "support/docstring.h" #include "support/docstring.h"
@ -86,7 +87,9 @@ public:
}; };
/// ///
MathRow(int asc = 0, int des = 0) : caret_ascent(asc), caret_descent(des) {}; MathRow() {}
///
MathRow(Dimension const & dim) : caret_dim(dim) {}
/// ///
typedef std::vector<Element> Elements; typedef std::vector<Element> Elements;
/// ///
@ -119,7 +122,7 @@ public:
int kerning(BufferView const *) const; int kerning(BufferView const *) const;
/// useful when the caret visits this cell /// useful when the caret visits this cell
int caret_ascent, caret_descent; Dimension caret_dim;
private: private: