Direct observation of protein folding in nanoenvironments using a molecular ruler.