iPXE
Data Structures | Functions
jumpscroll.h File Reference

Jump scrolling. More...

Go to the source code of this file.

Data Structures

struct  jump_scroller
 A jump scroller. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int jump_scroll_is_first (struct jump_scroller *scroll)
 Check if jump scroller is currently on first page.
static int jump_scroll_is_last (struct jump_scroller *scroll)
 Check if jump scroller is currently on last page.
int jump_scroll_key (struct jump_scroller *scroll, int key)
 Jump scrolling.
int jump_scroll_move (struct jump_scroller *scroll, int move)
 Move scroller.
int jump_scroll (struct jump_scroller *scroll)
 Jump scroll to new page (if applicable)

Detailed Description

Jump scrolling.

Definition in file jumpscroll.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int jump_scroll_is_first ( struct jump_scroller scroll) [inline, static]

Check if jump scroller is currently on first page.

Parameters:
scrollJump scroller
Return values:
is_firstScroller is currently on first page

Definition at line 30 of file jumpscroll.h.

References jump_scroller::first.

Referenced by draw_menu_items(), and draw_setting_rows().

                                                                        {

        return ( scroll->first == 0 );
}
static int jump_scroll_is_last ( struct jump_scroller scroll) [inline, static]

Check if jump scroller is currently on last page.

Parameters:
scrollJump scroller
Return values:
is_lastScroller is currently on last page

Definition at line 41 of file jumpscroll.h.

References jump_scroller::count, jump_scroller::first, and jump_scroller::rows.

Referenced by draw_menu_items(), and draw_setting_rows().

                                                                       {

        return ( ( scroll->first + scroll->rows ) >= scroll->count );
}
int jump_scroll_key ( struct jump_scroller scroll,
int  key 
)

Jump scrolling.

Handle keypress

Parameters:
scrollJump scroller
keyKey pressed by user
Return values:
moveScroller movement, or zero

Definition at line 42 of file jumpscroll.c.

References assert, jump_scroller::count, jump_scroller::current, jump_scroller::first, KEY_DOWN, KEY_END, KEY_HOME, KEY_NPAGE, KEY_PPAGE, KEY_UP, and jump_scroller::rows.

Referenced by main_loop(), and menu_loop().

                                                              {

        /* Sanity checks */
        assert ( scroll->rows != 0 );
        assert ( scroll->count != 0 );
        assert ( scroll->current < scroll->count );
        assert ( scroll->first < scroll->count );
        assert ( scroll->first <= scroll->current );
        assert ( scroll->current < ( scroll->first + scroll->rows ) );

        /* Handle key, if applicable */
        switch ( key ) {
        case KEY_UP:
                return -1;
        case KEY_DOWN:
                return +1;
        case KEY_PPAGE:
                return ( scroll->first - scroll->current - 1 );
        case KEY_NPAGE:
                return ( scroll->first - scroll->current + scroll->rows );
        case KEY_HOME:
                return -( scroll->count );
        case KEY_END:
                return +( scroll->count );
        default:
                return 0;
        }
}
int jump_scroll_move ( struct jump_scroller scroll,
int  move 
)

Move scroller.

Parameters:
scrollJump scroller
moveScroller movement
Return values:
moveContinuing scroller movement (if applicable)

Definition at line 78 of file jumpscroll.c.

References assert, jump_scroller::count, jump_scroller::current, last, and move().

Referenced by main_loop(), and menu_loop().

                                                                {
        int current = scroll->current;
        int last = ( scroll->count - 1 );

        /* Sanity checks */
        assert ( move != 0 );
        assert ( scroll->count != 0 );

        /* Move to the new current item */
        current += move;

        /* Check for start/end of list */
        if ( current < 0 ) {
                /* We have attempted to move before the start of the
                 * list.  Move to the start of the list and continue
                 * moving forwards (if applicable).
                 */
                scroll->current = 0;
                return +1;
        } else if ( current > last ) {
                /* We have attempted to move after the end of the
                 * list.  Move to the end of the list and continue
                 * moving backwards (if applicable).
                 */
                scroll->current = last;
                return -1;
        } else {
                /* Update the current item and continue moving in the
                 * same direction (if applicable).
                 */
                scroll->current = current;
                return ( ( move > 0 ) ? +1 : -1 );
        }
}
int jump_scroll ( struct jump_scroller scroll)

Jump scroll to new page (if applicable)

Parameters:
scrollJump scroller
Return values:
jumpedJumped to a new page

Definition at line 119 of file jumpscroll.c.

References assert, jump_scroller::count, jump_scroller::current, jump_scroller::first, index, and jump_scroller::rows.

Referenced by main_loop(), menu_loop(), and show_menu().

                                                 {
        unsigned int index;

        /* Sanity checks */
        assert ( scroll->rows != 0 );
        assert ( scroll->count != 0 );
        assert ( scroll->current < scroll->count );
        assert ( scroll->first < scroll->count );

        /* Do nothing if we are already on the correct page */
        index = ( scroll->current - scroll->first );
        if ( index < scroll->rows )
                return 0;

        /* Move to required page */
        while ( scroll->first < scroll->current )
                scroll->first += scroll->rows;
        while ( scroll->first > scroll->current )
                scroll->first -= scroll->rows;

        return 1;
}