Hello,
if you place the cursor in front of a vspace inset, it is displayed way
too high.
I had a look at method "metrics" in insetvspace.C which IMHO is a bit
confusing (and partially wrong - Why is size set to 10 initially? Why do
we decrease the font size twice but compute some values in between?)
I cleaned up the code and modified it in such a way that the cursor in
displayed on the same level as the vspace label.
Jean-Marc, Lars, can I commit it? (Pleeeeeease...)
Michael
PS: This was a nice opportunity in order to practice metrics
computation. I am ready for the rowpainter stuff now :-)
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1189
diff -u -r1.1189 ChangeLog
--- ChangeLog 16 Sep 2005 10:19:02 -0000 1.1189
+++ ChangeLog 16 Sep 2005 16:46:17 -0000
@@ -1,3 +1,8 @@
+2005-09-16 Michael Gerz <[EMAIL PROTECTED]>
+
+ * insetvspace.C (metrics): compute ascent and descent in a way that
+ the cursor is placed on the same level as the label text
+
2005-09-11 Martin Vermeer <[EMAIL PROTECTED]>
* insettabular.C: fixes bug 1765: multicol cell width on screen not
Index: insetvspace.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.C,v
retrieving revision 1.18
diff -u -r1.18 insetvspace.C
--- insetvspace.C 12 Sep 2005 14:57:50 -0000 1.18
+++ insetvspace.C 16 Sep 2005 16:46:17 -0000
@@ -116,25 +116,25 @@
void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
{
- int size = 10;
- int const space_size = space_.inPixels(*mi.base.bv);
-
LyXFont font;
font.decSize();
- int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+ font.decSize();
+
+ int height = 3 * arrow_size;
- if (space_.length().len().value() < 0.0)
- size = min_size;
- else
- size = max(min_size, space_size);
+ if (space_.length().len().value() > 0.0)
+ height = max(height, space_.inPixels(*mi.base.bv));
- dim.asc = size / 2;
- dim.des = size / 2;
int w = 0;
int a = 0;
int d = 0;
- font.decSize();
font_metrics::rectText(label(), font, w, a, d);
+
+ height = max(height, a * 2 + 1); // one extra pixel at the top
+ height = max(height, d * 2 + 1); // ... and at the bottom
+
+ dim.asc = height / 2 + (a - d) / 2; // align cursor with the
+ dim.des = height - dim.asc; // label text
dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
dim_ = dim;
@@ -150,8 +150,6 @@
int const start = y - dim_.asc;
int const end = y + dim_.des;
- // the label to display (if any)
- string const str = label();
// y-values for top arrow
int ty1, ty2;
// y-values for bottom arrow
@@ -184,8 +182,9 @@
font.decSize();
font_metrics::rectText(label(), font, w, a, d);
- pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
- str, font, LColor::none, LColor::none);
+ pi.pain.rectText(x + 2 * arrow_size + 5,
+ start + (end - start) / 2 + (a - d) / 2,
+ label(), font, LColor::none, LColor::none);
// top arrow
pi.pain.line(x, ty1, midx, ty2, LColor::added_space);