#include <string.h>
#include <assert.h>
#include <gpxe/editbox.h>
Go to the source code of this file.
Defines | |
| #define | EDITBOX_MIN_CHARS 3 |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| void | init_editbox (struct edit_box *box, char *buf, size_t len, WINDOW *win, unsigned int row, unsigned int col, unsigned int width, unsigned int flags) |
| Initialise text box widget. | |
| void | draw_editbox (struct edit_box *box) |
| Draw text box widget. | |
Definition in file editbox.c.
| #define EDITBOX_MIN_CHARS 3 |
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| void init_editbox | ( | struct edit_box * | box, | |
| char * | buf, | |||
| size_t | len, | |||
| WINDOW * | win, | |||
| unsigned int | row, | |||
| unsigned int | col, | |||
| unsigned int | width, | |||
| unsigned int | flags | |||
| ) |
Initialise text box widget.
| box | Editable text box widget | |
| buf | Text buffer | |
| len | Size of text buffer | |
| win | Containing window | |
| row | Row | |
| col | Starting column | |
| width | Width | |
| flags | Flags |
Definition at line 45 of file editbox.c.
References edit_string::buf, edit_box::col, edit_string::cursor, edit_box::flags, edit_string::len, memset(), edit_box::row, stdscr, edit_box::string, strlen(), edit_box::width, and edit_box::win.
Referenced by load_setting(), and login_ui().
00047 { 00048 memset ( box, 0, sizeof ( *box ) ); 00049 box->string.buf = buf; 00050 box->string.len = len; 00051 box->string.cursor = strlen ( buf ); 00052 box->win = ( win ? win : stdscr ); 00053 box->row = row; 00054 box->col = col; 00055 box->width = width; 00056 box->flags = flags; 00057 }
| void draw_editbox | ( | struct edit_box * | box | ) |
Draw text box widget.
| box | Editable text box widget |
Definition at line 65 of file editbox.c.
References edit_string::buf, edit_box::col, edit_string::cursor, EDITBOX_MIN_CHARS, EDITBOX_STARS, edit_box::first, edit_box::flags, memcpy, memset(), mvwprintw, edit_box::row, stdscr, edit_box::string, strlen(), edit_box::width, edit_box::win, and wmove().
Referenced by draw_setting(), and login_ui().
00065 { 00066 size_t width = box->width; 00067 char buf[ width + 1 ]; 00068 signed int cursor_offset, underflow, overflow, first; 00069 size_t len; 00070 00071 /* Adjust starting offset so that cursor remains within box */ 00072 cursor_offset = ( box->string.cursor - box->first ); 00073 underflow = ( EDITBOX_MIN_CHARS - cursor_offset ); 00074 overflow = ( cursor_offset - ( width - 1 ) ); 00075 first = box->first; 00076 if ( underflow > 0 ) { 00077 first -= underflow; 00078 if ( first < 0 ) 00079 first = 0; 00080 } else if ( overflow > 0 ) { 00081 first += overflow; 00082 } 00083 box->first = first; 00084 cursor_offset = ( box->string.cursor - first ); 00085 00086 /* Construct underscore-padded string portion */ 00087 memset ( buf, '_', width ); 00088 buf[width] = '\0'; 00089 len = ( strlen ( box->string.buf ) - first ); 00090 if ( len > width ) 00091 len = width; 00092 if ( box->flags & EDITBOX_STARS ) { 00093 memset ( buf, '*', len ); 00094 } else { 00095 memcpy ( buf, ( box->string.buf + first ), len ); 00096 } 00097 00098 /* Print box content and move cursor */ 00099 if ( ! box->win ) 00100 box->win = stdscr; 00101 mvwprintw ( box->win, box->row, box->col, "%s", buf ); 00102 wmove ( box->win, box->row, ( box->col + cursor_offset ) ); 00103 }
1.5.7.1