summaryrefslogtreecommitdiff
path: root/bootloader/x1000/gui.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-10 14:16:39 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-03-12 14:50:45 -0500
commit4b51ca5ce60a874276579d9b4657de1edc36f31d (patch)
tree8515eff650e8d0ef867c9d46c4ba024c5b97f23d /bootloader/x1000/gui.c
parent8b4949381c9edea54547624827acf0d562ef5b76 (diff)
downloadrockbox-4b51ca5ce60a874276579d9b4657de1edc36f31d.tar.gz
rockbox-4b51ca5ce60a874276579d9b4657de1edc36f31d.zip
x1000: bootloader: add GUI list widget
Change-Id: Ic5bf4747ed99b713b7c035153865ed9bdebd89b0
Diffstat (limited to 'bootloader/x1000/gui.c')
-rw-r--r--bootloader/x1000/gui.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/bootloader/x1000/gui.c b/bootloader/x1000/gui.c
index da20a9b128..a672c30380 100644
--- a/bootloader/x1000/gui.c
+++ b/bootloader/x1000/gui.c
@@ -111,3 +111,67 @@ void gui_shutdown(void)
111 111
112 backlight_hw_off(); 112 backlight_hw_off();
113} 113}
114
115void gui_list_init(struct bl_list* list, struct viewport* vp)
116{
117 list->vp = vp;
118 list->num_items = 0;
119 list->selected_item = 0;
120 list->top_item = 0;
121 list->item_height = SYSFONT_HEIGHT;
122 list->draw_item = NULL;
123}
124
125void gui_list_draw(struct bl_list* list)
126{
127 struct bl_listitem item = {
128 .list = list,
129 .x = 0, .y = 0,
130 .width = list->vp->width,
131 .height = list->item_height,
132 };
133
134 struct viewport* old_vp = lcd_set_viewport(list->vp);
135 lcd_clear_viewport();
136
137 int items_on_screen = list->vp->height / list->item_height;
138 for(int i = 0; i < items_on_screen; ++i) {
139 item.index = list->top_item + i;
140 if(item.index >= list->num_items)
141 break;
142
143 list->draw_item(&item);
144
145 item.y += item.height;
146 }
147
148 lcd_set_viewport(old_vp);
149}
150
151void gui_list_select(struct bl_list* list, int item_index)
152{
153 /* clamp the selection */
154 list->selected_item = item_index;
155
156 if(list->selected_item < 0)
157 list->selected_item = 0;
158 else if(list->selected_item >= list->num_items)
159 list->selected_item = list->num_items - 1;
160
161 /* handle scrolling the list view */
162 int items_on_screen = list->vp->height / list->item_height;
163 int bottom_item = list->top_item + items_on_screen;
164
165 if(list->selected_item < list->top_item) {
166 list->top_item = list->selected_item;
167 } else if(list->selected_item >= bottom_item) {
168 list->top_item = list->selected_item - items_on_screen + 1;
169 if(list->top_item < 0)
170 list->top_item = 0;
171 }
172}
173
174void gui_list_scroll(struct bl_list* list, int delta)
175{
176 gui_list_select(list, list->selected_item + delta);
177}