Merge pull request #608 from PixelPirate/scroll-indicator

Add a scrolling indicator thanks to @PixelPirate
This commit is contained in:
Ben V. Brown
2020-04-17 11:05:29 +10:00
committed by GitHub
3 changed files with 33 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ extern "C" {
#endif
#define DEVICEADDR_OLED (0x3c<<1)
#define OLED_WIDTH 96
#define OLED_HEIGHT 16
#define FRAMEBUFFER_START 17
class OLED {
@@ -99,6 +100,7 @@ public:
static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
bool clear);
static void drawHeatSymbol(uint8_t state);
static void drawScrollIndicator(uint8_t p, uint8_t h); // Draws a scrolling position indicator
private:
static void drawChar(char c); // Draw a character to a specific location
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer

View File

@@ -106,6 +106,25 @@ void OLED::drawChar(char c) {
cursor_x += fontWidth;
}
/*
* Draws a one pixel wide scrolling indicator. y is the upper vertical position
* of the indicator in pixels (0..<16).
*/
void OLED::drawScrollIndicator(uint8_t y, uint8_t height) {
union u_type {
uint16_t whole;
uint8_t strips[2];
} column;
column.whole = (1 << height) - 1;
column.whole <<= y;
// Draw a one pixel wide bar to the left with a single pixel as
// the scroll indicator.
fillArea(OLED_WIDTH - 1, 0, 1, 8, column.strips[0]);
fillArea(OLED_WIDTH - 1, 8, 1, 8, column.strips[1]);
}
void OLED::setRotation(bool leftHanded) {
#ifdef MODEL_TS80
leftHanded = !leftHanded;

View File

@@ -264,6 +264,8 @@ static void printShortDescription(uint32_t shortDescIndex,
// prepare cursor for value
OLED::setFont(0);
OLED::setCharCursor(cursorCharPosition, 0);
// make room for scroll indicator
OLED::setCursor(OLED::getCursorX() - 2, 0);
}
static int userConfirmation(const char *message) {
@@ -782,7 +784,8 @@ static void displayMenu(size_t index) {
OLED::print(SettingsMenuEntries[index]);
// Draw symbol
// 16 pixel wide image
OLED::drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index]));
// 2 pixel wide scrolling indicator
OLED::drawArea(96 - 16 - 2, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index]));
}
static void settings_displayCalibrateVIN(void) {
@@ -823,6 +826,11 @@ void gui_Menu(const menuitem *menu) {
int16_t lastOffset = -1;
bool lcdRefresh = true;
ButtonState lastButtonState = BUTTON_NONE;
uint8_t scrollContentSize = 0;
for (uint8_t i = 0; menu[i].draw.func != NULL; i++) {
scrollContentSize += 1;
}
while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) {
OLED::setFont(0);
@@ -833,6 +841,9 @@ void gui_Menu(const menuitem *menu) {
|| menu[currentScreen].description == NULL) {
OLED::clearScreen();
menu[currentScreen].draw.func();
uint8_t indicatorHeight = OLED_HEIGHT / scrollContentSize;
uint8_t position = currentScreen * indicatorHeight;
OLED::drawScrollIndicator(position, indicatorHeight);
lastOffset = -1;
lcdRefresh = true;
} else {