On 27.10.2016 10:21, racoon wrote:
On 27.10.2016 10:15, racoon wrote:
On 18.10.2016 09:37, Jean-Marc Lasgouttes wrote:
Le 17/10/2016 à 01:28, racoon a écrit :
I just tried to do some fine tuning on the inset offsets (minimalistic
and classic so far).
Hi racoon,
I am glad you are looking at this. I agree that small offsets are
better.
Though I have a non-high resolution display. Maybe it does not look as
good on a high-res display. If so, maybe there should be an adjustment
for high-res displays?
I had a go earlier to replace TEXT_TO_INSET_OFFSET with a function that
computes the length according to current zoom and screen resolution. I
abandonned the patch (attached) for now because it created problems for
vertical spacing. You are welcome to borrow parts of it (the margins are
already in).
You would be welcome to have a look at it. Another option would be to
have a length in em, that is relative to the current font. That would
make the inset spacing comparable to normal spacing in the enclosing
space. This is the best solution IMO, but I am not sure that the font
information is available when we need it.
Hi JMarc,
I did have a look and the attached patch is the current result (again
only buttons and frames for now). There is also a simple test example.
Since I did not touch the vertical spacing, only inner and outer side
offsets, that should be fine still. (Though there was something wrong
with the vertical spacing to begin with since, for example, the inner
text runs over the upper and lower boundaries on higher zoom levels.)
For some reason the frames scale a bit different different and maybe
nicer than the buttons.
ps. And I did not do anything about the interactive area. So it is still
a bit off to the right and includes the outer spaces (same as in LyX
2.2.2). The translation might be possible to solve easily. I am a bit
more uncertain about the outer space.
ps2. Oh, I forgot to comment on the added pixels. They are for the
non-sizable frames. Patch commented appropriately. Though I am not fully
sure I understood all of them properly.
From 5fc9359ece762af2792868ba6beeac278f9bde74 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Ram=C3=83=3F=3F=3F=3F=3F=3F=C3=83=3F=3F=3F=3F=3F?=
=?UTF-8?q?=C3=83=3F=3F=3F=3F=C3=83=3F=3F=3F=C3=83=3F=3F=C3=83=3F=C3=82?=
=?UTF-8?q?=C2=B6ller?= <d....@web.de>
Date: Mon, 17 Oct 2016 01:21:01 +0200
Subject: [PATCH] Some inset offset fine tuning: - Make outer inset offset
independent of inner. - Reduced the outer offset. - Make it scale with the
zoom.
---
src/frontends/qt4/GuiFontMetrics.cpp | 5 +++--
src/frontends/qt4/GuiPainter.cpp | 7 ++++---
src/insets/Inset.cpp | 16 ++++++++++++++++
src/insets/Inset.h | 6 +++++-
src/insets/InsetText.cpp | 15 ++++++++++-----
5 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp
b/src/frontends/qt4/GuiFontMetrics.cpp
index eade8cc..46c7dc2 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -254,7 +254,7 @@ void GuiFontMetrics::rectText(docstring const & str,
{
static int const d = Inset::TEXT_TO_INSET_OFFSET / 2;
- w = width(str) + Inset::TEXT_TO_INSET_OFFSET;
+ w = width(str) + 2 * Inset::textToInsetOffsetInside();
ascent = metrics_.ascent() + d;
descent = metrics_.descent() + d;
}
@@ -265,7 +265,8 @@ void GuiFontMetrics::buttonText(docstring const & str,
int & w, int & ascent, int & descent) const
{
rectText(str, w, ascent, descent);
- w += Inset::TEXT_TO_INSET_OFFSET;
+ // 2 added pixels for the frame
+ w += Inset::textToInsetOffsetInside() + 2;
}
diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp
index e613f3f..1cf5575 100644
--- a/src/frontends/qt4/GuiPainter.cpp
+++ b/src/frontends/qt4/GuiPainter.cpp
@@ -593,10 +593,11 @@ void GuiPainter::buttonText(int x, int y, docstring const
& str,
FontMetrics const & fm = theFontMetrics(font);
fm.buttonText(str, width, ascent, descent);
- static int const d = Inset::TEXT_TO_INSET_OFFSET / 2;
+ static int const d = Inset::textToInsetOffsetOutside();
- button(x + d, y - ascent, width - Inset::TEXT_TO_INSET_OFFSET, descent
+ ascent, mouseHover);
- text(x + Inset::TEXT_TO_INSET_OFFSET, y, str, font);
+ button(x + Inset::textToInsetOffsetOutside(), y - ascent, width -
2*Inset::textToInsetOffsetOutside(), descent + ascent, mouseHover);
+ // 1 pixel added for the frame
+ text(x + Inset::textToInsetOffsetInside() +
Inset::textToInsetOffsetOutside() + 1, y, str, font);
}
diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index 6e2e4a0..c9bf77e 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -27,6 +27,7 @@
#include "DispatchResult.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
+#include "Length.h"
#include "MetricsInfo.h"
#include "output_xhtml.h"
#include "Text.h"
@@ -621,6 +622,21 @@ ColorCode Inset::labelColor() const
}
+int Inset::textToInsetOffsetInside()
+{
+ // 2 pixel at 100dpi default resolution is
+ // equivalent to .5 millimeter.
+ return Length(.5, Length::MM).inPixels(0);
+}
+
+int Inset::textToInsetOffsetOutside()
+{
+ // 1 pixel at 100dpi default resolution is
+ // equivalent to .25 millimeter.
+ return Length(.25, Length::MM).inPixels(0);
+}
+
+
void Inset::setPosCache(PainterInfo const & pi, int x, int y) const
{
//LYXERR("Inset: set position cache to " << x << " " << y);
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 48ad7be..f131d59 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -574,7 +574,11 @@ public:
///
virtual ColorCode labelColor() const;
//
- enum { TEXT_TO_INSET_OFFSET = 4 };
+ enum {
+ TEXT_TO_INSET_OFFSET = 4
+ };
+ static int textToInsetOffsetInside();
+ static int textToInsetOffsetOutside();
protected:
/// Constructors
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index df4f6e2..0f6f117 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -208,7 +208,8 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim)
const
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
dim.asc += TEXT_TO_INSET_OFFSET;
dim.des += TEXT_TO_INSET_OFFSET;
- dim.wid += 2 * TEXT_TO_INSET_OFFSET;
+ // cursor position after inset, 2*1 pixel added for the frame
+ dim.wid += 2 * (textToInsetOffsetInside() + textToInsetOffsetOutside()
+ 1);
}
@@ -216,10 +217,12 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
{
TextMetrics & tm = pi.base.bv->textMetrics(&text_);
- int const w = tm.width() + TEXT_TO_INSET_OFFSET;
+ // framewidth, 1 pixel added for the frame
+ // (FIXME: why not 2 pixel is there something wrong with the rectangle
calculation?)
+ int const w = tm.width() + 2 * textToInsetOffsetInside() + 1;
int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent();
int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
- int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
+ int const xframe = x + textToInsetOffsetOutside();
bool change_drawn = false;
if (drawFrame_ || pi.full_repaint) {
if (pi.full_repaint)
@@ -251,7 +254,8 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
pi.backgroundColor(this, false));
// The change tracking cue must not be inherited
Changer dummy2 = make_change(pi.change_, Change());
- tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+ // text position within inset, 1 pixel added for the frame
+ tm.draw(pi, x + textToInsetOffsetInside() +
textToInsetOffsetOutside() + 1, y);
}
if (canPaintChange(*pi.base.bv) && (!change_drawn ||
pi.change_.deleted()))
// Do not draw the change tracking cue if already done by
RowPainter and
@@ -680,7 +684,8 @@ void InsetText::getArgs(otexstream & os, OutputParams const
& runparams_in,
void InsetText::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
- x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
+ // cursor position within inset, 1 pixel added for the frame
+ x = bv.textMetrics(&text_).cursorX(sl, boundary) +
textToInsetOffsetInside() + textToInsetOffsetOutside() + 1;
y = bv.textMetrics(&text_).cursorY(sl, boundary);
}
--
2.9.0.windows.1