]> git.lyx.org Git - features.git/commitdiff
Remove space between button and text with inlines collapsible insets
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 11 Dec 2022 19:59:43 +0000 (20:59 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 6 Feb 2023 19:28:37 +0000 (20:28 +0100)
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

index c19d3a4e92691fcf12eac11e0badab5c3e47a8aa..d629aaaca40d51e80e5a7e773563b480fee8aa8b 100644 (file)
@@ -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;