1 #include <MutilaDebug.h> 3 #include "GfxSSIDListBox.h" 4 #include "GfxTextBox.h" 5 #include "GfxSignalStrength.h" 6 #include "CbOledDisplay.h" 7 #include "CheeseboardConfig.h" 9 GfxSSIDListBox::GfxSSIDListBox(uint16_t x, uint16_t y) :
12 for(uint8_t i=0; i<MaxItems; i++) {
18 _lineHeight = (CBOLED_MESSAGE_FONT_HEIGHT + (2*CBOLED_MESSAGE_FONT_VSEP));
19 _screenLines = CbOledDisplay.getDisplayHeight() / _lineHeight;
23 GfxSSIDListBox::~GfxSSIDListBox()
25 for(uint8_t i=0; i<MaxItems; i++) {
26 if (_items[i] != NULL) {
35 int16_t i = findGap();
46 if (idx >= 0 && idx <MaxItems && _items[idx] != NULL) {
51 if (_selected == idx) {
68 for(uint8_t i=0; i<MaxItems && drawn<_screenLines; i++) {
69 if (_items[i] != NULL) {
71 uint16_t y = drawn * _items[i]->height();
72 _items[i]->draw(xOffset, yOffset+y);
74 CbOledDisplay.drawFrame(xOffset, y, _items[i]->
width(), _items[i]->
height());
89 return _lineHeight * (count() < _screenLines ? count() : _screenLines);
94 if (idx < 0 or idx >= MaxItems) {
103 int16_t idx = this->find(ssid, 1);
114 for(i=startAt; i<MaxItems && _items[i] != NULL; i++) {;}
124 for(uint8_t i=from+1; i<MaxItems; i++) {
125 if (_items[i] != NULL) {
134 if (from == 0 || from >= MaxItems) {
138 for(uint8_t i=from-1; i>=0; i--) {
139 if (_items[i] != NULL) {
149 for (uint8_t i=0; i<MaxItems; i++) {
150 if (_items[i] != NULL) {
159 for (uint8_t i=0; i<MaxItems; i++) {
160 if (_items[i] != NULL) {
161 if (_items[i]->ssid() == ssid) {
176 int16_t gap = findGap();
178 for (uint8_t i=gap+1; i<MaxItems; i++) {
179 if (_items[i] != NULL) {
190 while (!isCompacted()) {
191 int16_t gap = findGap();
193 for(uint8_t i=gap; i<MaxItems-1; i++) {
194 _items[i] = _items[i+1];
195 if (i+1 == _selected) {
199 _items[MaxItems-1] = NULL;
206 if (idx >= MaxItems || !(idx == -1 || _items[idx] != NULL)) {
223 uint8_t lines = _screenLines;
224 for (uint8_t i=_screenStart; i<MaxItems && lines>0; i++) {
228 if (_items[i] != NULL) {
238 for (uint8_t i=idx; i<MaxItems; i++) {
239 if (_items[i] != NULL) {
248 uint8_t scrolled = 0;
250 int16_t nextItem = findNext(_screenStart);
251 if (nextItem == -1) {
254 if (rowsFrom(nextItem) < _screenLines) {
257 _screenStart = nextItem;
267 uint8_t scrolled = 0;
269 int16_t preItem = findPreceding(_screenStart);
273 _screenStart = preItem;
282 if (_items[idx] == NULL || idx > MaxItems) {
286 if (idx < _screenStart) {
288 while(!isOnScreen(idx)) {
292 while(!isOnScreen(idx)) {
301 int16_t idx = this->find(ssid);
303 _items[idx]->update(channel, signal);
307 if (netInfo == NULL) {
311 idx = this->add(*netInfo);
int16_t add(const GfxNetInfo s)
void compact()
Make used items contiguous (remove gaps)
bool isOnScreen(uint8_t idx)
int16_t update(String ssid, int8_t channel, uint8_t signal)
uint8_t scrollUp(uint8_t rows)
bool remove(const uint8_t idx, bool compactAfter=true)
int16_t findGap(uint8_t startAt=0)
bool scrollTo(uint8_t idx)
uint8_t rowsFrom(uint8_t idx)
void draw(uint16_t xOffset=0, uint16_t yOffset=0)
GfxNetInfo * operator[](int16_t idx)
uint8_t scrollDown(uint8_t rows)
int16_t findNext(uint8_t from=0)
bool isCompacted()
Sort the items contained in the list box using quicksort.
int16_t find(const String &ssid, uint8_t n=1)
int16_t findPreceding(uint8_t from=MaxItems)