diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-12-20 00:21:09 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-12-20 00:21:09 +0100 |
| commit | 92aab607b238d41c4b33f0920ca36fa5454bf323 (patch) | |
| tree | 1872f2a4e84e06ebf6e296fb6c7e7abdef0e7344 /src/css/layout.nim | |
| parent | 84ad5010cd955796238407ae767c9ba239683db6 (diff) | |
| download | chawan-92aab607b238d41c4b33f0920ca36fa5454bf323.tar.gz | |
layout, render: image sizing fixes/workarounds
* fix clip for image
* switch back img's display to inline
* fix image width calculation without specified width/height
I'm not 100% sure if this is correct, but it certainly looks better.
Diffstat (limited to 'src/css/layout.nim')
| -rw-r--r-- | src/css/layout.nim | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim index 2316c23c..53ffcdce 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -1650,13 +1650,15 @@ proc addImage(ictx: var InlineContext; state: var InlineState; if computed{"max-width"}.canpx(ictx.space.w): let w = computed{"max-width"}.spx(ictx.space.w, computed, padding) atom.size.w = min(atom.size.w, w) - if computed{"min-width"}.canpx(ictx.space.w): + let hasMinWidth = computed{"min-width"}.canpx(ictx.space.w) + if hasMinWidth: let w = computed{"min-width"}.spx(ictx.space.w, computed, padding) atom.size.w = max(atom.size.w, w) if computed{"max-height"}.canpx(ictx.space.h): let h = computed{"max-height"}.spx(ictx.space.h, computed, padding) atom.size.h = min(atom.size.h, h) - if computed{"min-height"}.canpx(ictx.space.h): + let hasMinHeight = computed{"min-height"}.canpx(ictx.space.h) + if hasMinHeight: let h = computed{"min-height"}.spx(ictx.space.h, computed, padding) atom.size.h = max(atom.size.h, h) if not hasWidth and ictx.space.w.isDefinite(): @@ -1664,7 +1666,8 @@ proc addImage(ictx: var InlineContext; state: var InlineState; if not hasHeight and ictx.space.h.isDefinite(): atom.size.h = min(ictx.space.h.u, atom.size.h) if not hasHeight and not hasWidth: - if osize.w >= osize.h: + if osize.w >= osize.h or + not ictx.space.h.isDefinite() and ictx.space.w.isDefinite(): if osize.w > 0: atom.size.h = osize.h div osize.w * atom.size.w else: @@ -1686,12 +1689,13 @@ proc addImage(ictx: var InlineContext; state: var InlineState; # parent size yet. e.g. <img width=100% ...> with an indefinite containing # size (i.e. the first table cell pass) would resolve to an intr.w of # image.width, stretching out the table to an uncomfortably large size. - if ictx.space.w.t == scStretch or computed{"width"}.u != clPerc and - computed{"min-width"}.u != clPerc: + # The issue is similar with intr.h, which is relevant in flex layout. + # + # So check if any dimension is fixed, and if yes, report the intrinsic + # minimum dimension as that or the atom size (whichever is greater). + if ictx.space.w.t == scStretch or hasWidth or hasMinWidth: ictx.state.intr.w = max(ictx.state.intr.w, atom.size.w) - # Similarly for height, except in this case it happens in flex sizing. - if computed{"height"}.canpx(ictx.space.h) or - computed{"min-height"}.canpx(ictx.space.h): + if ictx.space.h.t == scStretch or hasHeight or hasMinHeight: ictx.lbstate.intrh = max(ictx.lbstate.intrh, atom.size.h) proc layoutInline(ictx: var InlineContext; fragment: InlineFragment) = |