14 static badge_sprite
const arrows
[] = {
15 { 5, 7, (uint8_t const *) "\x04\xc3\xdf\x40" },
16 { 5, 7, (uint8_t const *) "\x10\xd8\x1f\x06\x01" }
21 MENU_MARGIN_BOTTOM
= 3,
23 MENU_ENTRIES_HEIGHT
= 1 + BADGE_FONT_HEIGHT
,
24 MENU_ENTRIES_VISIBLE
= (BADGE_DISPLAY_HEIGHT
- MENU_MARGIN_TOP
- MENU_MARGIN_BOTTOM
) / MENU_ENTRIES_HEIGHT
27 static void badge_menu_show(char const *const *menu
,
32 badge_framebuffer fb
= { { { 0 } } };
34 bool arrow_down
= true;
36 size_t first_used_row
= 0;
37 size_t used_rows
= MENU_ENTRIES_VISIBLE
;
39 if(n
<= MENU_ENTRIES_VISIBLE
) {
42 first_used_row
= (MENU_ENTRIES_VISIBLE
- used_rows
) / 2;
45 if(first_visible
== 0) {
49 if(first_visible
+ MENU_ENTRIES_VISIBLE
>= n
) {
53 for(size_t i
= 0; i
< used_rows
; ++i
) {
54 badge_framebuffer_render_text(&fb
,
55 (int8_t) (MENU_MARGIN_LEFT
+ BADGE_FONT_WIDTH
),
56 (int8_t) (MENU_MARGIN_TOP
+ (first_used_row
+ i
) * MENU_ENTRIES_HEIGHT
),
57 menu
[first_visible
+ i
]);
60 badge_framebuffer_render_char(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
+ MENU_ENTRIES_HEIGHT
* (selected
- first_visible
+ first_used_row
), '*');
61 if(arrow_up
) { badge_framebuffer_blt(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
, &arrows
[MENU_ARROW_UP
], 0); }
62 if(arrow_down
) { badge_framebuffer_blt(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
+ (MENU_ENTRIES_VISIBLE
- 1) * MENU_ENTRIES_HEIGHT
, &arrows
[MENU_ARROW_DOWN
], 0); }
64 badge_framebuffer_flush(&fb
);
67 size_t badge_menu(char const *const *menu
,
69 size_t *first_visible
,
73 badge_menu_show(menu
, n
, *first_visible
, selected
);
78 ev
= badge_event_wait();
79 } while(badge_event_type(ev
) != BADGE_EVENT_USER_INPUT
);
81 uint8_t old_state
= badge_event_old_input_state(ev
);
82 uint8_t new_state
= badge_event_new_input_state(ev
);
83 uint8_t new_buttons
= new_state
& (old_state
^ new_state
);
85 if(new_buttons
& (BADGE_EVENT_KEY_BTN_A
| BADGE_EVENT_KEY_BTN_B
)) {
87 } else if((new_buttons
& BADGE_EVENT_KEY_UP
) && selected
!= 0) {
89 if(*first_visible
!= 0 && selected
<= *first_visible
) {
90 *first_visible
= selected
- 1;
92 } else if(new_buttons
& BADGE_EVENT_KEY_DOWN
&& selected
+ 1 < n
) {
94 if(*first_visible
+ (MENU_ENTRIES_VISIBLE
- 2 + (selected
+ 1 == n
)) < selected
) {
95 *first_visible
= selected
- (MENU_ENTRIES_VISIBLE
- 2 + (selected
+ 1 == n
));
This page took 0.058924 seconds and 5 git commands to generate.