Hi there,
This is an experiment to see what people think about it. The idea is
1/ make cursor width scalable by default
2/ instead of setting a width that depends on zoom, choose one that
depends on current font line width (like the height depends on font height).
What I still do not like is that "0" is not an intuitive value for the
caret width in preferences. I thought we had a way to display "auto"
instead, but I cannot find how to do that.
Thoughts?
JMarc
From 7f6aa7698bb56f4e645d5b0ac0cfa66ba06188f2 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Thu, 1 Oct 2020 14:24:21 +0200
Subject: [PATCH] Make cursor width depend on current font
This makes the cursor more visible wrt current font.
Moreover make the cursor width scalable by default.
---
src/BufferView.cpp | 6 ++----
src/LyXRC.h | 2 +-
src/mathed/MathData.cpp | 8 +++++---
src/mathed/MathRow.h | 7 +++++--
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 88fe021..576bc67 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -3067,18 +3067,16 @@ void BufferView::caretPosAndDim(Point & p, Dimension & dim) const
Cursor const & cur = cursor();
if (cur.inMathed()) {
MathRow const & mrow = mathRow(&cur.cell());
- dim.asc = mrow.caret_ascent;
- dim.des = mrow.caret_descent;
+ dim = mrow.caret_dim;
} else {
Font const font = cur.real_current_font;
frontend::FontMetrics const & fm = theFontMetrics(font);
+ dim.wid = fm.lineWidth();
dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
}
if (lyxrc.cursor_width > 0)
dim.wid = lyxrc.cursor_width;
- else
- dim.wid = 1 + int((lyxrc.currentZoom + 50) / 200.0);
p = getPos(cur);
p.y_ -= dim.asc;
diff --git a/src/LyXRC.h b/src/LyXRC.h
index 3ebecb7..8950ea5 100644
--- a/src/LyXRC.h
+++ b/src/LyXRC.h
@@ -560,7 +560,7 @@ public:
ScrollWheelZoom scroll_wheel_zoom = SCROLL_WHEEL_ZOOM_CTRL;
// FIXME: should be caret_width
///
- int cursor_width = 1;
+ int cursor_width = 0;
/// One of: yes, no, ask
std::string close_buffer_with_last_view = "yes";
};
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index 90f41eb..da9dee7 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -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,
// so that we can set the caret vertical dimensions.
- mrow.caret_ascent = min(dim.asc, fm.maxAscent());
- mrow.caret_descent = min(dim.des, fm.maxDescent());
+ mrow.caret_dim.asc = min(dim.asc, fm.maxAscent());
+ 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
- MathRow caret_row = MathRow(mrow.caret_ascent, mrow.caret_descent);
+ MathRow caret_row = MathRow(mrow.caret_dim);
for (auto const & e : mrow)
if (e.type == MathRow::BEGIN && e.ar)
bv->setMathRow(e.ar, caret_row);
diff --git a/src/mathed/MathRow.h b/src/mathed/MathRow.h
index 6d1a410..f2b0445 100644
--- a/src/mathed/MathRow.h
+++ b/src/mathed/MathRow.h
@@ -16,6 +16,7 @@
#include "MathClass.h"
#include "ColorCode.h"
+#include "Dimension.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;
///
@@ -119,7 +122,7 @@ public:
int kerning(BufferView const *) const;
/// useful when the caret visits this cell
- int caret_ascent, caret_descent;
+ Dimension caret_dim;
private:
--
2.7.4
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel