I'm not sur it's giving a best result, but an idee was to evalue the side to scroll the rectangle based on the position rectangle when the input is start pressing (I never try this type of movement in a game, so I'm not sur it can work beter or not).