6
6
7
7
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8
8
9
- Copyright (c) 2016 , [email protected]
9
+ Copyright (c) 2021 , [email protected]
10
10
All rights reserved.
11
11
12
12
Redistribution and use in source and binary forms, with or without modification,
80
80
81
81
//#define mui_get_fds_char(s) ((uint8_t)(*s))
82
82
83
-
83
+ //#include <stdio.h>
84
+ //#define MUI_DEBUG(...) printf(__VA_ARGS__)
85
+ #define MUI_DEBUG (...)
84
86
85
87
uint8_t mui_get_fds_char (fds_t * s )
86
88
{
@@ -92,8 +94,8 @@ uint8_t mui_get_fds_char(fds_t *s)
92
94
/*
93
95
s must point to a valid command within FDS
94
96
*/
95
- static size_t mui_fds_get_cmd_size_without_text (mui_t * ui , fds_t * s ) MUI_NOINLINE ;
96
- static size_t mui_fds_get_cmd_size_without_text (mui_t * ui , fds_t * s )
97
+ static size_t mui_fds_get_cmd_size_without_text (fds_t * s ) MUI_NOINLINE ;
98
+ static size_t mui_fds_get_cmd_size_without_text (fds_t * s )
97
99
{
98
100
uint8_t c = mui_get_fds_char (s );
99
101
c &= 0xdf ; /* consider upper and lower case */
@@ -180,7 +182,7 @@ static size_t mui_fds_parse_text(mui_t *ui, fds_t *s)
180
182
uint8_t mui_fds_first_token (mui_t * ui )
181
183
{
182
184
ui -> token = ui -> fds ;
183
- ui -> token += mui_fds_get_cmd_size_without_text (ui , ui -> fds );
185
+ ui -> token += mui_fds_get_cmd_size_without_text (ui -> fds );
184
186
ui -> delimiter = mui_get_fds_char (ui -> token );
185
187
ui -> token ++ ; // place ui->token on the first char of the token
186
188
return mui_fds_next_token (ui );
@@ -271,7 +273,7 @@ uint8_t mui_fds_get_token_cnt(mui_t *ui)
271
273
static size_t mui_fds_get_cmd_size (mui_t * ui , fds_t * s ) MUI_NOINLINE ;
272
274
static size_t mui_fds_get_cmd_size (mui_t * ui , fds_t * s )
273
275
{
274
- size_t l = mui_fds_get_cmd_size_without_text (ui , s );
276
+ size_t l = mui_fds_get_cmd_size_without_text (s );
275
277
uint8_t c = mui_get_fds_char (s );
276
278
ui -> text [0 ] = '\0' ; /* always reset the text buffer */
277
279
if ( mui_fds_is_text (c ) )
@@ -298,7 +300,7 @@ void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, si
298
300
299
301
int mui_find_uif (mui_t * ui , uint8_t id0 , uint8_t id1 )
300
302
{
301
- int i ;
303
+ size_t i ;
302
304
for ( i = 0 ; i < ui -> muif_tcnt ; i ++ )
303
305
{
304
306
/*
@@ -321,7 +323,8 @@ int mui_find_uif(mui_t *ui, uint8_t id0, uint8_t id1)
321
323
will return 1 if the field id was found.
322
324
will return 0 if the field id was not found in uif or if ui->fds points to something else than a field
323
325
*/
324
- uint8_t mui_prepare_current_field (mui_t * ui )
326
+ static uint8_t mui_prepare_current_field (mui_t * ui ) MUI_NOINLINE ;
327
+ static uint8_t mui_prepare_current_field (mui_t * ui )
325
328
{
326
329
int muif_tidx ;
327
330
@@ -338,7 +341,7 @@ uint8_t mui_prepare_current_field(mui_t *ui)
338
341
339
342
/* get the command and check whether end of form is reached */
340
343
ui -> cmd = mui_get_fds_char (ui -> fds );
341
- //printf("mui_prepare_current_field cmd='%c'\n", ui->cmd);
344
+ //printf("mui_prepare_current_field cmd='%c' len=%d \n", ui->cmd, ui->len );
342
345
343
346
/* Copy the cmd also to second id value. This is required for some commands, others will overwrite this below */
344
347
ui -> id1 = ui -> cmd ;
@@ -384,6 +387,9 @@ uint8_t mui_prepare_current_field(mui_t *ui)
384
387
ui -> arg = mui_get_fds_char (ui -> fds + 3 );
385
388
}
386
389
}
390
+
391
+ //MUI_DEBUG("mui_prepare_current_field cmd='%c' len=%d arg=%d\n", ui->cmd, ui->len, ui->arg);
392
+
387
393
388
394
/* find the field */
389
395
muif_tidx = mui_find_uif (ui , ui -> id0 , ui -> id1 );
@@ -404,10 +410,12 @@ uint8_t mui_prepare_current_field(mui_t *ui)
404
410
405
411
*/
406
412
407
- void mui_inner_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui )) MUI_NOINLINE ;
408
- void mui_inner_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui ))
413
+ static void mui_inner_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui )) MUI_NOINLINE ;
414
+ static void mui_inner_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui ))
409
415
{
410
416
uint8_t cmd ;
417
+
418
+ //MUI_DEBUG("mui_inner_loop_over_form start %p\n", task);
411
419
412
420
ui -> fds += mui_fds_get_cmd_size (ui , ui -> fds ); // skip the first entry, it is U always
413
421
for (;;)
@@ -419,13 +427,18 @@ void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
419
427
break ;
420
428
if ( mui_prepare_current_field (ui ) )
421
429
if ( task (ui ) ) /* call the task, which was provided as argument to this function */
430
+ {
431
+ //MUI_DEBUG("mui_inner_loop_over_form break by task\n");
422
432
break ;
433
+ }
423
434
ui -> fds += ui -> len ;
424
435
}
425
- //printf("mui_loop_over_form ended\n");
436
+
437
+ //MUI_DEBUG("mui_inner_loop_over_form end %p\n", task);
426
438
}
427
439
428
- void mui_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui ))
440
+ static void mui_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui )) MUI_NOINLINE ;
441
+ static void mui_loop_over_form (mui_t * ui , uint8_t (* task )(mui_t * ui ))
429
442
{
430
443
if ( mui_IsFormActive (ui ) == 0 )
431
444
return ;
@@ -486,10 +499,20 @@ uint8_t mui_task_form_end(mui_t *ui)
486
499
return 0 ; /* continue with the loop */
487
500
}
488
501
502
+ static uint8_t mui_uif_is_cursor_selectable (mui_t * ui ) MUI_NOINLINE ;
503
+ static uint8_t mui_uif_is_cursor_selectable (mui_t * ui )
504
+ {
505
+ if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
506
+ {
507
+ return 1 ;
508
+ }
509
+ return 0 ;
510
+ }
489
511
490
512
uint8_t mui_task_find_prev_cursor_uif (mui_t * ui )
491
513
{
492
- if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
514
+ //if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
515
+ if ( mui_uif_is_cursor_selectable (ui ) )
493
516
{
494
517
if ( ui -> fds == ui -> cursor_focus_fds )
495
518
{
@@ -503,7 +526,8 @@ uint8_t mui_task_find_prev_cursor_uif(mui_t *ui)
503
526
504
527
uint8_t mui_task_find_first_cursor_uif (mui_t * ui )
505
528
{
506
- if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
529
+ //if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
530
+ if ( mui_uif_is_cursor_selectable (ui ) )
507
531
{
508
532
// if ( ui->target_fds == NULL )
509
533
// {
@@ -516,7 +540,8 @@ uint8_t mui_task_find_first_cursor_uif(mui_t *ui)
516
540
517
541
uint8_t mui_task_find_last_cursor_uif (mui_t * ui )
518
542
{
519
- if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
543
+ //if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
544
+ if ( mui_uif_is_cursor_selectable (ui ) )
520
545
{
521
546
//ui->cursor_focus_position++;
522
547
ui -> target_fds = ui -> fds ;
@@ -526,7 +551,8 @@ uint8_t mui_task_find_last_cursor_uif(mui_t *ui)
526
551
527
552
uint8_t mui_task_find_next_cursor_uif (mui_t * ui )
528
553
{
529
- if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
554
+ //if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
555
+ if ( mui_uif_is_cursor_selectable (ui ) )
530
556
{
531
557
if ( ui -> tmp_fds != NULL )
532
558
{
@@ -544,7 +570,8 @@ uint8_t mui_task_find_next_cursor_uif(mui_t *ui)
544
570
545
571
uint8_t mui_task_get_current_cursor_focus_position (mui_t * ui )
546
572
{
547
- if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
573
+ //if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
574
+ if ( mui_uif_is_cursor_selectable (ui ) )
548
575
{
549
576
if ( ui -> fds == ui -> cursor_focus_fds )
550
577
return 1 ; /* stop looping */
@@ -553,9 +580,10 @@ uint8_t mui_task_get_current_cursor_focus_position(mui_t *ui)
553
580
return 0 ; /* continue with the loop */
554
581
}
555
582
556
- uint8_t mui_task_read_nth_seleectable_field (mui_t * ui )
583
+ uint8_t mui_task_read_nth_selectable_field (mui_t * ui )
557
584
{
558
- if ( muif_get_cflags (ui -> uif ) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
585
+ //if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
586
+ if ( mui_uif_is_cursor_selectable (ui ) )
559
587
{
560
588
if ( ui -> tmp8 == 0 )
561
589
return 1 ; /* stop looping */
@@ -567,14 +595,16 @@ uint8_t mui_task_read_nth_seleectable_field(mui_t *ui)
567
595
568
596
/* === utility functions for the user API === */
569
597
570
- void mui_send_cursor_msg (mui_t * ui , uint8_t msg )
598
+ static uint8_t mui_send_cursor_msg (mui_t * ui , uint8_t msg ) MUI_NOINLINE ;
599
+ static uint8_t mui_send_cursor_msg (mui_t * ui , uint8_t msg )
571
600
{
572
601
if ( ui -> cursor_focus_fds )
573
602
{
574
603
ui -> fds = ui -> cursor_focus_fds ;
575
604
if ( mui_prepare_current_field (ui ) )
576
- muif_get_cb (ui -> uif )(ui , msg );
605
+ return muif_get_cb (ui -> uif )(ui , msg );
577
606
}
607
+ return 0 ; /* not called, msg not handled */
578
608
}
579
609
580
610
/* === user API === */
@@ -626,7 +656,8 @@ void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor
626
656
627
657
// use the inner_loop procedure, because ui->fds has been assigned already
628
658
ui -> tmp8 = cursor_position ; // maybe we should also backup tmp8, but at the moment tmp8 is only used by mui_task_get_current_cursor_focus_position
629
- mui_inner_loop_over_form (ui , mui_task_read_nth_seleectable_field );
659
+ //MUI_DEBUG("mui_GetSelectableFieldTextOption\n");
660
+ mui_inner_loop_over_form (ui , mui_task_read_nth_selectable_field );
630
661
// at this point ui->fds contains the field which was selected from above
631
662
632
663
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
@@ -637,6 +668,42 @@ void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor
637
668
// result is stored in ui->text
638
669
}
639
670
671
+ /*
672
+ this function will overwrite the ui field related member variables
673
+ return the number of options in the referenced field
674
+ */
675
+ uint8_t mui_GetSelectableFieldOptionCnt (mui_t * ui , uint8_t form_id , uint8_t cursor_position )
676
+ {
677
+ fds_t * fds = ui -> fds ; // backup the current fds, so that this function can be called inside a task loop
678
+ int len = ui -> len ; // backup length of the current command
679
+ uint8_t cnt = 0 ;
680
+
681
+ ui -> fds = mui_find_form (ui , form_id ); // search for the target form and overwrite the current fds
682
+
683
+ // use the inner_loop procedure, because ui->fds has been assigned already
684
+ ui -> tmp8 = cursor_position ; // maybe we should also backup tmp8, but at the moment tmp8 is only used by mui_task_get_current_cursor_focus_position
685
+ //MUI_DEBUG("mui_GetSelectableFieldOptionCnt\n");
686
+ mui_inner_loop_over_form (ui , mui_task_read_nth_selectable_field );
687
+ // at this point ui->fds contains the field which was selected from above
688
+
689
+ // now get the opion string out of the text field. nth_token can be 0 if this is no opion string
690
+ cnt = mui_fds_get_token_cnt (ui );
691
+
692
+ ui -> fds = fds ; // restore the previous fds position
693
+ ui -> len = len ;
694
+ // result is stored in ui->text
695
+ return cnt ;
696
+ }
697
+
698
+
699
+
700
+ //static void mui_send_cursor_enter_msg(mui_t *ui) MUI_NOINLINE;
701
+ static void mui_send_cursor_enter_msg (mui_t * ui )
702
+ {
703
+ ui -> is_mud = 0 ;
704
+ mui_send_cursor_msg (ui , MUIF_MSG_CURSOR_ENTER );
705
+ }
706
+
640
707
/*
641
708
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
642
709
mui_EnterForm is similar to mui_GotoForm and differes only in the second argument (which is the form id instead of the fds pointer)
@@ -654,19 +721,22 @@ void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
654
721
ui -> current_form_fds = fds ;
655
722
656
723
/* inform all fields that we start a new form */
724
+ MUI_DEBUG ("mui_EnterForm: form_start\n" );
657
725
mui_loop_over_form (ui , mui_task_form_start );
658
726
659
727
/* assign initional cursor focus */
728
+ MUI_DEBUG ("mui_EnterForm: find_first_cursor_uif\n" );
660
729
mui_loop_over_form (ui , mui_task_find_first_cursor_uif );
661
730
ui -> cursor_focus_fds = ui -> target_fds ; // NULL is ok
731
+ MUI_DEBUG ("mui_EnterForm: find_first_cursor_uif target_fds=%p\n" , ui -> target_fds );
662
732
663
733
while ( initial_cursor_position > 0 )
664
734
{
665
- mui_next_field (ui );
735
+ mui_NextField (ui ); // mui_next_field(ui) is not sufficient in case of scrolling
666
736
initial_cursor_position -- ;
667
737
}
668
738
669
- mui_send_cursor_msg (ui , MUIF_MSG_CURSOR_ENTER );
739
+ mui_send_cursor_enter_msg (ui );
670
740
}
671
741
672
742
/* input: current_form_fds */
@@ -682,6 +752,7 @@ void mui_LeaveForm(mui_t *ui)
682
752
ui -> cursor_focus_fds = NULL ;
683
753
684
754
/* inform all fields that we leave the form */
755
+ MUI_DEBUG ("mui_LeaveForm: form_end\n" );
685
756
mui_loop_over_form (ui , mui_task_form_end );
686
757
ui -> current_form_fds = NULL ;
687
758
}
@@ -725,9 +796,11 @@ void mui_RestoreForm(mui_t *ui)
725
796
*/
726
797
void mui_NextField (mui_t * ui )
727
798
{
799
+ if ( mui_send_cursor_msg (ui , MUIF_MSG_EVENT_NEXT ) )
800
+ return ;
728
801
mui_send_cursor_msg (ui , MUIF_MSG_CURSOR_LEAVE );
729
802
mui_next_field (ui );
730
- mui_send_cursor_msg (ui , MUIF_MSG_CURSOR_ENTER );
803
+ mui_send_cursor_enter_msg (ui );
731
804
}
732
805
733
806
/*
@@ -738,6 +811,8 @@ void mui_NextField(mui_t *ui)
738
811
*/
739
812
void mui_PrevField (mui_t * ui )
740
813
{
814
+ if ( mui_send_cursor_msg (ui , MUIF_MSG_EVENT_PREV ) )
815
+ return ;
741
816
mui_send_cursor_msg (ui , MUIF_MSG_CURSOR_LEAVE );
742
817
743
818
mui_loop_over_form (ui , mui_task_find_prev_cursor_uif );
@@ -750,7 +825,7 @@ void mui_PrevField(mui_t *ui)
750
825
ui -> cursor_focus_fds = ui -> target_fds ; // NULL is ok
751
826
}
752
827
753
- mui_send_cursor_msg (ui , MUIF_MSG_CURSOR_ENTER );
828
+ mui_send_cursor_enter_msg (ui );
754
829
}
755
830
756
831
0 commit comments