The always-hot wire from the receptacle is spliced to the black wire on the fixture cable, and to a pigtail that connects back to the hot terminal on the receptacle. At the light fixture box, the black is spliced to the black from the switch cable. At the switch box the black wire is connected to the bottom terminal on the new switch.
At the switch, the other end of the black wire is connected to the bottom terminal on the switch and the black wire going to the new light is connected to the top terminal. The white wire from the receptacle is spliced to the white wire going to the light, it doesn’t connect to the switch in this diagram, but a new electronic switch will usually include a neutral wire connection. At the light the black wire connects to the hot terminal on the fixture and the white goes to the neutral terminal.
This page contains wiring diagrams for a service panel breaker box and circuit breakers including: 15amp, 20amp, 30amp and 50amp, as well as a GFCI breaker and an isolated ground circuit.
The white wire on the switch loop is used to carry current from the source to the switch and it is marked with black tape or paint to label it as hot. The black on the switch loop runs from the top switch terminal to the top half of the receptacle. With this arrangement the top half of the duplex is controlled with the switch and the bottom half is always hot.