pub fn meter_fill(cells: u32, filled: u32, of: u32) -> u32Expand description
How many of a meter’s cells are full when it shows filled of of.
The rule every meter shares: cells × filled / of rounded half up, but
a meter that is not empty (filled > 0) shows at least one full cell
and one that is not full (filled < of) at least one empty cell, so
“almost dead” and “almost full” never look like “dead” and “full”. With
one cell, the rounding alone decides. filled past of counts as
of; an of of 0 is an empty meter.
use shuyi_ui::frame::draw::meter_fill;
assert_eq!(meter_fill(10, 1, 100), 1); // 0.1 would round to 0
assert_eq!(meter_fill(10, 99, 100), 9); // 9.9 would round to 10
assert_eq!(meter_fill(10, 25, 100), 3); // 2.5 rounds up