Skip to content
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

Update Layout without creating from scratch #67

Closed
miquik opened this issue Nov 16, 2021 · 3 comments
Closed

Update Layout without creating from scratch #67

miquik opened this issue Nov 16, 2021 · 3 comments

Comments

@miquik
Copy link

miquik commented Nov 16, 2021

Hi,
There is a way to update layout (recalculate boxes position/size when viewport is resized for example), without creating layout from scratch? Usually CSS styles and fonts doesn't change, so (for example) creating a VisualContext every time size is changed it seems a little expensive for me.

Another question related to this one: could I recalculate only a "part" of document tree? Just a subtree for example?

Thanks

@radkovo
Copy link
Owner

radkovo commented Nov 21, 2021

CSSBox was originally designed primarily for one-time rendering so that page re-rendering was actually never thoroughly tested. But in theory, for re-rendering the page, the following approach should work:

Viewport viewport = engine.getViewport();
viewport.doLayout(canvasWidth, true, true); // canvasWidth is the new canvas width
viewport.absolutePositions(); // re-compute absolute positions of sub-boxes

Similarly, a subtree rooted with a BlockBox can be theoretically recomputed like this:

BloxBox root = ... // the subtree root block box
root.doLayout(root.getAvailableContentWidth(), true, true);
root.absolutePositions()

The size of the root block itself is not recomputed. Therefore, if some element changes, I would do this for its containing block (nearest block ancestor).

@miquik
Copy link
Author

miquik commented Nov 21, 2021

Thanks a lot I will try

@miquik miquik closed this as completed Nov 21, 2021
@Osiris-Team
Copy link

Osiris-Team commented Feb 22, 2023

@radkovo Doesn't work for me. Is the root returned by DOMAnalyzer a temporary/copy representation and not the original that gets rendered? Because I modified it and tried to re-render, but the changes were not shown.

Also another question. I assume there is no support for animations then? Or animations based on input, like a mouse hover for example?

Here is the code I am working with: https://github.com/Osiris-Team/Desku/blob/ccsbox/src/test/java/com/osiris/desku/cssbox/CssBoxTest.java

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

No branches or pull requests

3 participants