constrain between 0 and total size