add wrap-around option to the menu

master
Ondřej Hruška 5 years ago
parent 202b9e49f7
commit ad3eb59d58
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      main/scenes/scene_manual_menu.c
  2. 12
      main/scenes/scene_menu.c
  3. 7
      main/scenes/scene_menu.h

@ -104,6 +104,7 @@ struct Scene *NewScene_MenuTest() {
scene->base.paint = (Scene_paint_t) paint;
scene->extra = priv;
scene->extra_deinit = (Scene_deinit_t) priv_deinit;
scene->wraparound = true;
// add a child return handler (base does not use this)
scene->base.onChildReturn = (Scene_onChildReturn_t) onChildReturn;

@ -57,10 +57,18 @@ static struct SceneEvent onInput(struct MenuScene *self, struct InputEvent event
case InputEventKind_Wheel:;
self->selected += event.wheel.direction;
if (self->selected < 0) {
self->selected = 0;
if (self->wraparound) {
self->selected = self->items_len - 1;
} else {
self->selected = 0;
}
}
else if (self->selected >= self->items_len) {
self->selected = self->items_len - 1;
if (self->wraparound) {
self->selected = 0;
} else {
self->selected = self->items_len - 1;
}
}
// hacky scroll adjust

@ -8,6 +8,7 @@
#define REFLOWER_SCENE_MENU_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#define MENUITEM_LABEL_LEN 30
@ -38,10 +39,10 @@ struct MenuScene {
struct Scene base;
// items array
struct MenuItem *items;
// allow wrap-around
bool wraparound;
// items count
size_t items_len;
// number of visible characters in a line at a time
uint8_t ncols;
// Vertical scroll offset (how many steps is the topmost item moved above the screen)
int32_t scroll_up;
// Start X
@ -56,6 +57,8 @@ struct MenuScene {
int32_t hscroll_cnt;
// Number of lines visible at a time
uint8_t nlines;
// number of visible characters in a line at a time
uint8_t ncols;
// selection handler
MenuScene_onSelect_t onSelect;
// Extra field for the subclass's private use.

Loading…
Cancel
Save