Giter Site home page Giter Site logo

Comments (9)

frozolotl avatar frozolotl commented on May 21, 2024 1

I'm referring to most methods in svg::node::element.
It would allow writing for example:

let mut document = Document::new();
if cond {
    document.add();
}

from svg.

MichaelMauderer avatar MichaelMauderer commented on May 21, 2024 1

I just ran into the same issue. So I'm just here to pile on.

I have a wrapper struct that is meant to hold a Document and manipulate it.
Since add takes the Document by value, this means that a cumbersome dance with Options or mem::replace is needed to make this work.

Example:

struct SVGRenderer {
    document: Document,
}

impl SVGRenderer {
    pub fn new() -> Self {
        SVGRenderer {
            document: Document::new(),
        }
    }

    fn add_to_doc<T: Node>(&mut self, obj: T) {
        self.document = mem::replace(&mut self.document, Document::new()).add(obj);
    }
}

impl Renderer for SVGRenderer {
    fn draw_point(&mut self, p: &Point) {
        let circle = Circle::new()
            .set("cx", p.pos.x)
            .set("cy", p.pos.y)
            .set("r", p.radius)
            .set("stroke", "black")
            .set("stroke-width", 1);
        // Can't do self.document.add(circle)
        // Neither self.document = self.document.add(circle)
        // Needs to be something like this
        self.document = mem::replace(&mut self.document, Document::new()).add(obj);
    }
} 

from svg.

IvanUkhov avatar IvanUkhov commented on May 21, 2024

Could you please be more specific? Which methods are you referring to?

from svg.

IvanUkhov avatar IvanUkhov commented on May 21, 2024

I think it’s a good suggestion. I’ve tagged it as “feedback needed” to see if there are other opinions so that we don’t miss anything. If you have time, please feel free to open a pull request.

from svg.

IvanUkhov avatar IvanUkhov commented on May 21, 2024

Let us continue this discussion in #23. I need your input. Thanks!

from svg.

IvanUkhov avatar IvanUkhov commented on May 21, 2024

@MichaelMauderer, by the way, in your example, would it not work with append?

from svg.

IvanUkhov avatar IvanUkhov commented on May 21, 2024

@frozolotl, can’t append help you too?

from svg.

MichaelMauderer avatar MichaelMauderer commented on May 21, 2024

Actually, it does! I had completly missed that function. Thanks for pointing it out.

from svg.

IvanUkhov avatar IvanUkhov commented on May 21, 2024

I park it for now, as add and set are accompanied by append and assign, respectively.

from svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.