diff options
Diffstat (limited to 'bootloader/x1000/gui.c')
-rw-r--r-- | bootloader/x1000/gui.c | 64 |
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 | |||
115 | void 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 | |||
125 | void 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 | |||
151 | void 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 | |||
174 | void gui_list_scroll(struct bl_list* list, int delta) | ||
175 | { | ||
176 | gui_list_select(list, list->selected_item + delta); | ||
177 | } | ||