Skip to content

Add method update to document #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

mathisloge
Copy link

This is the solution to #259 and I think #69

I don't know if this is the correct solution but I call it whenever I made changes to the document with e.g. doc.create_element.

If this isn't the right changes for this use case, I would be happy to change it accordingly.

@TobiasBohnen
Copy link
Contributor

There are some memory issues:
root's m_css and m_styles aren't cleared and grow on every call to update.
m_root_render->init() adds items to m_renders of the source elements without removing the old ones.

@mathisloge mathisloge closed this Jan 4, 2024
@blafed
Copy link

blafed commented Dec 27, 2024

Not sure why but this didnt work for me. i have figured out another way to do this.

    void doc_retree(const document::ptr &doc)
    {
        // PERF check if it hurts
        doc->m_root_render = doc->m_root->create_render_item(nullptr);

        if (doc->m_root_render)
            doc->m_root_render = doc->m_root_render->init();
    }

    void change_parent(const element::ptr &el, const element::ptr &new_parent)
    {
        document::ptr doc = el->get_document();
        element::ptr old_parent = el->parent();

        if (old_parent)
            old_parent->removeChild(el);
        if (new_parent)
            new_parent->appendChild(el);

        if (old_parent)
            old_parent->compute_styles();
        if (new_parent)
            new_parent->compute_styles();

        doc_retree(doc); // PERF optimize this by request a call that be applied when renderering
    }
instead of using element->appendChild(), you need to use this custom change_parent which will ensure the document render tree is updated after changing a parent of element, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy