aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/css/cssvalues.nim10
-rw-r--r--src/layout/engine.nim9
-rw-r--r--src/layout/layoutunit.nim5
3 files changed, 11 insertions, 13 deletions
diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim
index 8751ba50..ec51e5de 100644
--- a/src/css/cssvalues.nim
+++ b/src/css/cssvalues.nim
@@ -585,18 +585,18 @@ func inherited(t: CSSPropertyType): bool =
return InheritedArray[t]
func em_to_px(em: float64; window: WindowAttributes): LayoutUnit =
- em * float64(window.ppl)
+ (em * float64(window.ppl)).toLayoutUnit()
func ch_to_px(ch: float64; window: WindowAttributes): LayoutUnit =
- ch * float64(window.ppc)
+ (ch * float64(window.ppc)).toLayoutUnit()
# 水 width, we assume it's 2 chars
func ic_to_px(ic: float64; window: WindowAttributes): LayoutUnit =
- ic * float64(window.ppc) * 2
+ (ic * float64(window.ppc) * 2).toLayoutUnit()
# x-letter height, we assume it's em/2
func ex_to_px(ex: float64; window: WindowAttributes): LayoutUnit =
- ex * float64(window.ppc) / 2
+ (ex * float64(window.ppc) / 2).toLayoutUnit()
func px*(l: CSSLength; window: WindowAttributes; p: LayoutUnit): LayoutUnit
{.inline.} =
@@ -927,7 +927,7 @@ func parseANSI(value: openArray[CSSComponentValue]): Opt[CellColor] =
return err()
let tok = CSSToken(value[i])
if tok.tokenType == cttNumber:
- if tok.nvalue notin 0..255:
+ if tok.tflagb != tflagbInteger or int(tok.nvalue) notin 0..255:
return err() # invalid numeric ANSI color
return ok(ANSIColor(tok.nvalue).cellColor())
elif tok.tokenType == cttIdent:
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):