starlit  Diff

Differences From Artifact [3edc02f291]:

To Artifact [43eaf4251e]:


    38     38   		{12, 'T', 'tera',  true,  'p', 'pico',  true};
    39     39   		{9, 'G', 'giga',   true,  'n', 'nano',  true};
    40     40   		{6, 'M', 'mega',   true,  'μ', 'micro', true};
    41     41   		{3, 'k', 'kilo',   true,  'm', 'milli', true};
    42     42   		{2, 'h', 'hecto',  false, 'c', 'centi', true};
    43     43   		{1, 'da','deca',   false, 'd', 'deci',  false};
    44     44   	}
           45  +
           46  +	local function unitForAmt(n)
           47  +		if type(unit)=='table' then
           48  +			if n == 1
           49  +				then return unit[1]
           50  +				else return unit[2]
           51  +			end
           52  +		end
           53  +		return unit
           54  +	end
           55  +
    45     56   	for i, s in ipairs(scales) do
    46     57   		local amt, smaj, pmaj, cmaj,
    47     58   		           smin, pmin, cmin = lib.tbl.unpack(s)
           59  +
    48     60   
    49     61   		if math.abs(val) > 1 then
    50     62   			if uncommonScales or cmaj then
    51     63   				local denom = 10^amt
    52     64   				local vd = val/denom
    53     65   				if prec then vd = lib.math.trim(vd, prec) end
    54     66   				if math.abs(val) >= (10^(amt)) then
    55     67   					return string.format("%s%s%s",
    56         -						vd, (full and (' ' .. pmaj) or smaj), unit)
           68  +						vd, (full and (' ' .. pmaj) or smaj), unitForAmt(vd))
    57     69   				end
    58     70   			end
    59     71   		elseif math.abs(val) < 1 then
    60     72   			if uncommonScales or cmin then
    61     73   				local denom = 10^-amt
    62     74   				local vd = val/denom
    63     75   				if prec then vd = lib.math.trim(vd, prec) end
    64     76   				if math.abs(val) <= (10^-(amt-1)) then
    65     77   					return string.format("%s%s%s",
    66         -						vd, (full and (' ' .. pmin) or smin), unit)
           78  +						vd, (full and (' ' .. pmin) or smin), unitForAmt(vd))
    67     79   				end
    68     80   			end
    69     81   		end
    70     82   	end
    71     83   
    72         -	return string.format("%s%s", val, unit)
           84  +	return string.format("%s%s", val, unitForAmt(val))
    73     85   end
           86  +function fn.siUI(u,v,f,us,...) return fn.si(u,v,f,us,2,...) end
    74     87   
    75     88   function fn.lerp(t, a, b) return (1-t)*a + t*b end
    76     89   function fn.gradient(grad, pos)
    77     90   	local n = #grad
    78     91   	if n == 1 then return grad[1] end
    79     92   	local op = pos*(n-1)
    80     93   	local idx = math.floor(op)