aboutsummaryrefslogtreecommitdiffstats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-22 16:56:20 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-22 16:56:20 +0200
commit2822dbed8b2011aa02cf43fc2f40d25e4950911f (patch)
tree288c6d02e4bfecd115f30f232ad3383e92c35805 /src/layout
parent1f4560cafd51874ee7a71d1e099e0a1d5a1e4947 (diff)
downloadchawan-2822dbed8b2011aa02cf43fc2f40d25e4950911f.tar.gz
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.
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim9
-rw-r--r--src/layout/layoutunit.nim5
2 files changed, 6 insertions, 8 deletions
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):