[LyX/master] Make graĥics and external insets tighter

Jean-Marc Lasgouttes lasgouttes at lyx.org
Wed Jan 15 14:43:28 UTC 2020


commit ba79a4b89e1dd3c3bf5fc6cf69281593e1e40356
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Wed Jan 15 15:54:47 2020 +0100

    Make graĥics and external insets tighter
    
    Now RenderGraphics adds offsets that depends on its parent inset.
    
    These offsets are set to 0 for InsetGraphics and InsetExternal. A nice
    consequence is that icons shown by Info inset stick out less on screen.
    
    As an unrelated change, the "private:" specifier of these two insets
    is moved to a more reasonable place.
---
 src/insets/InsetExternal.h   |   18 +++++++++++++++---
 src/insets/InsetGraphics.h   |   21 ++++++++++++++++-----
 src/insets/RenderGraphic.cpp |   11 ++++++-----
 src/insets/RenderGraphic.h   |    3 +++
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h
index 20ccfed..eefce3a 100644
--- a/src/insets/InsetExternal.h
+++ b/src/insets/InsetExternal.h
@@ -120,13 +120,20 @@ public:
 	///
 	void addToToc(DocIterator const & di, bool output_active,
 				  UpdateType utype, TocBackend & backend) const;
-private:
-	///
-	InsetExternal(InsetExternal const &);
 	///
 	InsetCode lyxCode() const { return EXTERNAL_CODE; }
 	///
 	bool hasSettings() const { return true; }
+
+	///
+	int topOffset(BufferView const *) const { return 0; }
+	///
+	int bottomOffset(BufferView const *) const { return 0; }
+	///
+	int leftOffset(BufferView const *) const { return 0; }
+	///
+	int rightOffset(BufferView const *) const { return 0; }
+
 	///
 	void metrics(MetricsInfo &, Dimension &) const;
 	///
@@ -159,6 +166,11 @@ private:
 	 *  and the preview should be regenerated.
 	 */
 	void fileChanged() const;
+
+private:
+	///
+	InsetExternal(InsetExternal const &);
+
 	/// Is this inset using (instant or graphics) preview?
 	bool isPreviewed() const;
 	/// Do we have the right renderer (button, graphic or monitored preview)?
diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h
index 22d70b2..be4a317 100644
--- a/src/insets/InsetGraphics.h
+++ b/src/insets/InsetGraphics.h
@@ -61,13 +61,8 @@ public:
 	/// 
 	InsetGraphics const * asInsetGraphics() const { return this; }
 
-private:
-	///
-	InsetGraphics(InsetGraphics const &);
-
 	///
 	bool isLabeled() const { return true; }
-	void metrics(MetricsInfo &, Dimension &) const;
 	///
 	bool hasSettings() const { return true; }
 	///
@@ -96,6 +91,18 @@ private:
 	docstring layoutName() const { return from_ascii("Graphics"); }
 	/// Get the inset parameters, used by the GUIndependent dialog.
 	InsetGraphicsParams const & params() const;
+
+	///
+	int topOffset(BufferView const *) const { return 0; }
+	///
+	int bottomOffset(BufferView const *) const { return 0; }
+	///
+	int leftOffset(BufferView const *) const { return 0; }
+	///
+	int rightOffset(BufferView const *) const { return 0; }
+
+	///
+	void metrics(MetricsInfo &, Dimension &) const;
 	///
 	void draw(PainterInfo & pi, int x, int y) const;
 	///
@@ -136,6 +143,10 @@ private:
 	///
 	OutputParams::CtObject CtObject(OutputParams const &) const { return OutputParams::CT_OBJECT; }
 
+private:
+	///
+	InsetGraphics(InsetGraphics const &);
+
 	///
 	InsetGraphicsParams params_;
 	/// holds the entity name that defines the graphics location (SGML).
diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp
index fe2d9b9..280a657 100644
--- a/src/insets/RenderGraphic.cpp
+++ b/src/insets/RenderGraphic.cpp
@@ -36,14 +36,14 @@ namespace lyx {
 
 
 RenderGraphic::RenderGraphic(Inset const * inset)
-	: loader_(inset->buffer().fileName())
+	: inset_(inset), loader_(inset->buffer().fileName())
 {
 	loader_.connect(bind(&Inset::updateFrontend, inset));
 }
 
 
 RenderGraphic::RenderGraphic(RenderGraphic const & other, Inset const * inset)
-	: RenderBase(other), loader_(other.loader_), params_(other.params_)
+	: RenderBase(other), inset_(inset), loader_(other.loader_), params_(other.params_)
 {
 	loader_.connect(bind(&Inset::updateFrontend, inset));
 }
@@ -147,7 +147,8 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
 
 	bool const image_ready = displayGraphic(params_) && readyToDisplay(loader_);
 	if (image_ready) {
-		dim.wid = loader_.image()->width() + 2 * Inset::textOffset(mi.base.bv);
+		dim.wid = loader_.image()->width() + inset_->leftOffset(mi.base.bv)
+			+ inset_->rightOffset(mi.base.bv);
 		dim.asc = loader_.image()->height();
 		dim_ = dim;
 		return;
@@ -190,9 +191,9 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
 {
 	// This will draw the graphics. If the graphics has not been
 	// loaded yet, we draw just a rectangle.
-	int const x1 = x + Inset::textOffset(pi.base.bv);
+	int const x1 = x + inset_->leftOffset(pi.base.bv);
 	int const y1 = y - dim_.asc;
-	int const w = dim_.wid - 2 * Inset::textOffset(pi.base.bv);
+	int const w = dim_.wid - inset_->leftOffset(pi.base.bv) - inset_->rightOffset(pi.base.bv);
 	int const h = dim_.height();
 
 	if (displayGraphic(params_) && readyToDisplay(loader_))
diff --git a/src/insets/RenderGraphic.h b/src/insets/RenderGraphic.h
index da09c4c..37f3aaa 100644
--- a/src/insets/RenderGraphic.h
+++ b/src/insets/RenderGraphic.h
@@ -45,6 +45,9 @@ private:
 	/// Not implemented.
 	RenderGraphic & operator=(RenderGraphic const &);
 
+	/// Reference to owner
+	Inset const * inset_;
+
 	/// The stored data.
 	graphics::Loader loader_;
 	graphics::Params params_;


More information about the lyx-cvs mailing list