iPXE
jumpscroll.h File Reference

Jump scrolling. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  jump_scroller
 A jump scroller. More...

Macros

#define SCROLL(delta)
 Construct scroll movement.
#define SCROLL_DELTA(scroll)
 Extract change in scroller position.
#define SCROLL_FLAGS   0xffff0000UL
 Scroll movement flags.
#define SCROLL_WRAP   0x80000000UL
 Wrap around scrolling.
#define SCROLL_NONE   SCROLL ( 0 )
 Do not scroll.
#define SCROLL_UP   SCROLL ( -1 )
 Scroll up by one line.
#define SCROLL_DOWN   SCROLL ( +1 )
 Scroll down by one line.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
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.
unsigned int jump_scroll_key (struct jump_scroller *scroll, int key)
 Jump scrolling.
unsigned int jump_scroll_move (struct jump_scroller *scroll, unsigned 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.

Macro Definition Documentation

◆ SCROLL

#define SCROLL ( delta)
Value:
( ( unsigned int ) ( uint16_t ) ( int16_t ) (delta) )
signed short int16_t
Definition stdint.h:16
unsigned short uint16_t
Definition stdint.h:11

Construct scroll movement.

Parameters
deltaChange in scroller position
Return values
moveScroll movement

Definition at line 33 of file jumpscroll.h.

Referenced by jump_scroll_key(), and jump_scroll_move().

◆ SCROLL_DELTA

#define SCROLL_DELTA ( scroll)
Value:
( ( int16_t ) ( (scroll) & 0x0000ffffUL ) )

Extract change in scroller position.

Parameters
moveScroll movement
Return values
deltaChange in scroller position

Definition at line 41 of file jumpscroll.h.

Referenced by jump_scroll_move().

◆ SCROLL_FLAGS

#define SCROLL_FLAGS   0xffff0000UL

Scroll movement flags.

Definition at line 44 of file jumpscroll.h.

Referenced by jump_scroll_move().

◆ SCROLL_WRAP

#define SCROLL_WRAP   0x80000000UL

Wrap around scrolling.

Definition at line 45 of file jumpscroll.h.

Referenced by jump_scroll_key(), and jump_scroll_move().

◆ SCROLL_NONE

#define SCROLL_NONE   SCROLL ( 0 )

Do not scroll.

Definition at line 48 of file jumpscroll.h.

Referenced by menu_loop().

◆ SCROLL_UP

#define SCROLL_UP   SCROLL ( -1 )

Scroll up by one line.

Definition at line 51 of file jumpscroll.h.

◆ SCROLL_DOWN

#define SCROLL_DOWN   SCROLL ( +1 )

Scroll down by one line.

Definition at line 54 of file jumpscroll.h.

Referenced by form_loop(), and menu_loop().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ jump_scroll_is_first()

int jump_scroll_is_first ( struct jump_scroller * scroll)
inlinestatic

Check if jump scroller is currently on first page.

Parameters
scrollJump scroller
Return values
is_firstScroller is currently on first page

Definition at line 62 of file jumpscroll.h.

62 {
63
64 return ( scroll->first == 0 );
65}
unsigned int first
First visible item.
Definition jumpscroll.h:24

References jump_scroller::first.

Referenced by draw_menu_items(), and draw_setting_rows().

◆ jump_scroll_is_last()

int jump_scroll_is_last ( struct jump_scroller * scroll)
inlinestatic

Check if jump scroller is currently on last page.

Parameters
scrollJump scroller
Return values
is_lastScroller is currently on last page

Definition at line 73 of file jumpscroll.h.

73 {
74
75 return ( ( scroll->first + scroll->rows ) >= scroll->count );
76}
unsigned int count
Total number of items.
Definition jumpscroll.h:20
unsigned int rows
Maximum number of visible rows.
Definition jumpscroll.h:18

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

Referenced by draw_menu_items(), and draw_setting_rows().

◆ jump_scroll_key()

unsigned int jump_scroll_key ( struct jump_scroller * scroll,
int key )
extern

Jump scrolling.

Handle keypress

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

Definition at line 43 of file jumpscroll.c.

43 {
44 unsigned int flags = 0;
45 int16_t delta;
46
47 /* Sanity checks */
48 assert ( scroll->rows != 0 );
49 assert ( scroll->count != 0 );
50 assert ( scroll->current < scroll->count );
51 assert ( scroll->first < scroll->count );
52 assert ( scroll->first <= scroll->current );
53 assert ( scroll->current < ( scroll->first + scroll->rows ) );
54
55 /* Handle key, if applicable */
56 switch ( key ) {
57 case KEY_UP:
58 delta = -1;
59 break;
60 case TAB:
62 /* fall through */
63 case KEY_DOWN:
64 delta = +1;
65 break;
66 case KEY_PPAGE:
67 delta = ( scroll->first - scroll->current - 1 );
68 break;
69 case KEY_NPAGE:
70 delta = ( scroll->first - scroll->current + scroll->rows );
71 break;
72 case KEY_HOME:
73 delta = -( scroll->count );
74 break;
75 case KEY_END:
76 delta = +( scroll->count );
77 break;
78 default:
79 delta = 0;
80 break;
81 }
82
83 return ( SCROLL ( delta ) | flags );
84}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint8_t flags
Flags.
Definition ena.h:7
#define SCROLL_WRAP
Wrap around scrolling.
Definition jumpscroll.h:45
#define SCROLL(delta)
Construct scroll movement.
Definition jumpscroll.h:33
#define KEY_DOWN
Down arrow.
Definition keys.h:107
#define KEY_PPAGE
Page up.
Definition keys.h:114
#define KEY_NPAGE
Page down.
Definition keys.h:115
#define KEY_END
End.
Definition keys.h:110
#define TAB
Definition keys.h:47
#define KEY_HOME
Home.
Definition keys.h:111
#define KEY_UP
Up arrow.
Definition keys.h:106
unsigned int current
Currently selected item.
Definition jumpscroll.h:22

References assert, jump_scroller::count, jump_scroller::current, jump_scroller::first, flags, key, KEY_DOWN, KEY_END, KEY_HOME, KEY_NPAGE, KEY_PPAGE, KEY_UP, jump_scroller::rows, SCROLL, SCROLL_WRAP, and TAB.

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

◆ jump_scroll_move()

unsigned int jump_scroll_move ( struct jump_scroller * scroll,
unsigned int move )
extern

Move scroller.

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

Definition at line 93 of file jumpscroll.c.

94 {
95 int16_t delta = SCROLL_DELTA ( move );
96 int current = scroll->current;
97 int last = ( scroll->count - 1 );
98
99 /* Sanity checks */
100 assert ( move != 0 );
101 assert ( scroll->count != 0 );
102
103 /* Move to the new current item */
104 current += delta;
105
106 /* Default to continuing movement in the same direction */
107 delta = ( ( delta >= 0 ) ? +1 : -1 );
108
109 /* Check for start/end of list */
110 if ( ( current >= 0 ) && ( current <= last ) ) {
111 /* We are still within the list. Update the current
112 * item and continue moving in the same direction (if
113 * applicable).
114 */
115 scroll->current = current;
116 } else {
117 /* We have attempted to move outside the list. If we
118 * are wrapping around, then continue in the same
119 * direction (if applicable), otherwise reverse.
120 */
121 if ( ! ( move & SCROLL_WRAP ) )
122 delta = -delta;
123
124 /* Move to start or end of list as appropriate */
125 if ( delta >= 0 ) {
126 scroll->current = 0;
127 } else {
128 scroll->current = last;
129 }
130 }
131
132 return ( SCROLL ( delta ) | ( move & SCROLL_FLAGS ) );
133}
static int move(int y, int x)
Definition curses.h:594
#define SCROLL_DELTA(scroll)
Extract change in scroller position.
Definition jumpscroll.h:41
#define SCROLL_FLAGS
Scroll movement flags.
Definition jumpscroll.h:44

References assert, jump_scroller::count, jump_scroller::current, move(), SCROLL, SCROLL_DELTA, SCROLL_FLAGS, and SCROLL_WRAP.

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

◆ jump_scroll()

int jump_scroll ( struct jump_scroller * scroll)
extern

Jump scroll to new page (if applicable)

Parameters
scrollJump scroller
Return values
jumpedJumped to a new page

Definition at line 141 of file jumpscroll.c.

141 {
142 unsigned int index;
143
144 /* Sanity checks */
145 assert ( scroll->rows != 0 );
146 assert ( scroll->count != 0 );
147 assert ( scroll->current < scroll->count );
148 assert ( scroll->first < scroll->count );
149
150 /* Do nothing if we are already on the correct page */
151 index = ( scroll->current - scroll->first );
152 if ( index < scroll->rows )
153 return 0;
154
155 /* Move to required page */
156 while ( scroll->first < scroll->current )
157 scroll->first += scroll->rows;
158 while ( scroll->first > scroll->current )
159 scroll->first -= scroll->rows;
160
161 return 1;
162}
long index
Definition bigint.h:65

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().