so if you have a notched ruler attached to a slide and a light that shone through the gap and a light detector to sense the teeth you have an elementary optical linear encoder.
They had these 50 years ago.
Now it is all digital and they use very fine patterns on film so you can get fine resolution.