-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeMenu.h
More file actions
72 lines (63 loc) · 3.24 KB
/
Copy pathTreeMenu.h
File metadata and controls
72 lines (63 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// TreeMenu — a small hierarchical menu renderer on top of LVGL.
//
// Data model: a static const tree of TreeMenuNode. A node is either a leaf
// (on_activate set, children NULL) or a branch (children set, on_activate
// ignored). Every non-root level automatically gets a "back" row injected
// at position 0 — you never declare it yourself.
//
// Input-agnostic: this library never reads any button/input device. The
// host app wires its own input (physical buttons, touch, ...) to
// treemenu_next()/treemenu_prev()/treemenu_activate().
#ifndef TREEMENU_H
#define TREEMENU_H
#include <lvgl.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct TreeMenuNode {
const char *label;
void (*on_activate)(const struct TreeMenuNode *self, void *userdata); // NULL for a branch node
const struct TreeMenuNode *children; // NULL for a leaf node
uint16_t children_count;
} TreeMenuNode;
typedef struct {
lv_obj_t *parent; // where to create the menu container
int16_t x, y; // position within parent (default 0,0)
int16_t width, height; // size of the menu area (0 = fill parent)
int16_t row_height; // height of one row, e.g. 18
uint32_t color_active; // fill of the selected row
uint32_t color_text; // label color of every other (unselected) row
uint32_t bg_color; // background of `parent` itself (visible
// behind/below the menu when it doesn't
// fill the whole area)
int16_t text_margin_left; // left margin of each row's label, in px
const char *back_label; // NULL = "< Back"
const lv_font_t *font_row; // row label font, NULL = LV_FONT_DEFAULT
uint32_t color_separator; // bottom border of every unselected row
int16_t select_radius; // corner radius of the selected row's fill
uint32_t color_text_active; // label color of the selected row
uint32_t color_chevron; // submenu-arrow color (fixed, not selection-dependent)
const char *root_label; // breadcrumb label for the top level, e.g. "Home". NULL = no breadcrumb.
int16_t breadcrumb_height; // height reserved for the breadcrumb strip above the rows. 0 = disabled.
int16_t breadcrumb_gap; // extra gap between the breadcrumb and the first row
uint32_t color_breadcrumb; // breadcrumb text color
const lv_font_t *font_breadcrumb; // NULL = LV_FONT_DEFAULT
void *userdata; // passed as-is to on_activate callbacks
} TreeMenuConfig;
// Builds the root level and displays it. Call once, after the LVGL display
// driver is registered.
void treemenu_init(TreeMenuConfig *cfg, const TreeMenuNode *root_children, uint16_t root_count);
// Moves the selection to the next / previous row, wrapping around. Redraws
// only the highlight (cheap — no widget rebuild).
void treemenu_next(void);
void treemenu_prev(void);
// Activates the selected row:
// - "back" row -> pops one level, restores the parent's selection
// - branch node -> pushes the current level, descends into it
// - leaf node -> calls its on_activate(self, userdata)
void treemenu_activate(void);
#ifdef __cplusplus
}
#endif
#endif // TREEMENU_H