-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCDML_DISP.ino
114 lines (96 loc) · 4.51 KB
/
LCDML_DISP.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// =====================================================================
//
// Output function
//
// =====================================================================
/* ******************************************************************** */
void lcdml_menu_clear()
/* ******************************************************************** */
{
}
/* ******************************************************************** */
void lcdml_menu_display()
/* ******************************************************************** */
{
// for first test set font here
u8g2.setFont(_LCDML_DISP_font);
// decalration of some variables
// ***************
// content variable
char content_text[_LCDML_DISP_cols]; // save the content text of every menu element
// menu element object
LCDMenuLib2_menu *tmp;
// some limit values
uint8_t i = LCDML.MENU_getScroll();
uint8_t maxi = _LCDML_DISP_rows + i;
uint8_t n = 0;
// init vars
uint8_t n_max = (LCDML.MENU_getChilds() >= _LCDML_DISP_rows) ? _LCDML_DISP_rows : (LCDML.MENU_getChilds());
uint8_t scrollbar_min = 0;
uint8_t scrollbar_max = LCDML.MENU_getChilds();
uint8_t scrollbar_cur_pos = LCDML.MENU_getCursorPosAbs();
uint8_t scroll_pos = ((1.*n_max * _LCDML_DISP_rows) / (scrollbar_max - 1) * scrollbar_cur_pos);
// generate content
u8g2.firstPage();
do {
n = 0;
i = LCDML.MENU_getScroll();
// update content
// ***************
// clear menu
// ***************
// check if this element has children
if (tmp = LCDML.MENU_getObj()->getChild(LCDML.MENU_getScroll()))
{
// loop to display lines
do
{
// check if a menu element has a condetion and if the condetion be true
if (tmp->checkCondetion())
{
// check the type off a menu element
if(tmp->checkType_menu() == true)
{
// display normal content
LCDML_getContent(content_text, tmp->getID());
u8g2.drawStr( _LCDML_DISP_box_x0+_LCDML_DISP_font_w + _LCDML_DISP_cur_space_behind, _LCDML_DISP_box_y0 + _LCDML_DISP_font_h * (n + 1), content_text);
}
else
{
if(tmp->checkType_dynParam()) {
tmp->callback(n);
}
}
// increment some values
i++;
n++;
}
// try to go to the next sibling and check the number of displayed rows
} while (((tmp = tmp->getSibling(1)) != NULL) && (i < maxi));
}
// set cursor
u8g2.drawStr( _LCDML_DISP_box_x0+_LCDML_DISP_cur_space_before, _LCDML_DISP_box_y0 + _LCDML_DISP_font_h * (LCDML.MENU_getCursorPos() + 1), _LCDML_DISP_cursor_char);
if(_LCDML_DISP_draw_frame == 1) {
u8g2.drawFrame(_LCDML_DISP_box_x0, _LCDML_DISP_box_y0, (_LCDML_DISP_box_x1-_LCDML_DISP_box_x0), (_LCDML_DISP_box_y1-_LCDML_DISP_box_y0));
}
// display scrollbar when more content as rows available and with > 2
if (scrollbar_max > n_max && _LCDML_DISP_scrollbar_w > 2)
{
// set frame for scrollbar
u8g2.drawFrame(_LCDML_DISP_box_x1 - _LCDML_DISP_scrollbar_w, _LCDML_DISP_box_y0, _LCDML_DISP_scrollbar_w, _LCDML_DISP_box_y1-_LCDML_DISP_box_y0);
// calculate scrollbar length
uint8_t scrollbar_block_length = scrollbar_max - n_max;
scrollbar_block_length = (_LCDML_DISP_box_y1-_LCDML_DISP_box_y0) / (scrollbar_block_length + _LCDML_DISP_rows);
//set scrollbar
if (scrollbar_cur_pos == 0) { // top position (min)
u8g2.drawBox(_LCDML_DISP_box_x1 - (_LCDML_DISP_scrollbar_w-1), _LCDML_DISP_box_y0 + 1 , (_LCDML_DISP_scrollbar_w-2) , scrollbar_block_length);
}
else if (scrollbar_cur_pos == (scrollbar_max-1)) { // bottom position (max)
u8g2.drawBox(_LCDML_DISP_box_x1 - (_LCDML_DISP_scrollbar_w-1), _LCDML_DISP_box_y1 - scrollbar_block_length , (_LCDML_DISP_scrollbar_w-2) , scrollbar_block_length);
}
else { // between top and bottom
u8g2.drawBox(_LCDML_DISP_box_x1 - (_LCDML_DISP_scrollbar_w-1), _LCDML_DISP_box_y0 + (scrollbar_block_length * scrollbar_cur_pos + 1),(_LCDML_DISP_scrollbar_w-2) , scrollbar_block_length);
}
}
} while ( u8g2.nextPage() );
}