]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCollapsible.cpp
Fix bug #12795
[lyx.git] / src / insets / InsetCollapsible.cpp
index 24aca669452a429c05a91f2728b324a816c75a81..a0a789cc6759416bd14f50b149928c8809870bf1 100644 (file)
@@ -188,8 +188,16 @@ 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; we also do it for
+       // TopButton (although it is not useful per se), because
+       // openinlined_ is not always set properly at this point.
+       Geometry const geom = geometry(bv);
+       if (geom == LeftButton || geom == TopButton)
+               // this form makes a difference if offset is even
+               dim.wid -= offset - offset / 2;
        return dim;
 }
 
@@ -198,10 +206,6 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        view_[mi.base.bv].auto_open_ = mi.base.bv->cursor().isInside(this);
 
-       FontInfo tmpfont = mi.base.font;
-       mi.base.font = getFont();
-       mi.base.font.realize(tmpfont);
-
        BufferView const & bv = *mi.base.bv;
 
        switch (geometry(bv)) {
@@ -240,8 +244,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 {
@@ -251,8 +255,6 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
                }
                break;
        }
-
-       mi.base.font = tmpfont;
 }
 
 
@@ -320,7 +322,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;
@@ -423,7 +427,7 @@ void InsetCollapsible::cursorPos(BufferView const & bv,
 
        switch (geometry(bv)) {
        case LeftButton:
-               x += dimensionCollapsed(bv).wid;
+               x += dimensionCollapsed(bv).wid - leftOffset(&bv) / 2;
                break;
        case TopButton: {
                y += dimensionCollapsed(bv).des + textdim.asc;
@@ -725,18 +729,6 @@ InsetDecoration InsetCollapsible::decoration() const
 }
 
 
-FontInfo InsetCollapsible::getFont() const
-{
-       return getLayout().font();
-}
-
-
-FontInfo InsetCollapsible::getLabelfont() const
-{
-       return getLayout().labelfont();
-}
-
-
 string InsetCollapsible::contextMenu(BufferView const & bv, int x,
        int y) const
 {