iPXE
Functions
jumpscroll.c File Reference
#include <assert.h>
#include <ipxe/keys.h>
#include <ipxe/jumpscroll.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int jump_scroll_key (struct jump_scroller *scroll, int key)
 Jump scrolling. More...
 
int jump_scroll_move (struct jump_scroller *scroll, int move)
 Move scroller. More...
 
int jump_scroll (struct jump_scroller *scroll)
 Jump scroll to new page (if applicable) More...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ jump_scroll_key()

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.

42  {
43 
44  /* Sanity checks */
45  assert ( scroll->rows != 0 );
46  assert ( scroll->count != 0 );
47  assert ( scroll->current < scroll->count );
48  assert ( scroll->first < scroll->count );
49  assert ( scroll->first <= scroll->current );
50  assert ( scroll->current < ( scroll->first + scroll->rows ) );
51 
52  /* Handle key, if applicable */
53  switch ( key ) {
54  case KEY_UP:
55  return -1;
56  case KEY_DOWN:
57  return +1;
58  case KEY_PPAGE:
59  return ( scroll->first - scroll->current - 1 );
60  case KEY_NPAGE:
61  return ( scroll->first - scroll->current + scroll->rows );
62  case KEY_HOME:
63  return -( scroll->count );
64  case KEY_END:
65  return +( scroll->count );
66  default:
67  return 0;
68  }
69 }
#define KEY_NPAGE
Page down.
Definition: keys.h:113
#define KEY_HOME
Home.
Definition: keys.h:109
#define KEY_DOWN
Down arrow.
Definition: keys.h:105
#define KEY_UP
Up arrow.
Definition: keys.h:104
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int first
First visible item.
Definition: jumpscroll.h:21
unsigned int count
Total number of items.
Definition: jumpscroll.h:17
#define KEY_PPAGE
Page up.
Definition: keys.h:112
#define KEY_END
End.
Definition: keys.h:108
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:15
unsigned int current
Currently selected item.
Definition: jumpscroll.h:19
union @382 key
Sense key.
Definition: crypto.h:284

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

Referenced by main_loop(), and menu_loop().

◆ jump_scroll_move()

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.

78  {
79  int current = scroll->current;
80  int last = ( scroll->count - 1 );
81 
82  /* Sanity checks */
83  assert ( move != 0 );
84  assert ( scroll->count != 0 );
85 
86  /* Move to the new current item */
87  current += move;
88 
89  /* Check for start/end of list */
90  if ( current < 0 ) {
91  /* We have attempted to move before the start of the
92  * list. Move to the start of the list and continue
93  * moving forwards (if applicable).
94  */
95  scroll->current = 0;
96  return +1;
97  } else if ( current > last ) {
98  /* We have attempted to move after the end of the
99  * list. Move to the end of the list and continue
100  * moving backwards (if applicable).
101  */
102  scroll->current = last;
103  return -1;
104  } else {
105  /* Update the current item and continue moving in the
106  * same direction (if applicable).
107  */
108  scroll->current = current;
109  return ( ( move > 0 ) ? +1 : -1 );
110  }
111 }
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int count
Total number of items.
Definition: jumpscroll.h:17
uint32_t last
Length to read in last segment, or zero.
Definition: pccrc.h:30
static int move(int y, int x)
Definition: curses.h:593
unsigned int current
Currently selected item.
Definition: jumpscroll.h:19

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

Referenced by main_loop(), and menu_loop().

◆ jump_scroll()

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.

119  {
120  unsigned int index;
121 
122  /* Sanity checks */
123  assert ( scroll->rows != 0 );
124  assert ( scroll->count != 0 );
125  assert ( scroll->current < scroll->count );
126  assert ( scroll->first < scroll->count );
127 
128  /* Do nothing if we are already on the correct page */
129  index = ( scroll->current - scroll->first );
130  if ( index < scroll->rows )
131  return 0;
132 
133  /* Move to required page */
134  while ( scroll->first < scroll->current )
135  scroll->first += scroll->rows;
136  while ( scroll->first > scroll->current )
137  scroll->first -= scroll->rows;
138 
139  return 1;
140 }
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int first
First visible item.
Definition: jumpscroll.h:21
unsigned int count
Total number of items.
Definition: jumpscroll.h:17
unsigned int rows
Maximum number of visible rows.
Definition: jumpscroll.h:15
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
unsigned int current
Currently selected item.
Definition: jumpscroll.h:19

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