[menu] Abstract out the generic concept of a jump scroller

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2015-03-03 02:47:37 +00:00
parent 70124dd3be
commit 58752cc10d
3 changed files with 221 additions and 65 deletions

View File

@@ -0,0 +1,50 @@
#ifndef _IPXE_JUMPSCROLL_H
#define _IPXE_JUMPSCROLL_H
/** @file
*
* Jump scrolling
*
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** A jump scroller */
struct jump_scroller {
/** Maximum number of visible rows */
unsigned int rows;
/** Total number of items */
unsigned int count;
/** Currently selected item */
unsigned int current;
/** First visible item */
unsigned int first;
};
/**
* Check if jump scroller is currently on first page
*
* @v scroll Jump scroller
* @ret is_first Scroller is currently on first page
*/
static inline int jump_scroll_is_first ( struct jump_scroller *scroll ) {
return ( scroll->first == 0 );
}
/**
* Check if jump scroller is currently on last page
*
* @v scroll Jump scroller
* @ret is_last Scroller is currently on last page
*/
static inline int jump_scroll_is_last ( struct jump_scroller *scroll ) {
return ( ( scroll->first + scroll->rows ) >= scroll->count );
}
extern int jump_scroll_key ( struct jump_scroller *scroll, int key );
extern int jump_scroll_move ( struct jump_scroller *scroll, int move );
extern int jump_scroll ( struct jump_scroller *scroll );
#endif /* _IPXE_JUMPSCROLL_H */