I'm creating a GUI to run on a STM32F429 microcontroller, it is written in C.
The problem I'm having is how to manage scrolling for a text view. I have a data buffer with ASCII characters and I want to manage the newline character (\n, ASCII code 10) so that it will give a new line in the text box.
Here is a small example of the buffer when scrolling back one row, no scrolling and scrolling forward one row: http://i.stack.imgur.com/4eK7w.png. The green box is the start pointer and the red box is the end pointer. The blue boxes show a row of text (6 characters max).
Scroll forward one row:
This one is quite easy.
- Move start pointer to after the next "\n" char or 6 positions (whatever comes first).
- Move end pointer to the next "\n" char or 6 positions (whatever comes first).
Scroll back one row:
This is the one I'm having trouble with.
- If we don't encounter a newline while moving the start pointer back we can move it 6 positions without trouble.
- If the current end pointer is not a newline "\n" we can move it back 6 positions but if it is we run into trouble.
By looking at the table it's easy to see that the start pointer needs to move 2 steps and the end pointer 5 steps and I think it's because we can see all the data (i.e. we know about the past and the future). But does that mean we have to go trough all the previous data to know where the rows are located?
If anyone has any ideas on how to solve this I would be very thankful!
EDIT: Added another example image: http://i.stack.imgur.com/FKCNg.png