elm-ui
elm-ui copied to clipboard
Element.modular returns Float but Font.size requires Int
There is a discrepancy between the docs and the implementation for use of Element.modular. The example in the docs is
scaled =
Scale.modular 16 1.25
Font.size (scaled 4) -- 16 * 1.25 ^ (4 - 1) results in 31.25
But this fails as Font.size expects an Int rather than a Float.
I think that changing teh return type will be a breaking change, so this isn't just going to be a bug fix as it would force a new version. Here is my workaround:
scaled : Int -> Int
scaled factor =
let
base = 16
in
if factor > 0 then
base * 1.25^(toFloat(factor-1)) |> round
else if factor == 0 then
base
else -- negative factor
base * 1.25^(toFloat(factor)) |> round
Why not just
scaled : Int -> Int
scaled factor =
Element.modular 16 1.25 factor |> round
I too had the same issue today. the bug it's in the docs, rather than the function.
this is what I used (with help from Manuel Baumann on slack):
scaled fs =
Basics.round (Element.modular 16 1.25 fs)
As you can see, the example in the docs is using partial application but there's no mention of this, hence the confusion.