diff options
Diffstat (limited to 'src/css')
| -rw-r--r-- | src/css/layout.nim | 20 | ||||
| -rw-r--r-- | src/css/render.nim | 8 |
2 files changed, 16 insertions, 12 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) = diff --git a/src/css/render.nim b/src/css/render.nim index 9f869ad9..efaa4910 100644 --- a/src/css/render.nim +++ b/src/css/render.nim @@ -373,20 +373,20 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState; else: let format = fragment.computed.toFormat() for atom in fragment.state.atoms: + let offset = offset + atom.offset case atom.t of iatInlineBlock: - grid.renderBlockBox(state, atom.innerbox, offset + atom.offset) + grid.renderBlockBox(state, atom.innerbox, offset) of iatWord: if fragment.computed{"visibility"} == VisibilityVisible: - grid.setText(state, atom.str, offset + atom.offset, format, - fragment.node) + grid.setText(state, atom.str, offset, format, fragment.node) of iatImage: if fragment.computed{"visibility"} == VisibilityVisible: let x2p = offset.x + atom.size.w let y2p = offset.y + atom.size.h let clipBox = addr state.clipBoxes[^1] #TODO implement proper image clipping - if offset.x < clipBox.send.y and offset.y < clipBox.send.y and + if offset.x < clipBox.send.x and offset.y < clipBox.send.y and x2p >= clipBox.start.x and y2p >= clipBox.start.y: let x1 = offset.x.toInt let y1 = offset.y.toInt |