[LyX/2.3.x] Fixup d207e85c: paint sublabel with the correct background color

Jean-Marc Lasgouttes lasgouttes at lyx.org
Sun Jun 7 12:02:56 UTC 2020


commit f01c23bd5a6c0adcd0bb9238112c3303d1adbc96
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Mon Feb 24 10:37:14 2020 +0100

    Fixup d207e85c: paint sublabel with the correct background color
    
    The above mentionned patch did paint the background of the sublabel to
    avoid "bold-like" effect. However the correct backgound color is the
    row's one, not the inset's one.
    
    To fix this, extend MetricsInfo::backgroundColor to work when no inset
    is specified. The code is also simplified as in master.
    
    (cherry picked from commit 74540c9896892b8f956f52258a59613af83a5cf8)
    (cherry picked from commit a71b96ac426438abb4fe835d0ad000c769693421)
---
 src/MetricsInfo.cpp             |   22 +++++++++++-----------
 src/MetricsInfo.h               |    6 +++---
 src/insets/InsetCollapsible.cpp |    2 +-
 status.23x                      |    2 ++
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index 7ab62dc..1124ed8 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -138,24 +138,24 @@ void PainterInfo::draw(int x, int y, docstring const & str)
 
 ColorCode PainterInfo::backgroundColor(Inset const * inset, bool sel) const
 {
-	ColorCode const color_bg = inset->backgroundColor(*this);
-
 	if (selected && sel)
 		// This inset is in a selection
 		return Color_selection;
-	else {
+
+	// special handling for inset background
+	if (inset != nullptr) {
+		ColorCode const color_bg = inset->backgroundColor(*this);
 		if (color_bg != Color_none)
 			// This inset has its own color
 			return color_bg;
-		else {
-			if (background_color == Color_none)
-				// This inset has no own color and does not inherit a color
-				return Color_background;
-			else
-				// This inset has no own color, but inherits a color
-				return background_color;
-		}
 	}
+
+	if (background_color == Color_none)
+		// This inset has no own color and does not inherit a color
+		return Color_background;
+
+	// This inset has no own color, but inherits a color
+	return background_color;
 }
 
 
diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h
index 717a5b0..1e24779 100644
--- a/src/MetricsInfo.h
+++ b/src/MetricsInfo.h
@@ -107,11 +107,11 @@ public:
 	void draw(int x, int y, char_type c);
 	///
 	void draw(int x, int y, docstring const & str);
-	/// Determines the background color for the specified inset based on the
+	/// Determines the background color based on the
 	/// selection state, the background color inherited from the parent inset
-	/// and the inset's own background color.
+	/// and the inset's own background color (if one is specified).
 	/// \param sel whether to take the selection state into account
-	ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
+	ColorCode backgroundColor(Inset const * inset = nullptr, bool sel = true) const;
 
 	/// Determines the text color based on the intended color, the
 	/// change tracking state and the selection state.
diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp
index 6c60e0b..3a2a9a5 100644
--- a/src/insets/InsetCollapsible.cpp
+++ b/src/insets/InsetCollapsible.cpp
@@ -336,7 +336,7 @@ void InsetCollapsible::draw(PainterInfo & pi, int x, int y) const
 			int w = 0;
 			int a = 0;
 			int d = 0;
-			Color const col = pi.full_repaint ? Color_none : pi.backgroundColor(this);
+			Color const col = pi.full_repaint ? Color_none : pi.backgroundColor();
 			theFontMetrics(font).rectText(buttonLabel(bv), w, a, d);
 			int const ww = max(textdim.wid, w);
 			pi.pain.rectText(x + (ww - w) / 2, y + desc + a,
diff --git a/status.23x b/status.23x
index 1e2bcdd..0cf0443 100644
--- a/status.23x
+++ b/status.23x
@@ -50,6 +50,8 @@ What's new
 
 - Ask to save hidden dirty documents (bug 11405).
 
+- Fix background color of collapsible insets with sublabel.
+
 
 * INTERNALS
 


More information about the lyx-cvs mailing list