28 #ifndef _LCDGFX_MENU_H_ 29 #define _LCDGFX_MENU_H_ 38 #define lcd_gfx_min(x, y) ((x) < (y) ? (x) : (y)) 43 #define lcd_gfx_max(x, y) ((x) > (y) ? (x) : (y)) 82 template <
typename D>
void show(D &d);
118 void setSelection(uint8_t s);
162 lcduint_t itemH = d.getFont().getHeader().height;
163 if ( itemH == 0 )
return 0xFF;
164 uint8_t maxItems = getMaxScreenItems(d);
166 if ( y < itemsTop || y >= itemsBot )
return 0xFF;
167 uint8_t row = (uint8_t)((y - itemsTop) / itemH);
169 if ( index >= menu.
count )
return 0xFF;
194 lcduint_t itemH = d.getFont().getHeader().height;
195 if ( itemH == 0 )
return false;
196 uint8_t maxItems = getMaxScreenItems(d);
198 if ( y >= borderTop && y < itemsTop )
207 if ( y >= itemsBot && y < borderBot )
216 if ( y >= itemsTop && y < itemsBot )
218 uint8_t row = (uint8_t)((y - itemsTop) / itemH);
220 if ( index < menu.
count )
231 uint8_t m_oldScrollPosition = 0;
232 bool m_initialized =
false;
234 template <
typename D> uint8_t getMaxScreenItems(D &d)
236 return (menu.
height - 16) / d.getFont().getHeader().height;
239 template <
typename D> uint8_t calculateScrollPosition(D &d, uint8_t selection)
245 else if ( selection - menu.
scrollPosition > getMaxScreenItems(d) - 1 )
247 return selection - getMaxScreenItems(d) + 1;
252 template <
typename D>
void drawMenuItem(D &d, uint8_t index)
259 uint16_t color = d.getColor();
266 d.fillRect(menu.
left + 8 + d.getFont().getTextSize(menu.
items[index]), item_top,
267 menu.
width + menu.
left - 9, item_top + d.getFont().getHeader().height - 1);
269 d.printFixed(menu.
left + 8, item_top, menu.
items[index], STYLE_NORMAL);
276 template <
typename D>
void drawScrollIndicators(D &d, uint8_t maxItems)
282 uint16_t color = d.getColor();
284 lcdint_t itemsBot = itemsTop + maxItems * d.getFont().getHeader().height;
286 lcdint_t sbH = itemsBot - itemsTop - 1;
297 d.fillRect(sbX, itemsTop, sbX + 1, itemsTop + sbH);
299 d.fillRect(sbX, thumbY, sbX + 1, thumbY + thumbH);
308 uint8_t maxItems = getMaxScreenItems(d);
309 uint8_t newScroll = this->calculateScrollPosition(d, menu.
selection);
316 if ( m_initialized && newScroll == m_oldScrollPosition )
322 this->drawMenuItem(d, prev);
336 this->drawMenuItem(d, i);
340 m_initialized =
true;
341 if ( menu.
count > maxItems )
343 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.
Basic structures of nano gfx library.