| Title | Implement margin auto |
|---|---|
| Author | campaul |
| Created | Thu, 29 May 2025 19:39:00 +0000 |
| State | open |
Fix for #67
This still needs more tests and documentation before it's ready to go but I wanted to post the PR to start getting feedback as early as possible. This is a big change so I expect it will end up needing many revisions.
Some changes that were made as prerequisites:
style.margin is now a length instead of just a valuemarginLeft, marginRight, marginTop, and marginBottom functions for converting back to a value. Percent and auto are treated as 0 by this function.boxOffsetX, boxRestWidth, and boxDiffWidth are moved from style to widget under the names marginBoxOffsetX, marginBoxRestWidth, and marginBoxDiffWidth.margin field is added to the Widget class.The main logic is as follows:
calcWidth computes margin widths and returns a BoxWidth struct that contains the computed margin sizes instead of just the total size.calcFinalWidth sets widget.margin.left and widget.margin.right based on what it picked as the final size.marginBoxOffsetX, marginBoxRestWidth, and marginBoxDiffWidth functions use the saved widget.margin values instead of style.margin values.This works because getAvailableWidth is always called before any of boxOffsetX, boxRestWidth or boxDiffWidth. This means calcFinalWidth is guaranteed to have already run.
The margin auto test passing
The dillo website correctly centered now
Thanks a lot for the effort! I will check the implementation when I have a moment, what you describe sounds reasonable.
So far I see that with fca573fa0b3c2654f2ca178aa6556394f52be2a8 the page https://dillo-browser.github.io/25-years/index.html extends the width ignoring the max-width constraint. Can we add another test case so we prevent future regressions?