From 04ece4f0d6af818b3bc572b558181b947a109580 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sun, 11 Dec 2022 20:59:43 +0100 Subject: [PATCH] Remove space between button and text with inlines collapsible insets Typically there are two sources of spacing: * the button has two pixels added to the left and to the right * the frame around the text also has 2 pixels to the left and to the right Note that this value of two pixels is given here for simplicity, but these are parameterized by methods like textOffset or leftOffset. What we want to remove is the space after the button and the space before the frame. This is done in 3 places In dimensionCollapsed(), the extra space is removed from the dimension after its computation In metrics(), the space avoided before the frame is removed from width. In draw, the whome text inset is drawn with a negative offset. Fixes #12335. --- src/insets/InsetCollapsible.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp index c19d3a4e92..d629aaaca4 100644 --- a/src/insets/InsetCollapsible.cpp +++ b/src/insets/InsetCollapsible.cpp @@ -188,8 +188,13 @@ Dimension InsetCollapsible::dimensionCollapsed(BufferView const & bv) const Dimension dim; FontInfo labelfont(getLabelfont()); labelfont.realize(sane_font); + int const offset = Inset::textOffset(&bv); theFontMetrics(labelfont).buttonText( - buttonLabel(bv), Inset::textOffset(&bv), dim.wid, dim.asc, dim.des); + buttonLabel(bv), offset, dim.wid, dim.asc, dim.des); + // remove spacing on the right for left buttons + if (geometry(bv) == LeftButton) + // this form makes a difference if offset is even + dim.wid -= offset - offset / 2; return dim; } @@ -236,8 +241,8 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const InsetText::metrics(mi, textdim); view_[&bv].openinlined_ = (textdim.wid + dim.wid) < mi.base.textwidth; if (view_[&bv].openinlined_) { - // Correct for button width. - dim.wid += textdim.wid; + // Correct for button width but remove spacing before frame + dim.wid += textdim.wid - leftOffset(mi.base.bv) / 2; dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des); dim.asc = textdim.asc; } else { @@ -314,7 +319,9 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const case LeftButton: case TopButton: { if (g == LeftButton) { - textx = x + dimc.width(); + // correct for spacing added before the frame in + // InsetText::draw. We want the button to touch the frame. + textx = x + dimc.width() - leftOffset(pi.base.bv) / 2; texty = baseline; } else { textx = x; -- 2.39.5