rm-hull / luma.oled

Python module to drive a SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106 OLED
https://luma-oled.readthedocs.io
MIT License
807 stars 161 forks source link

How to horizontally scroll a single line of text? #333

Closed EDIflyer closed 2 years ago

EDIflyer commented 3 years ago

I've had a search through the various examples and can see ones for scrolling text up a whole screen, moving items around a screen, etc. but I'm a bit stumped as to how to scroll an individual line of text!

For context - I've got a menu system and one of those items displays a list of files in a directory. I've got it sorted for the user to move up and down through the list, but unsurprisingly some of the filenames are too long to fit on the 128x64 screen! My idea would be that when the user has moved the cursor to that line of text then it will scroll, but that the rest of the screen will remain unchanged. I've got a progress bar down the right hand side of the screen too so would want to keep the text from going over that (e.g. perhaps only use 118px or so of horizontal space and scroll the text within that). I'm think of the kind of thing that DAB radios too - slowly scroll the track name backwards and forwards.

EDIflyer commented 2 years ago

Resolved by checking text string width in pixels then iterating and moving x-position for the text negatively. Not sure if it was the neatest solution but seems to work!