]> git.lyx.org Git - features.git/commitdiff
Make graĥics and external insets tighter
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 15 Jan 2020 14:54:47 +0000 (15:54 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:51 +0000 (15:48 +0200)
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
src/insets/InsetGraphics.h
src/insets/RenderGraphic.cpp
src/insets/RenderGraphic.h

index 20ccfededf32a0fcd368553450a9beb9f02b0ad9..eefce3a10d52d8f309a9151831aace0b26ca2eaf 100644 (file)
@@ -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)?
index 22d70b233b666d6e271cb229f48303d719d761ff..be4a31773ada009df95bac9eedfcfbaa50fd3f6b 100644 (file)
@@ -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).
index fe2d9b9eb4d97fb02e3b75fd6a138223d567ceb1..280a657ceb61ac0490c48230bddaec5046518937 100644 (file)
@@ -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_))
index da09c4cc0faefe0f6229b09efbfed4b136bf099d..37f3aaaa93cb84f02f3d76569fe40f33d68042ee 100644 (file)
@@ -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_;