-
-
Notifications
You must be signed in to change notification settings - Fork 889
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
Add support for auto horizontal margins #879
Add support for auto horizontal margins #879
Conversation
7da128c
to
b15a6bf
Compare
lib/html_parser.dart
Outdated
if(style.margin?.isAutoHorizontal ?? false) { | ||
return Row( | ||
mainAxisAlignment: style.margin?.alignment ?? MainAxisAlignment.start, | ||
children: [Flexible(child: container)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly doesn't seem to work with images - any advice on what I need to change to support this? Would applying the same wrapper in |
Sorry for the ping @erickok but do you have any feedback here and/or any advice for the best way I can make this work for inline images as well? |
This isn't so easy to achieve I suspect but I haven't had time to take a deep dive into it due to time limitations on my side. |
I managed to get it working for images as well with a few tweaks: Turns out there was a bug in the image renderer which wasn't passing the correct context (and, hence, styles) to the image which I have pull requested separately as #886 |
7fc13e6
to
3aa9b0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also when #924 is merged, there will likely be conflicts to resolve, you should be able to use the same approach as an extension on EdgeInsets
to ensure non-negative values.
3d961b4
to
822d16e
Compare
Have rebased on latest master. |
The Dart auto-formatter seems to have been a bit aggressive - is there a custom print-width I need to use or something to avoid the extra unnecessary diffs? |
Unfortunaly over time we seem to have used different formatting standards (including line width) and I fear any application of a since format now would cause code changes. We should really do that one time. |
Yeah the formatter did go a bit crazy, especially in the most recent commit. I would suggest turning off auto format in VSCode and either clearing the current branch of its changes, or creating a new PR with the core changes (formatting left out). Also this would be a breaking change in our library API as the |
@zbarbuto due to all changes from the customRender PR, there are conflicts that need to be resolved now, just FYI |
@tneotia No problems. Please leave this PR open for now and hopefully I'll have some time this week rebase on master without the auto-format changes rather than make a new one. |
822d16e
to
549600f
Compare
@tneotia Ok I've cleaned the diffs and fixes a few issues that were inconsistent with normal HTML behaviour. The demo has been updated to show these edge-cases: I previously was always center-aligning images that had |
549600f
to
e47936b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit, otherwise LGTM!
e47936b
to
735451c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work! Hopefully we can include this in the massively breaking v3.0.0... I also anticipate you'll have to do yet another rebase of this branch once #661 is merged...
Allow centering images with auto-margins
735451c
to
c5f396d
Compare
I have rebased and applied my changes. There is an issue that has come up after rebase in that divs are not displaying as block-level correctly which breaks their alignment (see the coloured examples below): For now, I am considering fixing this outside the scope of this pull request as it is currently broken on master anyway. i.e. the following: <div style="width: 150px; height: 20px; background-color: #ff9999;">Div A</div>
<div style="width: 150px; height: 20px; background-color: #99ff99;">Div B</div>
<div style="width: 150px; height: 20px; background-color: #ff99ff;">Div C</div> Renders in a blank project using But in regular HTML e.g. in a CodePen as: If this issue is fixed independently the alignment feature of this pull request should work as expected. |
@tneotia sorry for the ping but anything further I need to do on this since it has been rebased? I can create a separate issue for the block display problem above? |
Sure I would create a separate issue. I don't think anything more needs to be done, just @erickok needs to review. |
|
||
bool get isAutoHorizontal => (left is AutoMargin) || (right is AutoMargin); | ||
|
||
Alignment? get alignment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where we're going with this PR, but I'm not sure how I feel about the margin class handling its own alignment. I'm sure there are edge cases where these alignments don't hold true.
For now, can we move this alignment calculation outside of the Margins class?
I'm also going to look into how the w3 says renderers should handle auto margins for inspiration.
Thank you!
Merging this into a new branch |
Adds support for
margin: auto
style centering.A pretty common centering pattern in HTML/CSS is to give a left and right margin value of
auto
. Further, some WYSIWYG editors that output HTML will use this to center content like images instead of text-align.As a basic example:
Typically renders as (screenshot is from Chrome):
This PR adds support for
margin: auto
by changing margin storage from plainEdgeInsets
to a newMargins
class which wrapsleft
,top
,right
, andbottom
Margin
values. This allows storing a rawdouble
value
as before but also to flag the particular edge asauto
allowing it to be wrapped in a Row to center it if needed.I have updated the example project with a few samples:
Both of which now render as expected (screenshot is on an iPad):
FTR I assume
ContainerSpan
forms the wrapper for most elements so this would also make it work for things likeimg
?