28 #ifndef _LCDGFX_CHECKBOX_MENU_H_ 29 #define _LCDGFX_CHECKBOX_MENU_H_ 37 #define lcd_gfx_min(x, y) ((x) < (y) ? (x) : (y)) 41 #define lcd_gfx_max(x, y) ((x) > (y) ? (x) : (y)) 94 template <
typename D>
void show(D &d);
183 uint16_t m_oldChecked = 0;
184 uint8_t m_oldScrollPosition = 0;
185 bool m_initialized =
false;
187 template <
typename D> uint8_t getMaxScreenItems(D &d)
189 return (menu.
height - 16) / d.getFont().getHeader().height;
192 template <
typename D> uint8_t calculateScrollPosition(D &d, uint8_t selection)
198 else if ( selection - menu.
scrollPosition > getMaxScreenItems(d) - 1 )
200 return selection - getMaxScreenItems(d) + 1;
205 template <
typename D>
void drawMenuItem(D &d, uint8_t index)
207 lcduint_t fh = d.getFont().getHeader().height;
213 lcdint_t boxY = item_top + (fh - boxSize) / 2;
214 lcdint_t textX = boxX + boxSize + 3;
219 uint16_t fg = d.getColor();
221 d.fillRect(menu.
left + 5, item_top, textX - 1, item_top + fh - 1);
226 if ( m_checked & (1u << index) )
228 d.fillRect(boxX, boxY, boxX + boxSize - 1, boxY + boxSize - 1);
232 d.drawRect(boxX, boxY, boxX + boxSize - 1, boxY + boxSize - 1);
242 uint16_t textColor = d.getColor();
244 d.fillRect(textX + d.getFont().getTextSize(menu.
items[index]), item_top,
245 menu.
width + menu.
left - 9, item_top + fh - 1);
246 d.setColor(textColor);
247 d.printFixed(textX, item_top, menu.
items[index], STYLE_NORMAL);
254 template <
typename D>
void drawScrollIndicators(D &d, uint8_t maxItems)
259 uint16_t color = d.getColor();
261 lcdint_t itemsBot = itemsTop + maxItems * d.getFont().getHeader().height;
263 lcdint_t sbH = itemsBot - itemsTop - 1;
274 d.fillRect(sbX, itemsTop, sbX + 1, itemsTop + sbH);
276 d.fillRect(sbX, thumbY, sbX + 1, thumbY + thumbH);
285 uint8_t maxItems = getMaxScreenItems(d);
286 uint8_t newScroll = this->calculateScrollPosition(d, menu.
selection);
291 if ( m_initialized && newScroll == m_oldScrollPosition )
294 uint16_t changedCheck = m_checked ^ m_oldChecked;
304 else if ( changedCheck & (1u << menu.
selection) )
315 this->drawMenuItem(d, i);
319 m_oldChecked = m_checked;
330 this->drawMenuItem(d, i);
334 m_oldChecked = m_checked;
335 m_initialized =
true;
336 if ( menu.
count > maxItems )
338 this->drawScrollIndicators(d, maxItems);
uint8_t lcduint_t
internal int type, used by the library.
NanoRect structure describes rectangle area.
int8_t lcdint_t
internal int type, used by the library.
#define lcd_gfx_max(a, b)
Macros returning maximum of 2 numbers.
Basic structures of nano gfx library.
#define lcd_gfx_min(a, b)
Macros returning minimum of 2 numbers.