summaryrefslogtreecommitdiffstats
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
parent8b4949381c9edea54547624827acf0d562ef5b76 (diff)
downloadrockbox-4b51ca5ce6.tar.gz
rockbox-4b51ca5ce6.zip
x1000: bootloader: add GUI list widget
Change-Id: Ic5bf4747ed99b713b7c035153865ed9bdebd89b0
-rw-r--r--bootloader/x1000/gui.c64
-rw-r--r--bootloader/x1000/x1000bootloader.h24
2 files changed, 88 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)
backlight_hw_off();
}
+
+void gui_list_init(struct bl_list* list, struct viewport* vp)
+{
+ list->vp = vp;
+ list->num_items = 0;
+ list->selected_item = 0;
+ list->top_item = 0;
+ list->item_height = SYSFONT_HEIGHT;
+ list->draw_item = NULL;
+}
+
+void gui_list_draw(struct bl_list* list)
+{
+ struct bl_listitem item = {
+ .list = list,
+ .x = 0, .y = 0,
+ .width = list->vp->width,
+ .height = list->item_height,
+ };
+
+ struct viewport* old_vp = lcd_set_viewport(list->vp);
+ lcd_clear_viewport();
+
+ int items_on_screen = list->vp->height / list->item_height;
+ for(int i = 0; i < items_on_screen; ++i) {
+ item.index = list->top_item + i;
+ if(item.index >= list->num_items)
+ break;
+
+ list->draw_item(&item);
+
+ item.y += item.height;
+ }
+
+ lcd_set_viewport(old_vp);
+}
+
+void gui_list_select(struct bl_list* list, int item_index)
+{
+ /* clamp the selection */
+ list->selected_item = item_index;
+
+ if(list->selected_item < 0)
+ list->selected_item = 0;
+ else if(list->selected_item >= list->num_items)
+ list->selected_item = list->num_items - 1;
+
+ /* handle scrolling the list view */
+ int items_on_screen = list->vp->height / list->item_height;
+ int bottom_item = list->top_item + items_on_screen;
+
+ if(list->selected_item < list->top_item) {
+ list->top_item = list->selected_item;
+ } else if(list->selected_item >= bottom_item) {
+ list->top_item = list->selected_item - items_on_screen + 1;
+ if(list->top_item < 0)
+ list->top_item = 0;
+ }
+}
+
+void gui_list_scroll(struct bl_list* list, int delta)
+{
+ gui_list_select(list, list->selected_item + delta);
+}
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h
index c5984c9a91..9090523c14 100644
--- a/bootloader/x1000/x1000bootloader.h
+++ b/bootloader/x1000/x1000bootloader.h
@@ -23,6 +23,7 @@
#define __X1000BOOTLOADER_H__
#include "config.h"
+#include "lcd.h"
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
@@ -70,6 +71,24 @@ struct uimage_header;
* GUI stuff
*/
+struct bl_listitem {
+ struct bl_list* list;
+
+ int index;
+ int x, y, width, height;
+};
+
+struct bl_list {
+ struct viewport* vp;
+
+ int num_items;
+ int selected_item;
+ int top_item;
+ int item_height;
+
+ void(*draw_item)(const struct bl_listitem* item);
+};
+
void clearscreen(void);
void putversion(void);
void putcenter_y(int y, const char* msg);
@@ -81,6 +100,11 @@ void init_lcd(void);
void gui_shutdown(void);
+void gui_list_init(struct bl_list* list, struct viewport* vp);
+void gui_list_draw(struct bl_list* list);
+void gui_list_select(struct bl_list* list, int item_index);
+void gui_list_scroll(struct bl_list* list, int delta);
+
/*
* Installer
*/