Moved text writing to util

This commit is contained in:
Christian Colglazier 2020-09-11 13:15:10 -04:00
parent 6cdbf33d21
commit 91a31ecd9d
4 changed files with 29 additions and 7 deletions

View File

@ -45,14 +45,12 @@ std::string Menu::FilterMenuText(int position) {
} }
void Menu::CreateMenuItem(std::string text, int position, bool highlighted) { void Menu::CreateMenuItem(std::string text, int position, bool highlighted) {
char* cstr = &text[0];
text.insert(text.end(), MAX_CHAR_LENGTH-text.size(), ' '); text.insert(text.end(), MAX_CHAR_LENGTH-text.size(), ' ');
patch->display.SetCursor(MENU_X[position-1], MENU_Y[position-1]);
if (highlighted) { if (highlighted) {
DrawSolidRect(*patch, 0, MENU_Y[2], SSD1309_WIDTH, MENU_Y[2]+17, true); DrawSolidRect(*patch, 0, MENU_Y[2], SSD1309_WIDTH, MENU_Y[2]+17, true);
patch->display.WriteString(cstr, Font_11x18, !highlighted); WriteString(*patch, MENU_X[position-1], MENU_Y[position-1], Font_11x18, text, !highlighted);
} else { } else {
patch->display.WriteString(cstr, Font_7x10, !highlighted); WriteString(*patch, MENU_X[position-1], MENU_Y[position-1], Font_7x10, text, !highlighted);
} }
} }

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
#ifndef CASCADE_MENU_H_
#define CASCADE_MENU_H_
#include "daisy_patch.h" #include "daisy_patch.h"
#include "util.h" #include "util.h"
@ -21,3 +24,5 @@ class Menu {
void UpdateMenuPosition(); void UpdateMenuPosition();
std::string SelectedName(); std::string SelectedName();
}; };
#endif // CASCADE_MENU_H_

View File

@ -11,8 +11,20 @@ void DrawSolidRect(DaisyPatch patch,
} }
} }
void WriteString(DaisyPatch patch, int x, int y, FontDef font, std::string text) { void WriteString(DaisyPatch patch,
int x,
int y,
FontDef font,
std::string text,
bool on) {
patch.display.SetCursor(x, y); patch.display.SetCursor(x, y);
char* cstr = &text[0]; patch.display.WriteString(&text[0], font, on);
patch.display.WriteString(cstr, font, true); }
void WriteString(DaisyPatch patch,
int x,
int y,
FontDef font,
std::string text) {
WriteString(patch, x, y, font, text, true);
} }

View File

@ -16,6 +16,13 @@ void DrawSolidRect(DaisyPatch,
uint8_t, uint8_t,
bool); bool);
void WriteString(DaisyPatch,
int,
int,
FontDef,
std::string,
bool);
void WriteString(DaisyPatch, void WriteString(DaisyPatch,
int, int,
int, int,