From 2822dbed8b2011aa02cf43fc2f40d25e4950911f Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 22 May 2024 16:56:20 +0200 Subject: layout, layoutunit: remove some automatic converters I wish we didn't need any, but fixing this for integers would be too involved and the float64 one was causing problems now. --- src/layout/engine.nim | 9 +++++---- src/layout/layoutunit.nim | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src/layout') diff --git a/src/layout/engine.nim b/src/layout/engine.nim index a388f999..179714cd 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -2014,7 +2014,7 @@ proc redistributeWidth(ctx: var TableContext) = weight = 0 for i in countdown(avail.high, 0): let j = avail[i] - let x = unit * ctx.cols[j].weight + let x = (unit * ctx.cols[j].weight).toLayoutUnit() let mw = ctx.cols[j].minwidth ctx.cols[j].width = x if mw > x: @@ -2197,8 +2197,9 @@ proc redistributeMainSize(mctx: var FlexMainContext; sizes: ResolvedSizes; var totalWeight = mctx.totalWeight[wt] while (wt == fwtGrow and diff > 0 or wt == fwtShrink and diff < 0) and totalWeight > 0: - mctx.maxSize[odim] = 0 # redo maxSize calculation; we only need height here - let unit = diff / totalWeight + # redo maxSize calculation; we only need height here + mctx.maxSize[odim] = 0 + let unit = diff.toFloat64() / totalWeight # reset total weight & available diff for the next iteration (if there is # one) totalWeight = 0 @@ -2208,7 +2209,7 @@ proc redistributeMainSize(mctx: var FlexMainContext; sizes: ResolvedSizes; if it.weights[wt] == 0: mctx.updateMaxSizes(it.child) continue - var u = it.child.size[dim] + unit * it.weights[wt] + var u = it.child.size[dim] + (unit * it.weights[wt]).toLayoutUnit() # check for min/max violation var minu = it.sizes.minMaxSizes[dim].min if dim == dtHorizontal: diff --git a/src/layout/layoutunit.nim b/src/layout/layoutunit.nim index 777e58d7..8ec3e4a3 100644 --- a/src/layout/layoutunit.nim +++ b/src/layout/layoutunit.nim @@ -29,13 +29,10 @@ func toInt*(a: LayoutUnit): int = converter toLayoutUnit*(a: int32): LayoutUnit = return LayoutUnit(a shl 6) -converter toLayoutUnit*(a: int64): LayoutUnit = - return toLayoutUnit(cast[int32](a)) - converter toLayoutUnit*(a: int): LayoutUnit = return toLayoutUnit(cast[int32](a)) -converter toLayoutUnit*(a: float64): LayoutUnit = +func toLayoutUnit*(a: float64): LayoutUnit = if unlikely(a == Inf): return LayoutUnit(high(int32)) elif unlikely(a == -Inf): -- cgit 1.4.1-2-gfad0