Skip to content

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