1 #include <MutilaDebug.h> 2 #include "GfxStringListBox.h" 3 #include "GfxTextBox.h" 4 #include "CheeseboardConfig.h" 6 GfxStringListBox::GfxStringListBox(uint16_t width) :
8 _lineHeight(CBOLED_MESSAGE_FONT_HEIGHT + (2*CBOLED_MESSAGE_FONT_VSEP)),
11 for(uint8_t i=0; i<MaxItems; i++) {
21 GfxStringListBox::~GfxStringListBox()
23 for(uint8_t i=0; i<MaxItems; i++) {
24 if (_items[i] != NULL) {
35 _items[i] =
new String(s);
44 if (idx >= 0 && idx <MaxItems && _items[idx] != NULL) {
49 if (_selected == idx) {
65 DBLN(F(
"GfxStringListBox::draw"));
67 for(uint8_t i=0; i<MaxItems && drawn<_screenLines; i++) {
68 if (_items[i] != NULL) {
85 return _lineHeight * _screenLines;
91 for(i=startAt; i<MaxItems && _items[i] != NULL; i++) {;}
101 for(uint8_t i=from+1; i<MaxItems; i++) {
102 if (_items[i] != NULL) {
111 if (from == 0 || from >= MaxItems) {
115 for(uint8_t i=from-1; i>=0; i--) {
116 if (_items[i] != NULL) {
126 for(i=0; i<MaxItems; i++) {
127 if (*_items[i] == s) {
143 for (uint8_t i=gap+1; i<MaxItems; i++) {
144 if (_items[i] != NULL) {
158 for(uint8_t i=gap; i<MaxItems-1; i++) {
159 _items[i] = _items[i+1];
160 if (i+1 == _selected) {
164 _items[MaxItems-1] = NULL;
171 if (idx >= MaxItems || !(idx == -1 || _items[idx] != NULL)) {
188 uint8_t lines = _screenLines;
189 for (uint8_t i=_screenStart; i<MaxItems && lines>0; i++) {
193 if (_items[i] != NULL) {
203 for (uint8_t i=idx; i<MaxItems; i++) {
204 if (_items[i] != NULL) {
213 uint8_t scrolled = 0;
215 int16_t nextItem =
findNext(_screenStart);
216 if (nextItem == -1) {
219 if (
rowsFrom(nextItem) < _screenLines) {
222 _screenStart = nextItem;
232 uint8_t scrolled = 0;
238 _screenStart = preItem;
247 if (_items[idx] == NULL || idx > MaxItems) {
251 if (idx < _screenStart) {
void compact()
Make used items contiguous (remove gaps)
uint8_t rowsFrom(uint8_t idx)
bool isOnScreen(uint8_t idx)
void compact()
Make used items contiguous (remove gaps)
int16_t findPreceding(uint8_t from=MaxItems)
uint8_t scrollUp(uint8_t rows)
int16_t add(const String s)
uint8_t scrollDown(uint8_t rows)
bool remove(const uint8_t idx, bool compactAfter=true)
int16_t findGap(uint8_t startAt=0)
int16_t findGap(uint8_t startAt=0)
int16_t findNext(uint8_t from=0)
void draw(uint16_t xOffset=0, uint16_t yOffset=0)
bool isCompacted()
Sort the items contained in the list box using quicksort.
int16_t find(const String s, uint8_t n=1)
uint8_t scrollUp(uint8_t rows)
uint8_t rowsFrom(uint8_t idx)
uint8_t scrollDown(uint8_t rows)
int16_t findNext(uint8_t from=0)
bool isOnScreen(uint8_t idx)
bool scrollTo(uint8_t idx)
bool isCompacted()
Sort the items contained in the list box using quicksort.
int16_t findPreceding(uint8_t from=MaxItems)
void draw(uint16_t xOffset=0, uint16_t yOffset=0)