x1000: bootloader: add GUI list widget
Change-Id: Ic5bf4747ed99b713b7c035153865ed9bdebd89b0
This commit is contained in:
parent
8b4949381c
commit
4b51ca5ce6
2 changed files with 88 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue