Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibmui_u8g2.c

2849 lines · 86.1 KB · C

1/*
2
3 mui_u8g2.c
4
5 Monochrome minimal user interface: Glue code between mui and u8g2.
6
7 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8
9 Copyright (c) 2021, olikraus@gmail.com
10 All rights reserved.
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14
15 * Redistributions of source code must retain the above copyright notice, this
16 list of conditions and the following disclaimer.
17
18 * Redistributions in binary form must reproduce the above copyright notice,
19 this list of conditions and the following disclaimer in the documentation
20 and/or other materials provided with the distribution.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36*/
37
38/*
39
40 field function naming convention
41
42 action
43 draw_text: (rename from draw label)
44 draw_str:
45 btn_jmp button jump to: a button which jumps to a
46 specific form btn_exit button leave: a button
47 which leaves the form and places an exit code into a uint8 variable
48 u8_value_0_9
49 u8_chkbox
50 u8_radio
51 u8_opt_line edit value options in the same line
52 u8_opt_parent edit value options parent
53 u8_opt_child edit value options child
54
55
56 field width (not for draw text/str)
57 wm minimum width
58 wa width can be provided via FDS argument
59 w1 full display width
60 w2 half display size (minus some pixel)
61 w3 one/third of the dispay width (minus some pixel)
62
63 edit mode (not for draw text/str, buttons and checkbox)
64 mse select: select event will increment the value or activate the
65 field (buttons) mud up/down: select will enter the up/down edit mode.
66 Next/prev event will increment/decrement the value
67
68 styles (not for draw text/str)
69 unselected selected up/down edit
70 postfix Use for plain invers invers + gap +
71 frame pi input elements frame invers+frame
72 frame fi buttons
73
74 plain frame invers +
75 frame pf input elements invers frame
76 invers + frame if buttons
77
78
79 mui_u8g2_[action]_[field_width]_[edit_mode]_[style]
80
81 mui _label_u8g2 --> mui_u8g2_draw_text
82 mui _goto_frame_button_invers_select_u8g2 -->
83 mui_u8g2_btn_goto_wm_fi mui _goto_half_width_frame_button_invers_select_u8g2
84 --> mui_u8g2_btn_goto_w2_fi mui _goto_line_button_invers_select_u8g2 -->
85 mui_u8g2_btn_goto_w1_fi mui _leave_menu_frame_button_invers_select_u8g2 -->
86 mui_u8g2_btn_exit_wm_fi
87
88 mui _input_uint8_invers_select_u8g2 --> mui_u8g2_u8_value_0_9_wm_mse_pi
89 mui _single_line_option_invers_select_u8g2 -->
90 mui_u8g2_u8_opt_line_wa_mse_pi mui _select_options_parent_invers_select_u8g2
91 --> mui_u8g2_u8_opt_parent_wa_mse_pi mui
92 _select_options_child_invers_select_u8g2 --> mui_u8g2_u8_opt_child_wm_pi
93
94 mui _checkbox_invers_select_u8g2 --> mui_u8g2_u8_chkbox_wm_pi
95 mui _radio_invers_select_u8g2 --> mui_u8g2_u8_radio_wm_pi
96
97 mui _input_char_invers_select_u8g2 --> mui_u8g2_u8_char_wm_mud_pi
98
99
100
101 2 Buttons
102 Only use "mse", don't use "mud"
103
104 Button Call Description
105 1 mui_SendSelect() Activate elements & change values
106 2 mui_NextField() Goto next field
107
108 3 Buttons
109 Use "mse" or "mud"
110 Button Call Description
111 1 mui_SendSelect() Activate elements / change values (mse)
112 / enter "mud" mode (mud) 2 mui_NextField() Goto next
113 field, increment value (mud) 3 mui_PrevField() Goto prev
114 field, decrement value (mud)
115
116 4 Buttons
117 Prefer "mse"
118 Button Call Description
119 1 mui_SendValueIncrement() Activate elements / increment
120 values (mse) 2 mui_SendValueDecrement() Activate elements /
121 decrement values (mse) 3 mui_NextField() Goto next field 4
122 mui_PrevField() Goto prev field
123
124 5 Buttons
125 Prefer "mse", use the MUIF_EXECUTE_ON_SELECT_BUTTON on forms to finish the
126 form with the "form select" button 5 Button Call Description 1
127 mui_SendValueIncrement() Activate elements / increment values (mse) 2
128 mui_SendValueDecrement() Activate elements / decrement values (mse) 3
129 mui_NextField() Goto next field 4 mui_PrevField() Goto prev
130 field 5 mui_SendSelectWithExecuteOnSelectFieldSearch() Execute
131 the MUIF_EXECUTE_ON_SELECT_BUTTON button or activate the current element if
132 there is no EOS button
133
134 rotary encoder, push&release
135 Prefer "mud"
136 Button Call Description
137 encoder button mui_SendSelect() Activate elements /
138 change values (mse) / enter "mud" mode (mud) encoder CW mui_NextField() Goto
139 next field, increment value (mud) encoder CCW mui_PrevField() Goto prev
140 field, decrement value (mud)
141
142 rotary encoder, push&rotate
143 Prefer "mse"
144 Button Call Description encoder CW
145 mui_SendValueIncrement() Activate elements / increment values (mse) encoder
146 CCW mui_SendValueDecrement() Activate
147 elements / decrement values (mse) encoder CW+button press mui_NextField() Goto
148 next field encoder CCW+button press mui_PrevField() Goto prev
149 field
150
151
152*/
153
154#include "mui_u8g2.h"
155#include "mui.h"
156#include "u8g2.h"
157
158/*
159
160uint8_t mui_template(mui_t *ui, uint8_t msg)
161{
162 //u8g2_t *u8g2 = mui_get_U8g2(ui);
163 //ui->dflags MUIF_DFLAG_IS_CURSOR_FOCUS
164MUIF_DFLAG_IS_TOUCH_FOCUS
165 //muif_get_cflags(ui->uif) MUIF_CFLAG_IS_CURSOR_SELECTABLE
166 //muif_get_data(ui->uif)
167 switch(msg)
168 {
169 case MUIF_MSG_DRAW:
170 break;
171 case MUIF_MSG_FORM_START:
172 break;
173 case MUIF_MSG_FORM_END:
174 break;
175 case MUIF_MSG_CURSOR_ENTER:
176 break;
177 case MUIF_MSG_CURSOR_SELECT:
178 break;
179 case MUIF_MSG_CURSOR_LEAVE:
180 break;
181 case MUIF_MSG_VALUE_INCREMENT:
182 break;
183 case MUIF_MSG_VALUE_DECREMENT:
184 break;
185 case MUIF_MSG_TOUCH_DOWN:
186 break;
187 case MUIF_MSG_TOUCH_UP:
188 break;
189 }
190 return 0;
191}
192*/
193
194/*=========================================================================*/
195#define MUI_U8G2_V_PADDING 1
196
197/*=========================================================================*/
198/* extra u8g2 drawing functions */
199
200static void u8g2_DrawCheckbox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
201 u8g2_uint_t w,
202 u8g2_uint_t is_checked) MUI_NOINLINE;
203static void u8g2_DrawCheckbox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
204 u8g2_uint_t w, u8g2_uint_t is_checked) {
205 u8g2_DrawFrame(u8g2, x, y - w, w, w);
206 if (is_checked) {
207 w -= 4;
208 u8g2_DrawBox(u8g2, x + 2, y - w - 2, w, w);
209 }
210}
211
212static void u8g2_DrawValueMark(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
213 u8g2_uint_t w) {
214 u8g2_DrawBox(u8g2, x, y - w, w, w);
215}
216
217/*=========================================================================*/
218/* helper function */
219
220u8g2_uint_t mui_get_x(mui_t *ui) MUI_NOINLINE;
221u8g2_uint_t mui_get_x(mui_t *ui) {
222 if (u8g2_GetDisplayWidth(mui_get_U8g2(ui)) >= 255)
223 return ui->x * 2;
224 return ui->x;
225}
226
227u8g2_uint_t mui_get_y(mui_t *ui) { return ui->y; }
228
229u8g2_uint_t mui_get_arg(mui_t *ui) { return ui->arg; }
230
231char *mui_get_text(mui_t *ui) { return ui->text; }
232
233u8g2_t *mui_get_U8g2(mui_t *ui) { return (u8g2_t *)(ui->graphics_data); }
234
235// void u8g2_DrawButtonUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
236// u8g2_uint_t flags, u8g2_uint_t width, u8g2_uint_t padding_h, u8g2_uint_t
237// padding_v, const char *text);
238void mui_u8g2_draw_button_utf(mui_t *ui, u8g2_uint_t flags, u8g2_uint_t width,
239 u8g2_uint_t padding_h, u8g2_uint_t padding_v,
240 const char *text) {
241 if (text == NULL)
242 text = "";
243 u8g2_DrawButtonUTF8(mui_get_U8g2(ui), mui_get_x(ui), mui_get_y(ui), flags,
244 width, padding_h, padding_v, text);
245}
246
247u8g2_uint_t mui_u8g2_get_pi_flags(mui_t *ui) {
248 u8g2_uint_t flags = 0;
249 if (mui_IsCursorFocus(ui)) {
250 flags |= U8G2_BTN_INV;
251 if (ui->is_mud) {
252 flags |= U8G2_BTN_XFRAME;
253 }
254 }
255 return flags;
256}
257
258void mui_u8g2_draw_button_pi(mui_t *ui, u8g2_uint_t width,
259 u8g2_uint_t padding_h, const char *text) {
260 mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), width, padding_h,
261 MUI_U8G2_V_PADDING, text);
262}
263
264u8g2_uint_t mui_u8g2_get_fi_flags(mui_t *ui) {
265 u8g2_uint_t flags = 1;
266 if (mui_IsCursorFocus(ui)) {
267 flags |= U8G2_BTN_INV;
268 if (ui->is_mud) {
269 flags = 1; // undo INV
270 }
271 }
272 return flags;
273}
274
275void mui_u8g2_draw_button_fi(mui_t *ui, u8g2_uint_t width,
276 u8g2_uint_t padding_h, const char *text) {
277 mui_u8g2_draw_button_utf(ui, mui_u8g2_get_fi_flags(ui), width, padding_h,
278 MUI_U8G2_V_PADDING, text);
279}
280
281u8g2_uint_t mui_u8g2_get_pf_flags(mui_t *ui) {
282 u8g2_uint_t flags = 0;
283 if (mui_IsCursorFocus(ui)) {
284 flags |= 1;
285 if (ui->is_mud) {
286 flags |= U8G2_BTN_INV;
287 }
288 }
289 return flags;
290}
291
292void mui_u8g2_draw_button_pf(mui_t *ui, u8g2_uint_t width,
293 u8g2_uint_t padding_h, const char *text) {
294 mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pf_flags(ui), width, padding_h,
295 MUI_U8G2_V_PADDING, text);
296}
297
298u8g2_uint_t mui_u8g2_get_if_flags(mui_t *ui) {
299 u8g2_uint_t flags = 0;
300 if (mui_IsCursorFocus(ui)) {
301 if (ui->is_mud) {
302 flags |= 1;
303 flags |= U8G2_BTN_INV;
304 } else {
305 flags |= 1;
306 }
307 } else {
308 flags |= U8G2_BTN_INV;
309 }
310 return flags;
311}
312
313void mui_u8g2_draw_button_if(mui_t *ui, u8g2_uint_t width,
314 u8g2_uint_t padding_h, const char *text) {
315 mui_u8g2_draw_button_utf(ui, mui_u8g2_get_if_flags(ui), width, padding_h,
316 MUI_U8G2_V_PADDING, text);
317}
318
319static uint8_t
320mui_u8g2_handle_scroll_next_prev_events(mui_t *ui, uint8_t msg) MUI_NOINLINE;
321static uint8_t mui_u8g2_handle_scroll_next_prev_events(mui_t *ui, uint8_t msg) {
322 uint8_t arg = ui->arg;
323 switch (msg) {
324 case MUIF_MSG_CURSOR_ENTER:
325 if ((arg > 0) && (ui->form_scroll_top + arg >= ui->form_scroll_total))
326 return 255;
327 break;
328 case MUIF_MSG_EVENT_NEXT:
329 if (arg + 1 == ui->form_scroll_visible) {
330 if (ui->form_scroll_visible + ui->form_scroll_top <
331 ui->form_scroll_total) {
332 ui->form_scroll_top++;
333 return 1;
334 } else {
335 ui->form_scroll_top = 0;
336 }
337 }
338 break;
339 case MUIF_MSG_EVENT_PREV:
340 if (arg == 0) {
341 if (ui->form_scroll_top > 0) {
342 ui->form_scroll_top--;
343 return 1;
344 } else {
345 if (ui->form_scroll_total > ui->form_scroll_visible) {
346 ui->form_scroll_top =
347 ui->form_scroll_total - ui->form_scroll_visible;
348 } else {
349 ui->form_scroll_top = 0;
350 }
351 }
352 }
353 break;
354 }
355 return 0;
356}
357
358/*=========================================================================*/
359/* simplified style function */
360
361/*
362Used for MUIF_U8G2_FONT_STYLE(n,font)
363*/
364
365uint8_t mui_u8g2_set_font_style_function(mui_t *ui, uint8_t msg) {
366 if (msg == MUIF_MSG_DRAW) {
367 u8g2_SetFont(mui_get_U8g2(ui), (uint8_t *)muif_get_data(ui->uif));
368 }
369 return 0;
370}
371
372/*=========================================================================*/
373/* field functions */
374
375uint8_t mui_hline(mui_t *ui, uint8_t msg) {
376 u8g2_t *u8g2 = mui_get_U8g2(ui);
377 switch (msg) {
378 case MUIF_MSG_DRAW:
379 u8g2_DrawHLine(u8g2, 0, mui_get_y(ui), u8g2_GetDisplayWidth(u8g2));
380 break;
381 }
382 return 0;
383}
384
385/*
386 xy: yes, arg: no, text: yes
387*/
388
389uint8_t mui_u8g2_draw_text(mui_t *ui, uint8_t msg) {
390 switch (msg) {
391 case MUIF_MSG_DRAW:
392 u8g2_DrawUTF8(mui_get_U8g2(ui), mui_get_x(ui), mui_get_y(ui), ui->text);
393 break;
394 case MUIF_MSG_FORM_START:
395 break;
396 case MUIF_MSG_FORM_END:
397 break;
398 case MUIF_MSG_CURSOR_ENTER:
399 break;
400 case MUIF_MSG_CURSOR_SELECT:
401 break;
402 case MUIF_MSG_VALUE_INCREMENT:
403 break;
404 case MUIF_MSG_VALUE_DECREMENT:
405 break;
406 case MUIF_MSG_CURSOR_LEAVE:
407 break;
408 case MUIF_MSG_TOUCH_DOWN:
409 break;
410 case MUIF_MSG_TOUCH_UP:
411 break;
412 }
413 return 0;
414}
415
416/*
417
418 uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg)
419
420 Description:
421 A button with size equal to button text plus one pixel padding
422 The button has a one pixel frame around the text.
423 If the selected, then the form will change to the specified form number.
424
425 Message Handling: DRAW, CURSOR_SELECT
426
427 Style
428 No Selection: Text + Frame
429 Cursor Selection: Inverted text + Frame
430
431 User interface field list (muif):
432 flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
433 data: not used
434
435 Field definition string (fds):
436 xy: Left position of the text (required)
437 arg: Form numner (required)
438 text: Button label
439
440*/
441uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg) {
442 switch (msg) {
443 case MUIF_MSG_DRAW:
444 mui_u8g2_draw_button_utf(ui,
445 U8G2_BTN_HCENTER | mui_u8g2_get_fi_flags(ui),
446 0, 1, MUI_U8G2_V_PADDING, ui->text);
447 break;
448 case MUIF_MSG_FORM_START:
449 break;
450 case MUIF_MSG_FORM_END:
451 break;
452 case MUIF_MSG_CURSOR_ENTER:
453 break;
454 case MUIF_MSG_CURSOR_SELECT:
455 case MUIF_MSG_VALUE_INCREMENT:
456 case MUIF_MSG_VALUE_DECREMENT:
457 // return mui_GotoForm(ui, ui->arg, 0);
458 mui_SaveForm(ui);
459 return mui_GotoFormAutoCursorPosition(ui, ui->arg);
460 case MUIF_MSG_CURSOR_LEAVE:
461 break;
462 case MUIF_MSG_TOUCH_DOWN:
463 break;
464 case MUIF_MSG_TOUCH_UP:
465 break;
466 }
467 return 0;
468}
469
470uint8_t mui_u8g2_btn_goto_wm_if(mui_t *ui, uint8_t msg) {
471 switch (msg) {
472 case MUIF_MSG_DRAW:
473 mui_u8g2_draw_button_utf(ui,
474 U8G2_BTN_HCENTER | mui_u8g2_get_if_flags(ui),
475 0, 1, MUI_U8G2_V_PADDING, ui->text);
476 break;
477 case MUIF_MSG_FORM_START:
478 break;
479 case MUIF_MSG_FORM_END:
480 break;
481 case MUIF_MSG_CURSOR_ENTER:
482 break;
483 case MUIF_MSG_CURSOR_SELECT:
484 case MUIF_MSG_VALUE_INCREMENT:
485 case MUIF_MSG_VALUE_DECREMENT:
486 // return mui_GotoForm(ui, ui->arg, 0);
487 mui_SaveForm(ui);
488 return mui_GotoFormAutoCursorPosition(ui, ui->arg);
489 case MUIF_MSG_CURSOR_LEAVE:
490 break;
491 case MUIF_MSG_TOUCH_DOWN:
492 break;
493 case MUIF_MSG_TOUCH_UP:
494 break;
495 }
496 return 0;
497}
498
499uint8_t mui_u8g2_btn_goto_w2_fi(mui_t *ui, uint8_t msg) {
500 u8g2_t *u8g2 = mui_get_U8g2(ui);
501 switch (msg) {
502 case MUIF_MSG_DRAW:
503 mui_u8g2_draw_button_utf(ui,
504 U8G2_BTN_HCENTER | mui_u8g2_get_fi_flags(ui),
505 u8g2_GetDisplayWidth(u8g2) / 2 - 10, 0,
506 MUI_U8G2_V_PADDING, ui->text);
507 break;
508 case MUIF_MSG_FORM_START:
509 break;
510 case MUIF_MSG_FORM_END:
511 break;
512 case MUIF_MSG_CURSOR_ENTER:
513 break;
514 case MUIF_MSG_CURSOR_SELECT:
515 case MUIF_MSG_VALUE_INCREMENT:
516 case MUIF_MSG_VALUE_DECREMENT:
517 // return mui_GotoForm(ui, ui->arg, 0);
518 mui_SaveForm(ui);
519 return mui_GotoFormAutoCursorPosition(ui, ui->arg);
520 case MUIF_MSG_CURSOR_LEAVE:
521 break;
522 case MUIF_MSG_TOUCH_DOWN:
523 break;
524 case MUIF_MSG_TOUCH_UP:
525 break;
526 }
527 return 0;
528}
529
530uint8_t mui_u8g2_btn_goto_w2_if(mui_t *ui, uint8_t msg) {
531 u8g2_t *u8g2 = mui_get_U8g2(ui);
532 switch (msg) {
533 case MUIF_MSG_DRAW:
534 mui_u8g2_draw_button_utf(ui,
535 U8G2_BTN_HCENTER | mui_u8g2_get_if_flags(ui),
536 u8g2_GetDisplayWidth(u8g2) / 2 - 10, 0,
537 MUI_U8G2_V_PADDING, ui->text);
538 break;
539 case MUIF_MSG_FORM_START:
540 break;
541 case MUIF_MSG_FORM_END:
542 break;
543 case MUIF_MSG_CURSOR_ENTER:
544 break;
545 case MUIF_MSG_CURSOR_SELECT:
546 case MUIF_MSG_VALUE_INCREMENT:
547 case MUIF_MSG_VALUE_DECREMENT:
548 // return mui_GotoForm(ui, ui->arg, 0);
549 mui_SaveForm(ui);
550 return mui_GotoFormAutoCursorPosition(ui, ui->arg);
551 case MUIF_MSG_CURSOR_LEAVE:
552 break;
553 case MUIF_MSG_TOUCH_DOWN:
554 break;
555 case MUIF_MSG_TOUCH_UP:
556 break;
557 }
558 return 0;
559}
560
561uint8_t mui_u8g2_btn_goto_w1_pi(mui_t *ui, uint8_t msg) {
562 u8g2_t *u8g2 = mui_get_U8g2(ui);
563 switch (msg) {
564 case MUIF_MSG_DRAW:
565 mui_u8g2_draw_button_pi(ui,
566 u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
567 mui_get_x(ui), ui->text);
568 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
569 // u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) ,
570 // MUI_U8G2_V_PADDING, ui->text);
571 break;
572 case MUIF_MSG_FORM_START:
573 break;
574 case MUIF_MSG_FORM_END:
575 break;
576 case MUIF_MSG_CURSOR_ENTER:
577 break;
578 case MUIF_MSG_CURSOR_SELECT:
579 case MUIF_MSG_VALUE_INCREMENT:
580 case MUIF_MSG_VALUE_DECREMENT:
581 // return mui_GotoForm(ui, ui->arg, 0);
582 mui_SaveForm(ui);
583 return mui_GotoFormAutoCursorPosition(ui, ui->arg);
584 case MUIF_MSG_CURSOR_LEAVE:
585 break;
586 case MUIF_MSG_TOUCH_DOWN:
587 break;
588 case MUIF_MSG_TOUCH_UP:
589 break;
590 }
591 return 0;
592}
593
594uint8_t mui_u8g2_btn_goto_w1_fi(mui_t *ui, uint8_t msg) {
595 u8g2_t *u8g2 = mui_get_U8g2(ui);
596 switch (msg) {
597 case MUIF_MSG_DRAW:
598 mui_u8g2_draw_button_fi(ui,
599 u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
600 mui_get_x(ui) - 1, ui->text);
601 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
602 // u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) ,
603 // MUI_U8G2_V_PADDING, ui->text);
604 break;
605 case MUIF_MSG_FORM_START:
606 break;
607 case MUIF_MSG_FORM_END:
608 break;
609 case MUIF_MSG_CURSOR_ENTER:
610 break;
611 case MUIF_MSG_CURSOR_SELECT:
612 case MUIF_MSG_VALUE_INCREMENT:
613 case MUIF_MSG_VALUE_DECREMENT:
614 // return mui_GotoForm(ui, ui->arg, 0);
615 mui_SaveForm(ui);
616 return mui_GotoFormAutoCursorPosition(ui, ui->arg);
617 case MUIF_MSG_CURSOR_LEAVE:
618 break;
619 case MUIF_MSG_TOUCH_DOWN:
620 break;
621 case MUIF_MSG_TOUCH_UP:
622 break;
623 }
624 return 0;
625}
626
627/*
628 Back buttons are used to jump back to a previously stored form/cursor position
629*/
630
631uint8_t mui_u8g2_btn_back_wm_fi(mui_t *ui, uint8_t msg) {
632 switch (msg) {
633 case MUIF_MSG_DRAW:
634 mui_u8g2_draw_button_utf(ui,
635 U8G2_BTN_HCENTER | mui_u8g2_get_fi_flags(ui),
636 0, 1, MUI_U8G2_V_PADDING, ui->text);
637 break;
638 case MUIF_MSG_FORM_START:
639 break;
640 case MUIF_MSG_FORM_END:
641 break;
642 case MUIF_MSG_CURSOR_ENTER:
643 break;
644 case MUIF_MSG_CURSOR_SELECT:
645 case MUIF_MSG_VALUE_INCREMENT:
646 case MUIF_MSG_VALUE_DECREMENT:
647 return mui_RestoreForm(ui);
648 case MUIF_MSG_CURSOR_LEAVE:
649 break;
650 case MUIF_MSG_TOUCH_DOWN:
651 break;
652 case MUIF_MSG_TOUCH_UP:
653 break;
654 }
655 return 0;
656}
657
658uint8_t mui_u8g2_btn_back_wm_if(mui_t *ui, uint8_t msg) {
659 switch (msg) {
660 case MUIF_MSG_DRAW:
661 mui_u8g2_draw_button_utf(ui,
662 U8G2_BTN_HCENTER | mui_u8g2_get_if_flags(ui),
663 0, 1, MUI_U8G2_V_PADDING, ui->text);
664 break;
665 case MUIF_MSG_FORM_START:
666 break;
667 case MUIF_MSG_FORM_END:
668 break;
669 case MUIF_MSG_CURSOR_ENTER:
670 break;
671 case MUIF_MSG_CURSOR_SELECT:
672 case MUIF_MSG_VALUE_INCREMENT:
673 case MUIF_MSG_VALUE_DECREMENT:
674 return mui_RestoreForm(ui);
675 case MUIF_MSG_CURSOR_LEAVE:
676 break;
677 case MUIF_MSG_TOUCH_DOWN:
678 break;
679 case MUIF_MSG_TOUCH_UP:
680 break;
681 }
682 return 0;
683}
684
685uint8_t mui_u8g2_btn_back_w2_fi(mui_t *ui, uint8_t msg) {
686 u8g2_t *u8g2 = mui_get_U8g2(ui);
687 switch (msg) {
688 case MUIF_MSG_DRAW:
689 mui_u8g2_draw_button_utf(ui,
690 U8G2_BTN_HCENTER | mui_u8g2_get_fi_flags(ui),
691 u8g2_GetDisplayWidth(u8g2) / 2 - 10, 0,
692 MUI_U8G2_V_PADDING, ui->text);
693 break;
694 case MUIF_MSG_FORM_START:
695 break;
696 case MUIF_MSG_FORM_END:
697 break;
698 case MUIF_MSG_CURSOR_ENTER:
699 break;
700 case MUIF_MSG_CURSOR_SELECT:
701 case MUIF_MSG_VALUE_INCREMENT:
702 case MUIF_MSG_VALUE_DECREMENT:
703 return mui_RestoreForm(ui);
704 case MUIF_MSG_CURSOR_LEAVE:
705 break;
706 case MUIF_MSG_TOUCH_DOWN:
707 break;
708 case MUIF_MSG_TOUCH_UP:
709 break;
710 }
711 return 0;
712}
713
714uint8_t mui_u8g2_btn_back_w2_if(mui_t *ui, uint8_t msg) {
715 u8g2_t *u8g2 = mui_get_U8g2(ui);
716 switch (msg) {
717 case MUIF_MSG_DRAW:
718 mui_u8g2_draw_button_utf(ui,
719 U8G2_BTN_HCENTER | mui_u8g2_get_if_flags(ui),
720 u8g2_GetDisplayWidth(u8g2) / 2 - 10, 0,
721 MUI_U8G2_V_PADDING, ui->text);
722 break;
723 case MUIF_MSG_FORM_START:
724 break;
725 case MUIF_MSG_FORM_END:
726 break;
727 case MUIF_MSG_CURSOR_ENTER:
728 break;
729 case MUIF_MSG_CURSOR_SELECT:
730 case MUIF_MSG_VALUE_INCREMENT:
731 case MUIF_MSG_VALUE_DECREMENT:
732 return mui_RestoreForm(ui);
733 case MUIF_MSG_CURSOR_LEAVE:
734 break;
735 case MUIF_MSG_TOUCH_DOWN:
736 break;
737 case MUIF_MSG_TOUCH_UP:
738 break;
739 }
740 return 0;
741}
742
743uint8_t mui_u8g2_btn_back_w1_pi(mui_t *ui, uint8_t msg) {
744 u8g2_t *u8g2 = mui_get_U8g2(ui);
745 switch (msg) {
746 case MUIF_MSG_DRAW:
747 mui_u8g2_draw_button_pi(ui,
748 u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
749 mui_get_x(ui), ui->text);
750 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
751 // u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) ,
752 // MUI_U8G2_V_PADDING, ui->text);
753 break;
754 case MUIF_MSG_FORM_START:
755 break;
756 case MUIF_MSG_FORM_END:
757 break;
758 case MUIF_MSG_CURSOR_ENTER:
759 break;
760 case MUIF_MSG_CURSOR_SELECT:
761 case MUIF_MSG_VALUE_INCREMENT:
762 case MUIF_MSG_VALUE_DECREMENT:
763 return mui_RestoreForm(ui);
764 case MUIF_MSG_CURSOR_LEAVE:
765 break;
766 case MUIF_MSG_TOUCH_DOWN:
767 break;
768 case MUIF_MSG_TOUCH_UP:
769 break;
770 }
771 return 0;
772}
773
774uint8_t mui_u8g2_btn_back_w1_fi(mui_t *ui, uint8_t msg) {
775 u8g2_t *u8g2 = mui_get_U8g2(ui);
776 switch (msg) {
777 case MUIF_MSG_DRAW:
778 mui_u8g2_draw_button_fi(ui,
779 u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
780 mui_get_x(ui) - 1, ui->text);
781 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
782 // u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui) ,
783 // MUI_U8G2_V_PADDING, ui->text);
784 break;
785 case MUIF_MSG_FORM_START:
786 break;
787 case MUIF_MSG_FORM_END:
788 break;
789 case MUIF_MSG_CURSOR_ENTER:
790 break;
791 case MUIF_MSG_CURSOR_SELECT:
792 case MUIF_MSG_VALUE_INCREMENT:
793 case MUIF_MSG_VALUE_DECREMENT:
794 return mui_RestoreForm(ui);
795 case MUIF_MSG_CURSOR_LEAVE:
796 break;
797 case MUIF_MSG_TOUCH_DOWN:
798 break;
799 case MUIF_MSG_TOUCH_UP:
800 break;
801 }
802 return 0;
803}
804
805/*
806
807 uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg)
808
809 Description:
810 A button with size equal to button text plus one pixel padding
811 The button has a one pixel frame around the text.
812 If selected, then the menu system will be closed.
813 The arg value will be stored at the specified data location (if not NULL).
814 The arg value can be used as an exit value of the button.
815
816 Message Handling: DRAW, CURSOR_SELECT
817
818 Style
819 No Selection: Text + Frame
820 Cursor Selection: Inverted text + Frame
821
822 User interface field list (muif):
823 flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
824 data: Optionally points to uint8_t value which will receive the arg value of
825 the field.
826
827 Field definition string (fds):
828 xy: Left position of the text (required)
829 arg: Value which will be stored at *data (optional)
830 text: Button label
831
832*/
833uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg) {
834 switch (msg) {
835 case MUIF_MSG_DRAW:
836 mui_u8g2_draw_button_utf(ui,
837 U8G2_BTN_HCENTER | mui_u8g2_get_fi_flags(ui),
838 0, 1, MUI_U8G2_V_PADDING, ui->text);
839 break;
840 case MUIF_MSG_FORM_START:
841 break;
842 case MUIF_MSG_FORM_END:
843 break;
844 case MUIF_MSG_CURSOR_ENTER:
845 break;
846 case MUIF_MSG_CURSOR_SELECT:
847 case MUIF_MSG_VALUE_INCREMENT:
848 case MUIF_MSG_VALUE_DECREMENT: {
849 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
850 if (value != NULL)
851 *value = ui->arg;
852 }
853 mui_SaveForm(ui); // store the current form and position so that the
854 // child can jump back
855 mui_LeaveForm(ui);
856 return 1;
857 case MUIF_MSG_CURSOR_LEAVE:
858 break;
859 case MUIF_MSG_TOUCH_DOWN:
860 break;
861 case MUIF_MSG_TOUCH_UP:
862 break;
863 }
864 return 0;
865}
866
867/*===============================================================================*/
868/* u8 min max */
869
870static void mui_u8g2_u8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
871static void mui_u8g2_u8_vmm_draw_wm_pi(mui_t *ui) {
872 u8g2_t *u8g2 = mui_get_U8g2(ui);
873 mui_u8g2_u8_min_max_t *vmm =
874 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
875 char buf[4] = "999";
876 char *s = buf;
877 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
878 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
879 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
880 uint8_t cnt = 3;
881
882 if (*value > max)
883 *value = max;
884 if (*value <= min)
885 *value = min;
886 if (max < 100) {
887 s++;
888 cnt--;
889 }
890 if (max < 10) {
891 s++;
892 cnt--;
893 }
894 mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, s) + 1, 1,
895 u8x8_u8toa(*value, cnt));
896}
897
898uint8_t mui_u8g2_u8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg) {
899 mui_u8g2_u8_min_max_t *vmm =
900 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
901 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
902 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
903 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
904 switch (msg) {
905 case MUIF_MSG_DRAW:
906 mui_u8g2_u8_vmm_draw_wm_pi(ui);
907 break;
908 case MUIF_MSG_FORM_START:
909 break;
910 case MUIF_MSG_FORM_END:
911 break;
912 case MUIF_MSG_CURSOR_ENTER:
913 break;
914 case MUIF_MSG_CURSOR_SELECT:
915 case MUIF_MSG_VALUE_INCREMENT:
916 (*value)++;
917 if (*value > max)
918 *value = min;
919 break;
920 case MUIF_MSG_VALUE_DECREMENT:
921 if (*value > min)
922 (*value)--;
923 else
924 *value = max;
925 break;
926 case MUIF_MSG_CURSOR_LEAVE:
927 break;
928 case MUIF_MSG_TOUCH_DOWN:
929 break;
930 case MUIF_MSG_TOUCH_UP:
931 break;
932 }
933 return 0;
934}
935
936uint8_t mui_u8g2_u8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg) {
937 mui_u8g2_u8_min_max_t *vmm =
938 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
939 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
940 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
941 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
942 switch (msg) {
943 case MUIF_MSG_DRAW:
944 mui_u8g2_u8_vmm_draw_wm_pi(ui);
945 break;
946 case MUIF_MSG_FORM_START:
947 break;
948 case MUIF_MSG_FORM_END:
949 break;
950 case MUIF_MSG_CURSOR_ENTER:
951 break;
952 case MUIF_MSG_CURSOR_SELECT:
953 case MUIF_MSG_VALUE_INCREMENT:
954 case MUIF_MSG_VALUE_DECREMENT:
955 /* toggle between normal mode and capture next/prev mode */
956 ui->is_mud = !ui->is_mud;
957 break;
958 case MUIF_MSG_CURSOR_LEAVE:
959 break;
960 case MUIF_MSG_TOUCH_DOWN:
961 break;
962 case MUIF_MSG_TOUCH_UP:
963 break;
964 case MUIF_MSG_EVENT_NEXT:
965 if (ui->is_mud) {
966 (*value)++;
967 if (*value > max)
968 *value = min;
969 return 1;
970 }
971 break;
972 case MUIF_MSG_EVENT_PREV:
973 if (ui->is_mud) {
974 if (*value <= min)
975 *value = max;
976 else
977 (*value)--;
978 return 1;
979 }
980 break;
981 }
982 return 0;
983}
984
985static void mui_u8g2_u8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
986static void mui_u8g2_u8_vmm_draw_wm_pf(mui_t *ui) {
987 u8g2_t *u8g2 = mui_get_U8g2(ui);
988 mui_u8g2_u8_min_max_t *vmm =
989 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
990 char buf[4] = "999";
991 char *s = buf;
992 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
993 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
994 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
995 uint8_t cnt = 3;
996
997 if (*value > max)
998 *value = max;
999 if (*value <= min)
1000 *value = min;
1001 if (max < 100) {
1002 s++;
1003 cnt--;
1004 }
1005 if (max < 10) {
1006 s++;
1007 cnt--;
1008 }
1009 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
1010 // u8g2_GetStrWidth(u8g2, s)+1, 1, MUI_U8G2_V_PADDING, u8x8_u8toa(*value,
1011 // cnt));
1012 mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, s) + 1, 1,
1013 u8x8_u8toa(*value, cnt));
1014}
1015
1016uint8_t mui_u8g2_u8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg) {
1017 mui_u8g2_u8_min_max_t *vmm =
1018 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1019 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1020 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1021 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1022 switch (msg) {
1023 case MUIF_MSG_DRAW:
1024 mui_u8g2_u8_vmm_draw_wm_pf(ui);
1025 break;
1026 case MUIF_MSG_FORM_START:
1027 break;
1028 case MUIF_MSG_FORM_END:
1029 break;
1030 case MUIF_MSG_CURSOR_ENTER:
1031 break;
1032 case MUIF_MSG_CURSOR_SELECT:
1033 case MUIF_MSG_VALUE_INCREMENT:
1034 (*value)++;
1035 if (*value > max)
1036 *value = min;
1037 break;
1038 case MUIF_MSG_VALUE_DECREMENT:
1039 if (*value > min)
1040 (*value)--;
1041 else
1042 *value = max;
1043 break;
1044 case MUIF_MSG_CURSOR_LEAVE:
1045 break;
1046 case MUIF_MSG_TOUCH_DOWN:
1047 break;
1048 case MUIF_MSG_TOUCH_UP:
1049 break;
1050 }
1051 return 0;
1052}
1053
1054uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg) {
1055 mui_u8g2_u8_min_max_t *vmm =
1056 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1057 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1058 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1059 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1060 switch (msg) {
1061 case MUIF_MSG_DRAW:
1062 mui_u8g2_u8_vmm_draw_wm_pf(ui);
1063 break;
1064 case MUIF_MSG_FORM_START:
1065 break;
1066 case MUIF_MSG_FORM_END:
1067 break;
1068 case MUIF_MSG_CURSOR_ENTER:
1069 break;
1070 case MUIF_MSG_CURSOR_SELECT:
1071 case MUIF_MSG_VALUE_INCREMENT:
1072 case MUIF_MSG_VALUE_DECREMENT:
1073 /* toggle between normal mode and capture next/prev mode */
1074 ui->is_mud = !ui->is_mud;
1075 break;
1076 case MUIF_MSG_CURSOR_LEAVE:
1077 break;
1078 case MUIF_MSG_TOUCH_DOWN:
1079 break;
1080 case MUIF_MSG_TOUCH_UP:
1081 break;
1082 case MUIF_MSG_EVENT_NEXT:
1083 if (ui->is_mud) {
1084 (*value)++;
1085 if (*value > max)
1086 *value = min;
1087 return 1;
1088 }
1089 break;
1090 case MUIF_MSG_EVENT_PREV:
1091 if (ui->is_mud) {
1092 if (*value <= min)
1093 *value = max;
1094 else
1095 (*value)--;
1096 return 1;
1097 }
1098 break;
1099 }
1100 return 0;
1101}
1102
1103/*===============================================================================*/
1104/* s8 min max */
1105
1106static void mui_u8g2_s8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
1107static void mui_u8g2_s8_vmm_draw_wm_pi(mui_t *ui) {
1108 u8g2_t *u8g2 = mui_get_U8g2(ui);
1109 mui_u8g2_s8_min_max_t *vmm =
1110 (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
1111 char buf[6] = "+999";
1112 int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
1113 int8_t min = mui_u8g2_s8mm_get_min(vmm);
1114 int8_t max = mui_u8g2_s8mm_get_max(vmm);
1115 uint8_t cnt = 1; // number of digits
1116
1117 if (*value > max)
1118 *value = max;
1119 if (*value <= min)
1120 *value = min;
1121 if (max >= 10 || max <= -10 || min >= 10 || min <= -10)
1122 cnt = 2;
1123 if (max >= 100 || max <= -100 || min >= 100 || min <= -100)
1124 cnt = 3;
1125 buf[cnt + 1] = '\0';
1126 mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, buf) + 1, 1,
1127 u8x8_s8toa(*value, cnt));
1128}
1129
1130uint8_t mui_u8g2_s8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg) {
1131 mui_u8g2_s8_min_max_t *vmm =
1132 (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
1133 int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
1134 int8_t min = mui_u8g2_s8mm_get_min(vmm);
1135 int8_t max = mui_u8g2_s8mm_get_max(vmm);
1136 switch (msg) {
1137 case MUIF_MSG_DRAW:
1138 mui_u8g2_s8_vmm_draw_wm_pi(ui);
1139 break;
1140 case MUIF_MSG_FORM_START:
1141 break;
1142 case MUIF_MSG_FORM_END:
1143 break;
1144 case MUIF_MSG_CURSOR_ENTER:
1145 break;
1146 case MUIF_MSG_CURSOR_SELECT:
1147 case MUIF_MSG_VALUE_INCREMENT:
1148 (*value)++;
1149 if (*value > max)
1150 *value = min;
1151 break;
1152 case MUIF_MSG_VALUE_DECREMENT:
1153 if (*value > min)
1154 (*value)--;
1155 else
1156 *value = max;
1157 break;
1158 case MUIF_MSG_CURSOR_LEAVE:
1159 break;
1160 case MUIF_MSG_TOUCH_DOWN:
1161 break;
1162 case MUIF_MSG_TOUCH_UP:
1163 break;
1164 }
1165 return 0;
1166}
1167
1168uint8_t mui_u8g2_s8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg) {
1169 mui_u8g2_s8_min_max_t *vmm =
1170 (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
1171 int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
1172 int8_t min = mui_u8g2_s8mm_get_min(vmm);
1173 int8_t max = mui_u8g2_s8mm_get_max(vmm);
1174 switch (msg) {
1175 case MUIF_MSG_DRAW:
1176 mui_u8g2_s8_vmm_draw_wm_pi(ui);
1177 break;
1178 case MUIF_MSG_FORM_START:
1179 break;
1180 case MUIF_MSG_FORM_END:
1181 break;
1182 case MUIF_MSG_CURSOR_ENTER:
1183 break;
1184 case MUIF_MSG_CURSOR_SELECT:
1185 case MUIF_MSG_VALUE_INCREMENT:
1186 case MUIF_MSG_VALUE_DECREMENT:
1187 /* toggle between normal mode and capture next/prev mode */
1188 ui->is_mud = !ui->is_mud;
1189 break;
1190 case MUIF_MSG_CURSOR_LEAVE:
1191 break;
1192 case MUIF_MSG_TOUCH_DOWN:
1193 break;
1194 case MUIF_MSG_TOUCH_UP:
1195 break;
1196 case MUIF_MSG_EVENT_NEXT:
1197 if (ui->is_mud) {
1198 (*value)++;
1199 if (*value > max)
1200 *value = min;
1201 return 1;
1202 }
1203 break;
1204 case MUIF_MSG_EVENT_PREV:
1205 if (ui->is_mud) {
1206 if (*value <= min)
1207 *value = max;
1208 else
1209 (*value)--;
1210 return 1;
1211 }
1212 break;
1213 }
1214 return 0;
1215}
1216
1217static void mui_u8g2_s8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
1218static void mui_u8g2_s8_vmm_draw_wm_pf(mui_t *ui) {
1219 u8g2_t *u8g2 = mui_get_U8g2(ui);
1220 mui_u8g2_s8_min_max_t *vmm =
1221 (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
1222 char buf[4] = "999";
1223 // char *s = buf;
1224 int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
1225 int8_t min = mui_u8g2_s8mm_get_min(vmm);
1226 int8_t max = mui_u8g2_s8mm_get_max(vmm);
1227 uint8_t cnt = 1; // number of digits
1228
1229 if (*value > max)
1230 *value = max;
1231 if (*value <= min)
1232 *value = min;
1233 if (max >= 10 || max <= -10 || min >= 10 || min <= -10)
1234 cnt = 2;
1235 if (max >= 100 || max <= -100 || min >= 100 || min <= -100)
1236 cnt = 3;
1237 buf[cnt + 1] = '\0';
1238 mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, buf) + 1, 1,
1239 u8x8_s8toa(*value, cnt));
1240}
1241
1242uint8_t mui_u8g2_s8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg) {
1243 mui_u8g2_s8_min_max_t *vmm =
1244 (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
1245 int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
1246 int8_t min = mui_u8g2_s8mm_get_min(vmm);
1247 int8_t max = mui_u8g2_s8mm_get_max(vmm);
1248 switch (msg) {
1249 case MUIF_MSG_DRAW:
1250 mui_u8g2_s8_vmm_draw_wm_pf(ui);
1251 break;
1252 case MUIF_MSG_FORM_START:
1253 break;
1254 case MUIF_MSG_FORM_END:
1255 break;
1256 case MUIF_MSG_CURSOR_ENTER:
1257 break;
1258 case MUIF_MSG_CURSOR_SELECT:
1259 case MUIF_MSG_VALUE_INCREMENT:
1260 (*value)++;
1261 if (*value > max)
1262 *value = min;
1263 break;
1264 case MUIF_MSG_VALUE_DECREMENT:
1265 if (*value > min)
1266 (*value)--;
1267 else
1268 *value = max;
1269 break;
1270 case MUIF_MSG_CURSOR_LEAVE:
1271 break;
1272 case MUIF_MSG_TOUCH_DOWN:
1273 break;
1274 case MUIF_MSG_TOUCH_UP:
1275 break;
1276 }
1277 return 0;
1278}
1279
1280uint8_t mui_u8g2_s8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg) {
1281 mui_u8g2_s8_min_max_t *vmm =
1282 (mui_u8g2_s8_min_max_t *)muif_get_data(ui->uif);
1283 int8_t *value = mui_u8g2_s8mm_get_valptr(vmm);
1284 int8_t min = mui_u8g2_s8mm_get_min(vmm);
1285 int8_t max = mui_u8g2_s8mm_get_max(vmm);
1286 switch (msg) {
1287 case MUIF_MSG_DRAW:
1288 mui_u8g2_s8_vmm_draw_wm_pf(ui);
1289 break;
1290 case MUIF_MSG_FORM_START:
1291 break;
1292 case MUIF_MSG_FORM_END:
1293 break;
1294 case MUIF_MSG_CURSOR_ENTER:
1295 break;
1296 case MUIF_MSG_CURSOR_SELECT:
1297 case MUIF_MSG_VALUE_INCREMENT:
1298 case MUIF_MSG_VALUE_DECREMENT:
1299 /* toggle between normal mode and capture next/prev mode */
1300 ui->is_mud = !ui->is_mud;
1301 break;
1302 case MUIF_MSG_CURSOR_LEAVE:
1303 break;
1304 case MUIF_MSG_TOUCH_DOWN:
1305 break;
1306 case MUIF_MSG_TOUCH_UP:
1307 break;
1308 case MUIF_MSG_EVENT_NEXT:
1309 if (ui->is_mud) {
1310 (*value)++;
1311 if (*value > max)
1312 *value = min;
1313 return 1;
1314 }
1315 break;
1316 case MUIF_MSG_EVENT_PREV:
1317 if (ui->is_mud) {
1318 if (*value <= min)
1319 *value = max;
1320 else
1321 (*value)--;
1322 return 1;
1323 }
1324 break;
1325 }
1326 return 0;
1327}
1328
1329/*===============================================================================*/
1330/* x8 min max */
1331
1332static void mui_u8g2_x8_vmm_draw_wm_pi(mui_t *ui) MUI_NOINLINE;
1333static void mui_u8g2_x8_vmm_draw_wm_pi(mui_t *ui) {
1334 u8g2_t *u8g2 = mui_get_U8g2(ui);
1335 mui_u8g2_u8_min_max_t *vmm =
1336 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1337 char buf[3] = "FF";
1338 char *s = buf;
1339 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1340 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1341 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1342 uint8_t cnt = 2;
1343
1344 if (*value > max)
1345 *value = max;
1346 if (*value <= min)
1347 *value = min;
1348 if (max < 16) {
1349 s++;
1350 cnt--;
1351 }
1352 mui_u8g2_draw_button_pi(ui, u8g2_GetStrWidth(u8g2, s) + 1, 1,
1353 u8x8_u8tox(*value, cnt));
1354}
1355
1356uint8_t mui_x8g2_x8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg) {
1357 mui_u8g2_u8_min_max_t *vmm =
1358 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1359 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1360 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1361 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1362 switch (msg) {
1363 case MUIF_MSG_DRAW:
1364 mui_u8g2_x8_vmm_draw_wm_pi(ui);
1365 break;
1366 case MUIF_MSG_FORM_START:
1367 break;
1368 case MUIF_MSG_FORM_END:
1369 break;
1370 case MUIF_MSG_CURSOR_ENTER:
1371 break;
1372 case MUIF_MSG_CURSOR_SELECT:
1373 case MUIF_MSG_VALUE_INCREMENT:
1374 (*value)++;
1375 if (*value > max)
1376 *value = min;
1377 break;
1378 case MUIF_MSG_VALUE_DECREMENT:
1379 if (*value > min)
1380 (*value)--;
1381 else
1382 *value = max;
1383 break;
1384 case MUIF_MSG_CURSOR_LEAVE:
1385 break;
1386 case MUIF_MSG_TOUCH_DOWN:
1387 break;
1388 case MUIF_MSG_TOUCH_UP:
1389 break;
1390 }
1391 return 0;
1392}
1393
1394uint8_t mui_u8g2_x8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg) {
1395 mui_u8g2_u8_min_max_t *vmm =
1396 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1397 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1398 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1399 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1400 switch (msg) {
1401 case MUIF_MSG_DRAW:
1402 mui_u8g2_x8_vmm_draw_wm_pi(ui);
1403 break;
1404 case MUIF_MSG_FORM_START:
1405 break;
1406 case MUIF_MSG_FORM_END:
1407 break;
1408 case MUIF_MSG_CURSOR_ENTER:
1409 break;
1410 case MUIF_MSG_CURSOR_SELECT:
1411 case MUIF_MSG_VALUE_INCREMENT:
1412 case MUIF_MSG_VALUE_DECREMENT:
1413 /* toggle between normal mode and capture next/prev mode */
1414 ui->is_mud = !ui->is_mud;
1415 break;
1416 case MUIF_MSG_CURSOR_LEAVE:
1417 break;
1418 case MUIF_MSG_TOUCH_DOWN:
1419 break;
1420 case MUIF_MSG_TOUCH_UP:
1421 break;
1422 case MUIF_MSG_EVENT_NEXT:
1423 if (ui->is_mud) {
1424 (*value)++;
1425 if (*value > max)
1426 *value = min;
1427 return 1;
1428 }
1429 break;
1430 case MUIF_MSG_EVENT_PREV:
1431 if (ui->is_mud) {
1432 if (*value <= min)
1433 *value = max;
1434 else
1435 (*value)--;
1436 return 1;
1437 }
1438 break;
1439 }
1440 return 0;
1441}
1442
1443static void mui_u8g2_x8_vmm_draw_wm_pf(mui_t *ui) MUI_NOINLINE;
1444static void mui_u8g2_x8_vmm_draw_wm_pf(mui_t *ui) {
1445 u8g2_t *u8g2 = mui_get_U8g2(ui);
1446 mui_u8g2_u8_min_max_t *vmm =
1447 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1448 char buf[3] = "FF";
1449 char *s = buf;
1450 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1451 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1452 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1453 uint8_t cnt = 2;
1454
1455 if (*value > max)
1456 *value = max;
1457 if (*value <= min)
1458 *value = min;
1459 if (max < 16) {
1460 s++;
1461 cnt--;
1462 }
1463 mui_u8g2_draw_button_pf(ui, u8g2_GetStrWidth(u8g2, s) + 1, 1,
1464 u8x8_u8tox(*value, cnt));
1465}
1466
1467uint8_t mui_u8g2_x8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg) {
1468 mui_u8g2_u8_min_max_t *vmm =
1469 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1470 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1471 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1472 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1473 switch (msg) {
1474 case MUIF_MSG_DRAW:
1475 mui_u8g2_x8_vmm_draw_wm_pf(ui);
1476 break;
1477 case MUIF_MSG_FORM_START:
1478 break;
1479 case MUIF_MSG_FORM_END:
1480 break;
1481 case MUIF_MSG_CURSOR_ENTER:
1482 break;
1483 case MUIF_MSG_CURSOR_SELECT:
1484 case MUIF_MSG_VALUE_INCREMENT:
1485 (*value)++;
1486 if (*value > max)
1487 *value = min;
1488 break;
1489 case MUIF_MSG_VALUE_DECREMENT:
1490 if (*value > min)
1491 (*value)--;
1492 else
1493 *value = max;
1494 break;
1495 case MUIF_MSG_CURSOR_LEAVE:
1496 break;
1497 case MUIF_MSG_TOUCH_DOWN:
1498 break;
1499 case MUIF_MSG_TOUCH_UP:
1500 break;
1501 }
1502 return 0;
1503}
1504
1505uint8_t mui_u8g2_x8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg) {
1506 mui_u8g2_u8_min_max_t *vmm =
1507 (mui_u8g2_u8_min_max_t *)muif_get_data(ui->uif);
1508 uint8_t *value = mui_u8g2_u8mm_get_valptr(vmm);
1509 uint8_t min = mui_u8g2_u8mm_get_min(vmm);
1510 uint8_t max = mui_u8g2_u8mm_get_max(vmm);
1511 switch (msg) {
1512 case MUIF_MSG_DRAW:
1513 mui_u8g2_x8_vmm_draw_wm_pf(ui);
1514 break;
1515 case MUIF_MSG_FORM_START:
1516 break;
1517 case MUIF_MSG_FORM_END:
1518 break;
1519 case MUIF_MSG_CURSOR_ENTER:
1520 break;
1521 case MUIF_MSG_CURSOR_SELECT:
1522 case MUIF_MSG_VALUE_INCREMENT:
1523 case MUIF_MSG_VALUE_DECREMENT:
1524 /* toggle between normal mode and capture next/prev mode */
1525 ui->is_mud = !ui->is_mud;
1526 break;
1527 case MUIF_MSG_CURSOR_LEAVE:
1528 break;
1529 case MUIF_MSG_TOUCH_DOWN:
1530 break;
1531 case MUIF_MSG_TOUCH_UP:
1532 break;
1533 case MUIF_MSG_EVENT_NEXT:
1534 if (ui->is_mud) {
1535 (*value)++;
1536 if (*value > max)
1537 *value = min;
1538 return 1;
1539 }
1540 break;
1541 case MUIF_MSG_EVENT_PREV:
1542 if (ui->is_mud) {
1543 if (*value <= min)
1544 *value = max;
1545 else
1546 (*value)--;
1547 return 1;
1548 }
1549 break;
1550 }
1551 return 0;
1552}
1553
1554/*===============================================================================*/
1555/* u8 bar graph */
1556
1557static uint8_t mui_u8g2_u8_bar_mse_msg_handler(mui_t *ui,
1558 uint8_t msg) MUI_NOINLINE;
1559static uint8_t mui_u8g2_u8_bar_mse_msg_handler(mui_t *ui, uint8_t msg) {
1560 mui_u8g2_u8_min_max_step_t *vmms =
1561 (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
1562 uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
1563 uint8_t min = mui_u8g2_u8mms_get_min(vmms);
1564 uint8_t max = mui_u8g2_u8mms_get_max(vmms);
1565 uint8_t step = mui_u8g2_u8mms_get_step(vmms);
1566 uint8_t flags = mui_u8g2_u8mms_get_flags(vmms);
1567
1568 switch (msg) {
1569 case MUIF_MSG_DRAW:
1570 break;
1571 case MUIF_MSG_FORM_START:
1572 break;
1573 case MUIF_MSG_FORM_END:
1574 break;
1575 case MUIF_MSG_CURSOR_ENTER:
1576 break;
1577 case MUIF_MSG_CURSOR_SELECT:
1578 case MUIF_MSG_VALUE_INCREMENT:
1579 (*value) += step;
1580 if (*value > max) {
1581 if (flags & MUI_MMS_NO_WRAP)
1582 *value = max;
1583 else
1584 *value = min;
1585 }
1586 break;
1587 case MUIF_MSG_VALUE_DECREMENT:
1588 if (*value >= min + step)
1589 (*value) -= step;
1590 else {
1591 if (flags & MUI_MMS_NO_WRAP)
1592 *value = min;
1593 else
1594 *value = max;
1595 }
1596 break;
1597 case MUIF_MSG_CURSOR_LEAVE:
1598 break;
1599 case MUIF_MSG_TOUCH_DOWN:
1600 break;
1601 case MUIF_MSG_TOUCH_UP:
1602 break;
1603 }
1604 return 0;
1605}
1606
1607static uint8_t mui_u8g2_u8_bar_mud_msg_handler(mui_t *ui,
1608 uint8_t msg) MUI_NOINLINE;
1609static uint8_t mui_u8g2_u8_bar_mud_msg_handler(mui_t *ui, uint8_t msg) {
1610 mui_u8g2_u8_min_max_step_t *vmms =
1611 (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
1612 uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
1613 uint8_t min = mui_u8g2_u8mms_get_min(vmms);
1614 uint8_t max = mui_u8g2_u8mms_get_max(vmms);
1615 uint8_t step = mui_u8g2_u8mms_get_step(vmms);
1616 uint8_t flags = mui_u8g2_u8mms_get_flags(vmms);
1617 switch (msg) {
1618 case MUIF_MSG_DRAW:
1619 break;
1620 case MUIF_MSG_FORM_START:
1621 break;
1622 case MUIF_MSG_FORM_END:
1623 break;
1624 case MUIF_MSG_CURSOR_ENTER:
1625 break;
1626 case MUIF_MSG_CURSOR_SELECT:
1627 case MUIF_MSG_VALUE_INCREMENT:
1628 case MUIF_MSG_VALUE_DECREMENT:
1629 /* toggle between normal mode and capture next/prev mode */
1630 ui->is_mud = !ui->is_mud;
1631 break;
1632 case MUIF_MSG_CURSOR_LEAVE:
1633 break;
1634 case MUIF_MSG_TOUCH_DOWN:
1635 break;
1636 case MUIF_MSG_TOUCH_UP:
1637 break;
1638 case MUIF_MSG_EVENT_NEXT:
1639 if (ui->is_mud) {
1640 (*value) += step;
1641 if (*value > max) {
1642 if (flags & MUI_MMS_NO_WRAP)
1643 *value = max;
1644 else
1645 *value = min;
1646 }
1647 return 1;
1648 }
1649 break;
1650 case MUIF_MSG_EVENT_PREV:
1651 if (ui->is_mud) {
1652 if (*value <= min || *value > max) {
1653 if (flags & MUI_MMS_NO_WRAP)
1654 *value = min;
1655 else
1656 *value = max;
1657 } else
1658 (*value) -= step;
1659 return 1;
1660 }
1661 break;
1662 }
1663 return 0;
1664}
1665
1666static void mui_u8g2_u8_bar_draw_wm(mui_t *ui, uint8_t flags,
1667 uint8_t is_fixed_width) MUI_NOINLINE;
1668static void mui_u8g2_u8_bar_draw_wm(mui_t *ui, uint8_t flags,
1669 uint8_t is_fixed_width) {
1670 u8g2_t *u8g2 = mui_get_U8g2(ui);
1671 mui_u8g2_u8_min_max_step_t *vmms =
1672 (mui_u8g2_u8_min_max_step_t *)muif_get_data(ui->uif);
1673 char buf[4] = "999";
1674 char *s = buf;
1675 uint8_t *value = mui_u8g2_u8mms_get_valptr(vmms);
1676 uint8_t min = mui_u8g2_u8mms_get_min(vmms);
1677 uint8_t max = mui_u8g2_u8mms_get_max(vmms);
1678 uint8_t scale = 0;
1679 // uint8_t step = mui_u8g2_u8mms_get_step(vmms);
1680 uint8_t mms_flags = mui_u8g2_u8mms_get_flags(vmms);
1681 uint8_t cnt = 3;
1682 uint8_t height = u8g2_GetAscent(u8g2);
1683 int8_t backup_descent;
1684 u8g2_uint_t x = mui_get_x(ui);
1685 u8g2_uint_t w = 0;
1686 u8g2_uint_t v; // the calculated pixel value
1687
1688 if (mms_flags & MUI_MMS_2X_BAR)
1689 scale |= 1;
1690 if (mms_flags & MUI_MMS_4X_BAR)
1691 scale |= 2;
1692
1693 if (*value > max)
1694 *value = max;
1695 if (*value <= min)
1696 *value = min;
1697 if (max < 100) {
1698 s++;
1699 cnt--;
1700 }
1701 if (max < 10) {
1702 s++;
1703 cnt--;
1704 }
1705
1706 if (is_fixed_width == 0) {
1707 w += (max
1708 << scale); // total width of the bar is derived from the max value
1709 v = (*value) << scale; // pixel position for the current value
1710 } else {
1711 u8g2_uint_t width = mui_u8g2_u8mms_get_width(vmms);
1712
1713 w += (width
1714 << scale); // total width of bar is defined by the width argument
1715 v = ((u8g2_long_t)(*value) * (u8g2_long_t)(width << scale)) /
1716 (u8g2_long_t)
1717 max; // u8g2_long_t is int32_t if 16 bit mode is enabled
1718 }
1719
1720 w += 2; // add gap for the frame
1721
1722 u8g2_DrawFrame(u8g2, x, mui_get_y(ui) - height, w, height);
1723 u8g2_DrawBox(u8g2, x + 1, mui_get_y(ui) - height + 1, v, height - 2);
1724 if (mms_flags & MUI_MMS_SHOW_VALUE) {
1725 w += 2;
1726 u8g2_DrawStr(u8g2, x + w, mui_get_y(ui), u8x8_u8toa(*value, cnt));
1727 w += u8g2_GetStrWidth(u8g2, s);
1728 w += 1;
1729 }
1730 backup_descent = u8g2->font_ref_descent;
1731 u8g2->font_ref_descent =
1732 0; /* hmm... that's a low level hack so that DrawButtonFrame ignores the
1733 descent value of the font */
1734 u8g2_DrawButtonFrame(u8g2, x, mui_get_y(ui), flags, w, 1, 1);
1735 u8g2->font_ref_descent = backup_descent;
1736}
1737
1738// #define MUIF_U8G2_U8_MIN_MAX_STEP(id, valptr, min, max, step, flags, muif)
1739
1740uint8_t mui_u8g2_u8_bar_wm_mse_pi(mui_t *ui, uint8_t msg) {
1741 switch (msg) {
1742 case MUIF_MSG_DRAW:
1743 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 0);
1744 break;
1745 default:
1746 return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
1747 }
1748 return 0;
1749}
1750
1751uint8_t mui_u8g2_u8_bar_wm_mud_pi(mui_t *ui, uint8_t msg) {
1752 switch (msg) {
1753 case MUIF_MSG_DRAW:
1754 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 0);
1755 break;
1756 default:
1757 return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
1758 }
1759 return 0;
1760}
1761
1762uint8_t mui_u8g2_u8_bar_wm_mse_pf(mui_t *ui, uint8_t msg) {
1763 switch (msg) {
1764 case MUIF_MSG_DRAW:
1765 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 0);
1766 break;
1767 default:
1768 return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
1769 }
1770 return 0;
1771}
1772
1773uint8_t mui_u8g2_u8_bar_wm_mud_pf(mui_t *ui, uint8_t msg) {
1774 switch (msg) {
1775 case MUIF_MSG_DRAW:
1776 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 0);
1777 break;
1778 default:
1779 return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
1780 }
1781 return 0;
1782}
1783
1784// #define MUIF_U8G2_U8_MIN_MAX_STEP_WIDTH(id, valptr, min, max, step, width,
1785// flags, muif)
1786
1787uint8_t mui_u8g2_u8_fixed_width_bar_wm_mse_pi(mui_t *ui, uint8_t msg) {
1788 switch (msg) {
1789 case MUIF_MSG_DRAW:
1790 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 1);
1791 break;
1792 default:
1793 return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
1794 }
1795 return 0;
1796}
1797
1798uint8_t mui_u8g2_u8_fixed_width_bar_wm_mud_pi(mui_t *ui, uint8_t msg) {
1799 switch (msg) {
1800 case MUIF_MSG_DRAW:
1801 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pi_flags(ui), 1);
1802 break;
1803 default:
1804 return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
1805 }
1806 return 0;
1807}
1808
1809uint8_t mui_u8g2_u8_fixed_width_bar_wm_mse_pf(mui_t *ui, uint8_t msg) {
1810 switch (msg) {
1811 case MUIF_MSG_DRAW:
1812 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 1);
1813 break;
1814 default:
1815 return mui_u8g2_u8_bar_mse_msg_handler(ui, msg);
1816 }
1817 return 0;
1818}
1819
1820uint8_t mui_u8g2_u8_fixed_width_bar_wm_mud_pf(mui_t *ui, uint8_t msg) {
1821 switch (msg) {
1822 case MUIF_MSG_DRAW:
1823 mui_u8g2_u8_bar_draw_wm(ui, mui_u8g2_get_pf_flags(ui), 1);
1824 break;
1825 default:
1826 return mui_u8g2_u8_bar_mud_msg_handler(ui, msg);
1827 }
1828 return 0;
1829}
1830
1831/*===============================================================================*/
1832
1833static uint8_t mui_is_valid_char(uint8_t c) MUI_NOINLINE;
1834uint8_t mui_is_valid_char(uint8_t c) {
1835 if (c == 32)
1836 return 1;
1837 if (c >= 'A' && c <= 'Z')
1838 return 1;
1839 if (c >= 'a' && c <= 'z')
1840 return 1;
1841 if (c >= '0' && c <= '9')
1842 return 1;
1843 return 0;
1844}
1845
1846uint8_t mui_u8g2_u8_char_wm_mud_pi(mui_t *ui, uint8_t msg) {
1847 // ui->dflags MUIF_DFLAG_IS_CURSOR_FOCUS
1848 // MUIF_DFLAG_IS_TOUCH_FOCUS mui_get_cflags(ui->uif)
1849 // MUIF_CFLAG_IS_CURSOR_SELECTABLE
1850 u8g2_t *u8g2 = mui_get_U8g2(ui);
1851 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
1852 char buf[6];
1853 switch (msg) {
1854 case MUIF_MSG_DRAW:
1855 while (mui_is_valid_char(*value) == 0)
1856 (*value)++;
1857 buf[0] = *value;
1858 buf[1] = '\0';
1859 mui_u8g2_draw_button_pi(ui, u8g2_GetMaxCharWidth(u8g2), 1, buf);
1860 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
1861 // u8g2_GetMaxCharWidth(u8g2), 1, MUI_U8G2_V_PADDING, buf);
1862 // u8g2_DrawButtonUTF8(u8g2, mui_get_x(ui), mui_get_y(ui),
1863 // mui_u8g2_get_pi_flags(ui), u8g2_GetMaxCharWidth(u8g2), 1,
1864 // MUI_U8G2_V_PADDING, buf);
1865 break;
1866 case MUIF_MSG_FORM_START:
1867 break;
1868 case MUIF_MSG_FORM_END:
1869 break;
1870 case MUIF_MSG_CURSOR_ENTER:
1871 break;
1872 case MUIF_MSG_CURSOR_SELECT:
1873 case MUIF_MSG_VALUE_INCREMENT:
1874 case MUIF_MSG_VALUE_DECREMENT:
1875 /* toggle between normal mode and capture next/prev mode */
1876 ui->is_mud = !ui->is_mud;
1877 break;
1878 case MUIF_MSG_CURSOR_LEAVE:
1879 break;
1880 case MUIF_MSG_TOUCH_DOWN:
1881 break;
1882 case MUIF_MSG_TOUCH_UP:
1883 break;
1884 case MUIF_MSG_EVENT_NEXT:
1885 if (ui->is_mud) {
1886 do {
1887 (*value)++;
1888 } while (mui_is_valid_char(*value) == 0);
1889 return 1;
1890 }
1891 break;
1892 case MUIF_MSG_EVENT_PREV:
1893 if (ui->is_mud) {
1894 do {
1895 (*value)--;
1896 } while (mui_is_valid_char(*value) == 0);
1897 return 1;
1898 }
1899 break;
1900 }
1901 return 0;
1902}
1903
1904/*
1905
1906 uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg)
1907
1908 Description:
1909 Select one of several options. First option has value 0.
1910 Only one option is visible.
1911 The visible option is automatically the selected option.
1912
1913 Message Handling: DRAW, SELECT
1914
1915 Style
1916 No Selection: Text only
1917 Cursor Selection: Inverted text
1918
1919 User interface field list (muif):
1920 flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
1921 data: uint8_t *, pointer to a uint8_t variable, which contains the selected
1922 option
1923
1924 Field definition string (fds):
1925 xy: Left position of the text (required)
1926 arg: total width of the selectable option (optional),
1927 text: '|' separated list of options
1928
1929*/
1930uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg) {
1931 // u8g2_t *u8g2 = mui_get_U8g2(ui);
1932 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
1933 switch (msg) {
1934 case MUIF_MSG_DRAW:
1935 if (mui_fds_get_nth_token(ui, *value) == 0) {
1936 *value = 0;
1937 mui_fds_get_nth_token(ui, *value);
1938 }
1939 mui_u8g2_draw_button_pi(ui, ui->arg, 1, ui->text);
1940 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1,
1941 // MUI_U8G2_V_PADDING, ui->text); u8g2_DrawButtonUTF8(u8g2,
1942 // mui_get_x(ui), mui_get_y(ui), mui_u8g2_get_pi_flags(ui), ui->arg, 1,
1943 // MUI_U8G2_V_PADDING, ui->text);
1944
1945 break;
1946 case MUIF_MSG_FORM_START:
1947 break;
1948 case MUIF_MSG_FORM_END:
1949 break;
1950 case MUIF_MSG_CURSOR_ENTER:
1951 break;
1952 case MUIF_MSG_CURSOR_SELECT:
1953 case MUIF_MSG_VALUE_INCREMENT:
1954 (*value)++;
1955 if (mui_fds_get_nth_token(ui, *value) == 0)
1956 *value = 0;
1957 break;
1958 case MUIF_MSG_VALUE_DECREMENT:
1959 if (*value > 0)
1960 (*value)--;
1961 else
1962 (*value) = mui_fds_get_token_cnt(ui) - 1;
1963 break;
1964 case MUIF_MSG_CURSOR_LEAVE:
1965 break;
1966 case MUIF_MSG_TOUCH_DOWN:
1967 break;
1968 case MUIF_MSG_TOUCH_UP:
1969 break;
1970 }
1971 return 0;
1972}
1973
1974uint8_t mui_u8g2_u8_opt_line_wa_mse_pf(mui_t *ui, uint8_t msg) {
1975 // u8g2_t *u8g2 = mui_get_U8g2(ui);
1976 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
1977 switch (msg) {
1978 case MUIF_MSG_DRAW:
1979 if (mui_fds_get_nth_token(ui, *value) == 0) {
1980 *value = 0;
1981 mui_fds_get_nth_token(ui, *value);
1982 }
1983 mui_u8g2_draw_button_pf(ui, ui->arg, 1, ui->text);
1984
1985 break;
1986 case MUIF_MSG_FORM_START:
1987 break;
1988 case MUIF_MSG_FORM_END:
1989 break;
1990 case MUIF_MSG_CURSOR_ENTER:
1991 break;
1992 case MUIF_MSG_CURSOR_SELECT:
1993 case MUIF_MSG_VALUE_INCREMENT:
1994 (*value)++;
1995 if (mui_fds_get_nth_token(ui, *value) == 0)
1996 *value = 0;
1997 break;
1998 case MUIF_MSG_VALUE_DECREMENT:
1999 if (*value > 0)
2000 (*value)--;
2001 else
2002 (*value) = mui_fds_get_token_cnt(ui) - 1;
2003 break;
2004 case MUIF_MSG_CURSOR_LEAVE:
2005 break;
2006 case MUIF_MSG_TOUCH_DOWN:
2007 break;
2008 case MUIF_MSG_TOUCH_UP:
2009 break;
2010 }
2011 return 0;
2012}
2013
2014uint8_t mui_u8g2_u8_opt_line_wa_mud_pi(mui_t *ui, uint8_t msg) {
2015 // u8g2_t *u8g2 = mui_get_U8g2(ui);
2016 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2017 switch (msg) {
2018 case MUIF_MSG_DRAW:
2019 if (mui_fds_get_nth_token(ui, *value) == 0) {
2020 *value = 0;
2021 mui_fds_get_nth_token(ui, *value);
2022 }
2023 mui_u8g2_draw_button_pi(ui, ui->arg, 1, ui->text);
2024
2025 break;
2026 case MUIF_MSG_FORM_START:
2027 break;
2028 case MUIF_MSG_FORM_END:
2029 break;
2030 case MUIF_MSG_CURSOR_ENTER:
2031 break;
2032 case MUIF_MSG_CURSOR_SELECT:
2033 case MUIF_MSG_VALUE_INCREMENT:
2034 case MUIF_MSG_VALUE_DECREMENT:
2035 /* toggle between normal mode and capture next/prev mode */
2036 ui->is_mud = !ui->is_mud;
2037 break;
2038 case MUIF_MSG_CURSOR_LEAVE:
2039 break;
2040 case MUIF_MSG_TOUCH_DOWN:
2041 break;
2042 case MUIF_MSG_TOUCH_UP:
2043 break;
2044 case MUIF_MSG_EVENT_NEXT:
2045 if (ui->is_mud) {
2046 (*value)++;
2047 if (mui_fds_get_nth_token(ui, *value) == 0)
2048 *value = 0;
2049 return 1;
2050 }
2051 break;
2052 case MUIF_MSG_EVENT_PREV:
2053 if (ui->is_mud) {
2054 if (*value == 0)
2055 *value = mui_fds_get_token_cnt(ui);
2056 (*value)--;
2057 return 1;
2058 }
2059 break;
2060 }
2061 return 0;
2062}
2063
2064uint8_t mui_u8g2_u8_opt_line_wa_mud_pf(mui_t *ui, uint8_t msg) {
2065 // u8g2_t *u8g2 = mui_get_U8g2(ui);
2066 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2067 switch (msg) {
2068 case MUIF_MSG_DRAW:
2069 if (mui_fds_get_nth_token(ui, *value) == 0) {
2070 *value = 0;
2071 mui_fds_get_nth_token(ui, *value);
2072 }
2073 mui_u8g2_draw_button_pf(ui, ui->arg, 1, ui->text);
2074
2075 break;
2076 case MUIF_MSG_FORM_START:
2077 break;
2078 case MUIF_MSG_FORM_END:
2079 break;
2080 case MUIF_MSG_CURSOR_ENTER:
2081 break;
2082 case MUIF_MSG_CURSOR_SELECT:
2083 case MUIF_MSG_VALUE_INCREMENT:
2084 case MUIF_MSG_VALUE_DECREMENT:
2085 /* toggle between normal mode and capture next/prev mode */
2086 ui->is_mud = !ui->is_mud;
2087 break;
2088 case MUIF_MSG_CURSOR_LEAVE:
2089 break;
2090 case MUIF_MSG_TOUCH_DOWN:
2091 break;
2092 case MUIF_MSG_TOUCH_UP:
2093 break;
2094 case MUIF_MSG_EVENT_NEXT:
2095 if (ui->is_mud) {
2096 (*value)++;
2097 if (mui_fds_get_nth_token(ui, *value) == 0)
2098 *value = 0;
2099 return 1;
2100 }
2101 break;
2102 case MUIF_MSG_EVENT_PREV:
2103 if (ui->is_mud) {
2104 if (*value == 0)
2105 *value = mui_fds_get_token_cnt(ui);
2106 (*value)--;
2107 return 1;
2108 }
2109 break;
2110 }
2111 return 0;
2112}
2113
2114/*
2115
2116 uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg)
2117
2118 Description:
2119 Checkbox with the values 0 (not selected) and 1 (selected).
2120
2121 Message Handling: DRAW, SELECT
2122
2123 Style
2124 No Selection: Plain checkbox and text
2125 Cursor Selection: Checkbox and text is inverted
2126
2127 User interface field list (muif):
2128 flags: MUIF_CFLAG_IS_CURSOR_SELECTABLE
2129 data: uint8_t *, pointer to a uint8_t variable, which contains the values 0
2130 or 1
2131
2132 Field definition string (fds):
2133 xy: Left position of the text (required)
2134 arg: not used
2135 text: Optional: Text will be printed after the checkbox with a small gap
2136
2137*/
2138
2139uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg) {
2140 u8g2_t *u8g2 = mui_get_U8g2(ui);
2141 u8g2_uint_t flags = 0;
2142 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2143 switch (msg) {
2144 case MUIF_MSG_DRAW:
2145 if (*value > 1)
2146 *value = 1;
2147 if (mui_IsCursorFocus(ui)) {
2148 flags |= U8G2_BTN_INV;
2149 }
2150
2151 {
2152 u8g2_uint_t w = 0;
2153 u8g2_uint_t a = u8g2_GetAscent(u8g2);
2154 if (*value)
2155 u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 1);
2156 else
2157 u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 0);
2158
2159 if (ui->text[0] != '\0') {
2160 w = u8g2_GetUTF8Width(u8g2, ui->text);
2161 // u8g2_SetFontMode(u8g2, 1);
2162 a += 2; /* add gap between the checkbox and the text area */
2163 u8g2_DrawUTF8(u8g2, mui_get_x(ui) + a, mui_get_y(ui), ui->text);
2164 }
2165
2166 u8g2_DrawButtonFrame(u8g2, mui_get_x(ui), mui_get_y(ui), flags,
2167 w + a, 1, MUI_U8G2_V_PADDING);
2168 }
2169 break;
2170 case MUIF_MSG_FORM_START:
2171 break;
2172 case MUIF_MSG_FORM_END:
2173 break;
2174 case MUIF_MSG_CURSOR_ENTER:
2175 break;
2176 case MUIF_MSG_CURSOR_SELECT:
2177 case MUIF_MSG_VALUE_INCREMENT:
2178 case MUIF_MSG_VALUE_DECREMENT:
2179 (*value)++;
2180 if (*value > 1)
2181 *value = 0;
2182 break;
2183 case MUIF_MSG_CURSOR_LEAVE:
2184 break;
2185 case MUIF_MSG_TOUCH_DOWN:
2186 break;
2187 case MUIF_MSG_TOUCH_UP:
2188 break;
2189 }
2190 return 0;
2191}
2192
2193/*
2194 radio button style, arg is assigned as value
2195*/
2196uint8_t mui_u8g2_u8_radio_wm_pi(mui_t *ui, uint8_t msg) {
2197 u8g2_t *u8g2 = mui_get_U8g2(ui);
2198 u8g2_uint_t flags = 0;
2199 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2200 switch (msg) {
2201 case MUIF_MSG_DRAW:
2202 if (mui_IsCursorFocus(ui)) {
2203 flags |= U8G2_BTN_INV;
2204 }
2205
2206 {
2207 u8g2_uint_t w = 0;
2208 u8g2_uint_t a = u8g2_GetAscent(u8g2);
2209 if (*value == ui->arg)
2210 u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 1);
2211 else
2212 u8g2_DrawCheckbox(u8g2, mui_get_x(ui), mui_get_y(ui), a, 0);
2213
2214 if (ui->text[0] != '\0') {
2215 w = u8g2_GetUTF8Width(u8g2, ui->text);
2216 // u8g2_SetFontMode(u8g2, 1);
2217 a += 2; /* add gap between the checkbox and the text area */
2218 u8g2_DrawUTF8(u8g2, mui_get_x(ui) + a, mui_get_y(ui), ui->text);
2219 }
2220
2221 u8g2_DrawButtonFrame(u8g2, mui_get_x(ui), mui_get_y(ui), flags,
2222 w + a, 1, MUI_U8G2_V_PADDING);
2223 }
2224 break;
2225 case MUIF_MSG_FORM_START:
2226 break;
2227 case MUIF_MSG_FORM_END:
2228 break;
2229 case MUIF_MSG_CURSOR_ENTER:
2230 break;
2231 case MUIF_MSG_CURSOR_SELECT:
2232 case MUIF_MSG_VALUE_INCREMENT:
2233 case MUIF_MSG_VALUE_DECREMENT:
2234 *value = ui->arg;
2235 break;
2236 case MUIF_MSG_CURSOR_LEAVE:
2237 break;
2238 case MUIF_MSG_TOUCH_DOWN:
2239 break;
2240 case MUIF_MSG_TOUCH_UP:
2241 break;
2242 }
2243 return 0;
2244}
2245
2246uint8_t mui_u8g2_u8_opt_parent_wm_pi(mui_t *ui, uint8_t msg) {
2247 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2248 switch (msg) {
2249 case MUIF_MSG_DRAW:
2250 if (mui_fds_get_nth_token(ui, *value) == 0) {
2251 *value = 0;
2252 mui_fds_get_nth_token(ui, *value);
2253 }
2254 mui_u8g2_draw_button_pi(ui, 0, 1, ui->text);
2255 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), 0, 1,
2256 // MUI_U8G2_V_PADDING, ui->text);
2257
2258 break;
2259 case MUIF_MSG_FORM_START:
2260 break;
2261 case MUIF_MSG_FORM_END:
2262 break;
2263 case MUIF_MSG_CURSOR_ENTER:
2264 break;
2265 case MUIF_MSG_CURSOR_SELECT:
2266 case MUIF_MSG_VALUE_INCREMENT:
2267 case MUIF_MSG_VALUE_DECREMENT:
2268 mui_SaveForm(ui); // store the current form and position so that the
2269 // child can jump back
2270 mui_GotoForm(ui, ui->arg,
2271 *value); // assumes that the selectable values are at the
2272 // beginning of the form definition
2273 break;
2274 case MUIF_MSG_CURSOR_LEAVE:
2275 break;
2276 case MUIF_MSG_TOUCH_DOWN:
2277 break;
2278 case MUIF_MSG_TOUCH_UP:
2279 break;
2280 }
2281 return 0;
2282}
2283
2284static uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg) {
2285 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2286 uint8_t arg =
2287 ui->arg; // remember the arg value, because it might be overwritten
2288
2289 switch (msg) {
2290 case MUIF_MSG_DRAW:
2291 /* done by the calling function */
2292 break;
2293 case MUIF_MSG_FORM_START:
2294 /* we can assume that the list starts at the top. It will be adjisted by
2295 * cursor down events later */
2296 /* ui->form_scroll_top = 0 and all other form_scroll values are set to 0
2297 * if a new form is entered in mui_EnterForm() */
2298 if (ui->form_scroll_visible <= arg)
2299 ui->form_scroll_visible = arg + 1;
2300 if (ui->form_scroll_total == 0)
2301 ui->form_scroll_total =
2302 mui_GetSelectableFieldOptionCnt(ui, ui->last_form_fds);
2303 // printf("MUIF_MSG_FORM_START: arg=%d visible=%d top=%d total=%d\n",
2304 // arg, ui->form_scroll_visible, ui->form_scroll_top,
2305 // ui->form_scroll_total);
2306 break;
2307 case MUIF_MSG_FORM_END:
2308 break;
2309 case MUIF_MSG_CURSOR_ENTER:
2310 return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
2311 case MUIF_MSG_CURSOR_SELECT:
2312 case MUIF_MSG_VALUE_INCREMENT:
2313 case MUIF_MSG_VALUE_DECREMENT:
2314 if (value != NULL)
2315 *value = ui->form_scroll_top + arg;
2316 mui_RestoreForm(ui);
2317 break;
2318 case MUIF_MSG_CURSOR_LEAVE:
2319 break;
2320 case MUIF_MSG_TOUCH_DOWN:
2321 break;
2322 case MUIF_MSG_TOUCH_UP:
2323 break;
2324 case MUIF_MSG_EVENT_NEXT:
2325 return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
2326 case MUIF_MSG_EVENT_PREV:
2327 return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
2328 }
2329 return 0;
2330}
2331
2332uint8_t mui_u8g2_u8_opt_radio_child_wm_pi(mui_t *ui, uint8_t msg) {
2333 u8g2_t *u8g2 = mui_get_U8g2(ui);
2334 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2335 uint8_t arg =
2336 ui->arg; // remember the arg value, because it might be overwritten
2337
2338 switch (msg) {
2339 case MUIF_MSG_DRAW: {
2340 u8g2_uint_t w = 0;
2341 u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
2342 u8g2_uint_t x =
2343 mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called,
2344 // then field vars are overwritten, so get the value
2345 u8g2_uint_t y =
2346 mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called,
2347 // then field vars are overwritten, so get the value
2348 uint8_t is_focus = mui_IsCursorFocus(ui);
2349 if (*value == arg + ui->form_scroll_top)
2350 u8g2_DrawValueMark(u8g2, x, y, a);
2351
2352 if (ui->text[0] == '\0') {
2353 /* if the text is not provided, then try to get the text from the
2354 * previous (saved) element, assuming that this contains the
2355 * selection */
2356 /* this will overwrite all ui member functions, so we must not
2357 * access any ui members (except ui->text) any more */
2358 mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2359 arg + ui->form_scroll_top);
2360 }
2361
2362 if (ui->text[0] != '\0') {
2363 w = u8g2_GetUTF8Width(u8g2, ui->text);
2364 // u8g2_SetFontMode(u8g2, 1);
2365 a += 2; /* add gap between the checkbox and the text area */
2366 u8g2_DrawUTF8(u8g2, x + a, y, ui->text);
2367 }
2368 if (is_focus) {
2369 u8g2_DrawButtonFrame(u8g2, x, y, U8G2_BTN_INV, w + a, 1,
2370 MUI_U8G2_V_PADDING);
2371 }
2372 } break;
2373 default:
2374 return mui_u8g2_u8_opt_child_mse_common(ui, msg);
2375 }
2376 return 0;
2377}
2378
2379uint8_t mui_u8g2_u8_opt_radio_child_w1_pi(mui_t *ui, uint8_t msg) {
2380 u8g2_t *u8g2 = mui_get_U8g2(ui);
2381 uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2382 uint8_t arg =
2383 ui->arg; // remember the arg value, because it might be overwritten
2384
2385 switch (msg) {
2386 case MUIF_MSG_DRAW: {
2387 // u8g2_uint_t w = 0;
2388 u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
2389 u8g2_uint_t x =
2390 mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called,
2391 // then field vars are overwritten, so get the value
2392 u8g2_uint_t y =
2393 mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called,
2394 // then field vars are overwritten, so get the value
2395 uint8_t is_focus = mui_IsCursorFocus(ui);
2396
2397 if (*value == arg + ui->form_scroll_top)
2398 u8g2_DrawValueMark(u8g2, x, y, a);
2399
2400 if (ui->text[0] == '\0') {
2401 /* if the text is not provided, then try to get the text from the
2402 * previous (saved) element, assuming that this contains the
2403 * selection */
2404 /* this will overwrite all ui member functions, so we must not
2405 * access any ui members (except ui->text) any more */
2406 mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2407 arg + ui->form_scroll_top);
2408 }
2409
2410 if (ui->text[0] != '\0') {
2411 // w = u8g2_GetUTF8Width(u8g2, ui->text);
2412 // u8g2_SetFontMode(u8g2, 1);
2413 a += 2; /* add gap between the checkbox and the text area */
2414 u8g2_DrawUTF8(u8g2, x + a, y, ui->text);
2415 }
2416 if (is_focus) {
2417 u8g2_DrawButtonFrame(u8g2, 0, y, U8G2_BTN_INV,
2418 u8g2_GetDisplayWidth(u8g2), 0,
2419 MUI_U8G2_V_PADDING);
2420 }
2421 } break;
2422 default:
2423 return mui_u8g2_u8_opt_child_mse_common(ui, msg);
2424 }
2425 return 0;
2426}
2427
2428uint8_t mui_u8g2_u8_opt_child_wm_pi(mui_t *ui, uint8_t msg) {
2429 u8g2_t *u8g2 = mui_get_U8g2(ui);
2430 // uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
2431 uint8_t arg =
2432 ui->arg; // remember the arg value, because it might be overwritten
2433
2434 switch (msg) {
2435 case MUIF_MSG_DRAW: {
2436 // u8g2_uint_t w = 0;
2437 u8g2_uint_t x =
2438 mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called,
2439 // then field vars are overwritten, so get the value
2440 u8g2_uint_t y =
2441 mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called,
2442 // then field vars are overwritten, so get the value
2443 uint8_t flags = mui_u8g2_get_pi_flags(ui);
2444 // if ( mui_IsCursorFocus(ui) )
2445 //{
2446 // flags = U8G2_BTN_INV;
2447 // }
2448
2449 if (ui->text[0] == '\0') {
2450 /* if the text is not provided, then try to get the text from the
2451 * previous (saved) element, assuming that this contains the
2452 * selection */
2453 /* this will overwrite all ui member functions, so we must not
2454 * access any ui members (except ui->text) any more */
2455 mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2456 arg + ui->form_scroll_top);
2457 }
2458 if (ui->text[0] != '\0') {
2459 u8g2_DrawButtonUTF8(u8g2, x, y, flags, 0, 1, MUI_U8G2_V_PADDING,
2460 ui->text);
2461 }
2462 } break;
2463 default:
2464 return mui_u8g2_u8_opt_child_mse_common(ui, msg);
2465 }
2466 return 0;
2467}
2468
2469/*
2470 an invisible field (which will not show anything). It should also not be
2471 selectable it just provides the menu entries, see
2472 "mui_u8g2_u8_opt_child_mse_common" and friends as a consequence it does not
2473 have width, input mode and style
2474
2475 MUIF: MUIF_RO()
2476 FDS: MUI_DATA()
2477
2478 mui_u8g2_goto_parent --> mui_u8g2_goto_data
2479
2480 Used together with mui_u8g2_goto_form_w1_pi
2481
2482*/
2483uint8_t mui_u8g2_goto_data(mui_t *ui, uint8_t msg) {
2484 switch (msg) {
2485 case MUIF_MSG_DRAW:
2486 break;
2487 case MUIF_MSG_FORM_START:
2488 // store the field (and the corresponding elements) in the last_form_fds
2489 // variable. last_form_fds is later used to access the elements (see
2490 // mui_u8g2_u8_opt_child_mse_common and friends)
2491 ui->last_form_fds = ui->fds;
2492 break;
2493 case MUIF_MSG_FORM_END:
2494 break;
2495 case MUIF_MSG_CURSOR_ENTER:
2496 break;
2497 case MUIF_MSG_CURSOR_SELECT:
2498 break;
2499 case MUIF_MSG_CURSOR_LEAVE:
2500 break;
2501 case MUIF_MSG_TOUCH_DOWN:
2502 break;
2503 case MUIF_MSG_TOUCH_UP:
2504 break;
2505 }
2506 return 0;
2507}
2508
2509/*
2510mui_u8g2_goto_child_w1_mse_pi --> mui_u8g2_goto_form_w1_pi
2511*/
2512uint8_t mui_u8g2_goto_form_w1_pi(mui_t *ui, uint8_t msg) {
2513 u8g2_t *u8g2 = mui_get_U8g2(ui);
2514 uint8_t arg =
2515 ui->arg; // remember the arg value, because it might be overwritten
2516 switch (msg) {
2517 case MUIF_MSG_DRAW:
2518 if (mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2519 arg + ui->form_scroll_top))
2520 mui_u8g2_draw_button_pi(
2521 ui, u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
2522 mui_get_x(ui), ui->text + 1);
2523 break;
2524 case MUIF_MSG_CURSOR_SELECT:
2525 if (mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2526 ui->arg + ui->form_scroll_top)) {
2527 mui_SaveFormWithCursorPosition(ui, ui->arg + ui->form_scroll_top);
2528 mui_SaveCursorPosition(
2529 ui,
2530 ui->arg +
2531 ui->form_scroll_top); // store the current cursor position,
2532 // so that the user can jump back to
2533 // the corresponding cursor position
2534 return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
2535 }
2536 break;
2537 default:
2538 return mui_u8g2_u8_opt_child_mse_common(ui, msg);
2539 }
2540 return 0;
2541}
2542
2543uint8_t mui_u8g2_goto_form_w1_pf(mui_t *ui, uint8_t msg) {
2544 u8g2_t *u8g2 = mui_get_U8g2(ui);
2545 uint8_t arg =
2546 ui->arg; // remember the arg value, because it might be overwritten
2547 switch (msg) {
2548 case MUIF_MSG_DRAW:
2549 if (mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2550 arg + ui->form_scroll_top))
2551 mui_u8g2_draw_button_pf(
2552 ui, u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
2553 mui_get_x(ui) - 1, ui->text + 1);
2554 break;
2555 case MUIF_MSG_CURSOR_SELECT:
2556 if (mui_GetSelectableFieldTextOption(ui, ui->last_form_fds,
2557 ui->arg + ui->form_scroll_top)) {
2558 mui_SaveFormWithCursorPosition(ui, ui->arg + ui->form_scroll_top);
2559 mui_SaveCursorPosition(
2560 ui,
2561 ui->arg +
2562 ui->form_scroll_top); // store the current cursor position,
2563 // so that the user can jump back to
2564 // the corresponding cursor position
2565 return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
2566 }
2567 break;
2568 default:
2569 return mui_u8g2_u8_opt_child_mse_common(ui, msg);
2570 }
2571 return 0;
2572}
2573
2574/*
2575 data: mui_u8g2_list_t *
2576*/
2577uint8_t mui_u8g2_u16_list_line_wa_mse_pi(mui_t *ui, uint8_t msg) {
2578 // u8g2_t *u8g2 = mui_get_U8g2(ui);
2579 mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
2580 uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
2581 void *data = mui_u8g2_list_get_data_ptr(list);
2582 mui_u8g2_get_list_element_cb element_cb =
2583 mui_u8g2_list_get_element_cb(list);
2584 mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
2585
2586 switch (msg) {
2587 case MUIF_MSG_DRAW:
2588 mui_u8g2_draw_button_pi(ui, ui->arg, 1, element_cb(data, *selection));
2589 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1,
2590 // MUI_U8G2_V_PADDING, element_cb(data, *selection));
2591 break;
2592 case MUIF_MSG_FORM_START:
2593 break;
2594 case MUIF_MSG_FORM_END:
2595 break;
2596 case MUIF_MSG_CURSOR_ENTER:
2597 break;
2598 case MUIF_MSG_CURSOR_SELECT:
2599 case MUIF_MSG_VALUE_INCREMENT:
2600 (*selection)++;
2601 if (*selection >= count_cb(data))
2602 *selection = 0;
2603 break;
2604 case MUIF_MSG_VALUE_DECREMENT:
2605 if (*selection > 0)
2606 (*selection)--;
2607 else
2608 (*selection) = count_cb(data) - 1;
2609 break;
2610 case MUIF_MSG_CURSOR_LEAVE:
2611 break;
2612 case MUIF_MSG_TOUCH_DOWN:
2613 break;
2614 case MUIF_MSG_TOUCH_UP:
2615 break;
2616 }
2617 return 0;
2618}
2619
2620uint8_t mui_u8g2_u16_list_line_wa_mud_pi(mui_t *ui, uint8_t msg) {
2621 // u8g2_t *u8g2 = mui_get_U8g2(ui);
2622 mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
2623 uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
2624 void *data = mui_u8g2_list_get_data_ptr(list);
2625 mui_u8g2_get_list_element_cb element_cb =
2626 mui_u8g2_list_get_element_cb(list);
2627 mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
2628
2629 switch (msg) {
2630 case MUIF_MSG_DRAW:
2631 mui_u8g2_draw_button_pi(ui, ui->arg, 1, element_cb(data, *selection));
2632 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1,
2633 // MUI_U8G2_V_PADDING, element_cb(data, *selection));
2634 break;
2635 case MUIF_MSG_FORM_START:
2636 break;
2637 case MUIF_MSG_FORM_END:
2638 break;
2639 case MUIF_MSG_CURSOR_ENTER:
2640 break;
2641 case MUIF_MSG_CURSOR_SELECT:
2642 case MUIF_MSG_VALUE_INCREMENT:
2643 case MUIF_MSG_VALUE_DECREMENT:
2644 /* toggle between normal mode and capture next/prev mode */
2645 ui->is_mud = !ui->is_mud;
2646 break;
2647 case MUIF_MSG_CURSOR_LEAVE:
2648 break;
2649 case MUIF_MSG_TOUCH_DOWN:
2650 break;
2651 case MUIF_MSG_TOUCH_UP:
2652 break;
2653 case MUIF_MSG_EVENT_NEXT:
2654 if (ui->is_mud) {
2655 (*selection)++;
2656 if (*selection >= count_cb(data))
2657 *selection = 0;
2658 return 1;
2659 }
2660 break;
2661 case MUIF_MSG_EVENT_PREV:
2662 if (ui->is_mud) {
2663 if (*selection == 0)
2664 *selection = count_cb(data);
2665 (*selection)--;
2666 return 1;
2667 }
2668 break;
2669 }
2670 return 0;
2671}
2672
2673/*
2674 MUIF: MUIF_U8G2_U16_LIST
2675 FDS: MUI_XYA, arg=form id
2676 data: mui_u8g2_list_t *
2677*/
2678uint8_t mui_u8g2_u16_list_parent_wm_pi(mui_t *ui, uint8_t msg) {
2679 // u8g2_t *u8g2 = mui_get_U8g2(ui);
2680 mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
2681 uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
2682 void *data = mui_u8g2_list_get_data_ptr(list);
2683 mui_u8g2_get_list_element_cb element_cb =
2684 mui_u8g2_list_get_element_cb(list);
2685 // mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
2686 switch (msg) {
2687 case MUIF_MSG_DRAW:
2688 mui_u8g2_draw_button_pi(ui, 0, 1, element_cb(data, *selection));
2689 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui), ui->arg, 1,
2690 // MUI_U8G2_V_PADDING, element_cb(data, *selection));
2691 break;
2692 case MUIF_MSG_FORM_START:
2693 break;
2694 case MUIF_MSG_FORM_END:
2695 break;
2696 case MUIF_MSG_CURSOR_ENTER:
2697 break;
2698 case MUIF_MSG_CURSOR_SELECT:
2699 case MUIF_MSG_VALUE_INCREMENT:
2700 case MUIF_MSG_VALUE_DECREMENT:
2701 mui_SaveForm(ui); // store the current form and position so that the
2702 // child can jump back
2703 mui_GotoForm(ui, ui->arg,
2704 *selection); // assumes that the selectable values are at
2705 // the beginning of the form definition
2706 break;
2707 case MUIF_MSG_CURSOR_LEAVE:
2708 break;
2709 case MUIF_MSG_TOUCH_DOWN:
2710 break;
2711 case MUIF_MSG_TOUCH_UP:
2712 break;
2713 }
2714 return 0;
2715}
2716
2717static uint8_t mui_u8g2_u16_list_child_mse_common(mui_t *ui, uint8_t msg) {
2718 mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
2719 uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
2720 void *data = mui_u8g2_list_get_data_ptr(list);
2721 // mui_u8g2_get_list_element_cb element_cb =
2722 // mui_u8g2_list_get_element_cb(list);
2723 mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
2724
2725 uint8_t arg =
2726 ui->arg; // remember the arg value, because it might be overwritten
2727
2728 switch (msg) {
2729 case MUIF_MSG_DRAW:
2730 /* done by the calling function */
2731 break;
2732 case MUIF_MSG_FORM_START:
2733 /* we can assume that the list starts at the top. It will be adjisted by
2734 * cursor down events later */
2735 ui->form_scroll_top = 0;
2736 if (ui->form_scroll_visible <= arg)
2737 ui->form_scroll_visible = arg + 1;
2738 if (ui->form_scroll_total == 0)
2739 ui->form_scroll_total = count_cb(data);
2740 break;
2741 case MUIF_MSG_FORM_END:
2742 break;
2743 case MUIF_MSG_CURSOR_ENTER:
2744 return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
2745 case MUIF_MSG_CURSOR_SELECT:
2746 case MUIF_MSG_VALUE_INCREMENT:
2747 case MUIF_MSG_VALUE_DECREMENT:
2748 if (selection != NULL)
2749 *selection = ui->form_scroll_top + arg;
2750 mui_RestoreForm(ui);
2751 break;
2752 case MUIF_MSG_CURSOR_LEAVE:
2753 break;
2754 case MUIF_MSG_TOUCH_DOWN:
2755 break;
2756 case MUIF_MSG_TOUCH_UP:
2757 break;
2758 case MUIF_MSG_EVENT_NEXT:
2759 return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
2760 case MUIF_MSG_EVENT_PREV:
2761 return mui_u8g2_handle_scroll_next_prev_events(ui, msg);
2762 }
2763 return 0;
2764}
2765
2766uint8_t mui_u8g2_u16_list_child_w1_pi(mui_t *ui, uint8_t msg) {
2767 u8g2_t *u8g2 = mui_get_U8g2(ui);
2768 mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
2769 uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
2770 void *data = mui_u8g2_list_get_data_ptr(list);
2771 mui_u8g2_get_list_element_cb element_cb =
2772 mui_u8g2_list_get_element_cb(list);
2773 mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
2774 uint16_t pos =
2775 ui->arg; // remember the arg value, because it might be overwritten
2776 switch (msg) {
2777 case MUIF_MSG_DRAW: {
2778 // u8g2_uint_t w = 0;
2779 u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
2780 u8g2_uint_t x =
2781 mui_get_x(ui); // if mui_GetSelectableFieldTextOption is called,
2782 // then field vars are overwritten, so get the value
2783 u8g2_uint_t y =
2784 mui_get_y(ui); // if mui_GetSelectableFieldTextOption is called,
2785 // then field vars are overwritten, so get the value
2786 uint8_t is_focus = mui_IsCursorFocus(ui);
2787
2788 pos += ui->form_scroll_top;
2789
2790 if (*selection == pos)
2791 u8g2_DrawValueMark(u8g2, x, y, a);
2792
2793 // u8g2_SetFontMode(u8g2, 1);
2794 a += 2; /* add gap between the checkbox and the text area */
2795 if (pos < count_cb(data))
2796 u8g2_DrawUTF8(u8g2, x + a, y, element_cb(data, pos));
2797 if (is_focus) {
2798 u8g2_DrawButtonFrame(u8g2, 0, y, U8G2_BTN_INV,
2799 u8g2_GetDisplayWidth(u8g2), 0,
2800 MUI_U8G2_V_PADDING);
2801 }
2802 } break;
2803 default:
2804 return mui_u8g2_u16_list_child_mse_common(ui, msg);
2805 }
2806 return 0;
2807}
2808
2809uint8_t mui_u8g2_u16_list_goto_w1_pi(mui_t *ui, uint8_t msg) {
2810 u8g2_t *u8g2 = mui_get_U8g2(ui);
2811 mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
2812 uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
2813 void *data = mui_u8g2_list_get_data_ptr(list);
2814 mui_u8g2_get_list_element_cb element_cb =
2815 mui_u8g2_list_get_element_cb(list);
2816 // mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
2817
2818 uint16_t pos =
2819 ui->arg; // remember the arg value, because it might be overwritten
2820 pos += ui->form_scroll_top;
2821
2822 switch (msg) {
2823 case MUIF_MSG_DRAW:
2824 mui_u8g2_draw_button_pi(ui,
2825 u8g2_GetDisplayWidth(u8g2) - mui_get_x(ui) * 2,
2826 mui_get_x(ui), element_cb(data, pos) + 1);
2827 // mui_u8g2_draw_button_utf(ui, mui_u8g2_get_pi_flags(ui),
2828 // u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui),
2829 // MUI_U8G2_V_PADDING, element_cb(data, pos)+1);
2830 break;
2831 case MUIF_MSG_CURSOR_SELECT:
2832 case MUIF_MSG_VALUE_INCREMENT:
2833 case MUIF_MSG_VALUE_DECREMENT:
2834 if (selection != NULL)
2835 *selection = pos;
2836 mui_SaveFormWithCursorPosition(ui, pos >= 255 ? 0 : pos);
2837 mui_SaveCursorPosition(
2838 ui,
2839 pos >= 255
2840 ? 0
2841 : pos); // store the current cursor position, so that the user
2842 // can jump back to the corresponding cursor position
2843 mui_GotoFormAutoCursorPosition(ui, (uint8_t)element_cb(data, pos)[0]);
2844 break;
2845 default:
2846 return mui_u8g2_u16_list_child_mse_common(ui, msg);
2847 }
2848 return 0;
2849}