mirror of https://github.com/ipxe/ipxe.git
[hci] Draw all widgets on the standard screen
The curses concept of a window has been supported but never actively used in iPXE since the mucurses library was first implemented in 2006. Simplify the code by removing the ability to place a widget set in a specified window, and instead use the standard screen for all drawing operations. This simplification allows the widget set parameter to be omitted for the draw_widget() and edit_widget() operations, since the only reason for its inclusion was to provide access to the specified window. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1243/head
parent
e965f179e1
commit
bb4a10696f
|
@ -39,10 +39,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
/**
|
||||
* Draw text box widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
*/
|
||||
static void draw_editbox ( struct widgets *widgets, struct widget *widget ) {
|
||||
static void draw_editbox ( struct widget *widget ) {
|
||||
struct edit_box *box = container_of ( widget, struct edit_box, widget );
|
||||
const char *content = *(box->string.buf);
|
||||
size_t width = widget->width;
|
||||
|
@ -79,21 +78,19 @@ static void draw_editbox ( struct widgets *widgets, struct widget *widget ) {
|
|||
|
||||
/* Print box content and move cursor */
|
||||
color_set ( CPAIR_EDIT, NULL );
|
||||
mvwprintw ( widgets->win, widget->row, widget->col, "%s", buf );
|
||||
wmove ( widgets->win, widget->row, ( widget->col + cursor_offset ) );
|
||||
mvprintw ( widget->row, widget->col, "%s", buf );
|
||||
move ( widget->row, ( widget->col + cursor_offset ) );
|
||||
color_set ( CPAIR_NORMAL, NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit text box widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
* @v key Key pressed by user
|
||||
* @ret key Key returned to application, or zero
|
||||
*/
|
||||
static int edit_editbox ( struct widgets *widgets __unused,
|
||||
struct widget *widget, int key ) {
|
||||
static int edit_editbox ( struct widget *widget, int key ) {
|
||||
struct edit_box *box = container_of ( widget, struct edit_box, widget );
|
||||
|
||||
return edit_string ( &box->string, key );
|
||||
|
|
|
@ -36,10 +36,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
/**
|
||||
* Draw text label widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
*/
|
||||
static void draw_label ( struct widgets *widgets, struct widget *widget ) {
|
||||
static void draw_label ( struct widget *widget ) {
|
||||
struct label *label = container_of ( widget, struct label, widget );
|
||||
unsigned int width = widget->width;
|
||||
unsigned int col = widget->col;
|
||||
|
@ -51,20 +50,18 @@ static void draw_label ( struct widgets *widgets, struct widget *widget ) {
|
|||
|
||||
/* Print label content */
|
||||
attron ( A_BOLD );
|
||||
mvwprintw ( widgets->win, widget->row, col, "%s", text );
|
||||
mvprintw ( widget->row, col, "%s", text );
|
||||
attroff ( A_BOLD );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit text label widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
* @v key Key pressed by user
|
||||
* @ret key Key returned to application, or zero
|
||||
*/
|
||||
static int edit_label ( struct widgets *widgets __unused,
|
||||
struct widget *widget __unused, int key ) {
|
||||
static int edit_label ( struct widget *widget __unused, int key ) {
|
||||
|
||||
/* Cannot be edited */
|
||||
return key;
|
||||
|
|
|
@ -67,7 +67,7 @@ int login_ui ( void ) {
|
|||
|
||||
/* Construct user interface */
|
||||
memset ( &widgets, 0, sizeof ( widgets ) );
|
||||
init_widgets ( &widgets.widgets, NULL );
|
||||
init_widgets ( &widgets.widgets );
|
||||
init_label ( &widgets.username_label, USERNAME_LABEL_ROW, WIDGET_COL,
|
||||
WIDGET_WIDTH, "Username" );
|
||||
init_label ( &widgets.password_label, PASSWORD_LABEL_ROW, WIDGET_COL,
|
||||
|
|
|
@ -253,7 +253,7 @@ static void draw_setting_row ( struct settings_ui *ui ) {
|
|||
static int edit_setting ( struct settings_ui *ui, int key ) {
|
||||
assert ( ui->row.setting.name != NULL );
|
||||
ui->row.editing = 1;
|
||||
return edit_widget ( &ui->widgets, &ui->row.editbox.widget, key );
|
||||
return edit_widget ( &ui->row.editbox.widget, key );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -457,7 +457,7 @@ static int main_loop ( struct settings *settings ) {
|
|||
/* Print initial screen content */
|
||||
color_set ( CPAIR_NORMAL, NULL );
|
||||
memset ( &ui, 0, sizeof ( ui ) );
|
||||
init_widgets ( &ui.widgets, NULL );
|
||||
init_widgets ( &ui.widgets );
|
||||
select_settings ( &ui, settings );
|
||||
|
||||
while ( 1 ) {
|
||||
|
@ -481,7 +481,7 @@ static int main_loop ( struct settings *settings ) {
|
|||
assert ( ui.row.setting.name != NULL );
|
||||
|
||||
/* Redraw edit box */
|
||||
draw_widget ( &ui.widgets, &ui.row.editbox.widget );
|
||||
draw_widget ( &ui.row.editbox.widget );
|
||||
|
||||
/* Process keypress */
|
||||
key = edit_setting ( &ui, getkey ( 0 ) );
|
||||
|
|
|
@ -68,7 +68,7 @@ static int widget_ui_loop ( struct widgets *widgets ) {
|
|||
|
||||
/* Draw all widgets */
|
||||
list_for_each_entry ( widget, &widgets->list, list )
|
||||
draw_widget ( widgets, widget );
|
||||
draw_widget ( widget );
|
||||
|
||||
/* Count editable widgets */
|
||||
count = 0;
|
||||
|
@ -85,10 +85,10 @@ static int widget_ui_loop ( struct widgets *widgets ) {
|
|||
return -ENOENT;
|
||||
|
||||
/* Redraw current widget */
|
||||
draw_widget ( widgets, widget );
|
||||
draw_widget ( widget );
|
||||
|
||||
/* Process keypress */
|
||||
key = edit_widget ( widgets, widget, getkey ( 0 ) );
|
||||
key = edit_widget ( widget, getkey ( 0 ) );
|
||||
switch ( key ) {
|
||||
case KEY_UP:
|
||||
if ( current > 0 )
|
||||
|
|
|
@ -16,8 +16,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
struct widgets {
|
||||
/** List of widgets (in tab order) */
|
||||
struct list_head list;
|
||||
/** Containing window */
|
||||
WINDOW *win;
|
||||
};
|
||||
|
||||
/** A text widget */
|
||||
|
@ -50,14 +48,12 @@ struct widget_operations {
|
|||
/**
|
||||
* Draw widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
*/
|
||||
void ( * draw ) ( struct widgets *widgets, struct widget *widget );
|
||||
void ( * draw ) ( struct widget *widget );
|
||||
/**
|
||||
* Edit widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
* @v key Key pressed by user
|
||||
* @ret key Key returned to application, or zero
|
||||
|
@ -66,21 +62,18 @@ struct widget_operations {
|
|||
* method to ensure that any changes to an editable widget are
|
||||
* displayed to the user.
|
||||
*/
|
||||
int ( * edit ) ( struct widgets *widgets, struct widget *widget,
|
||||
int key );
|
||||
int ( * edit ) ( struct widget *widget, int key );
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise text widget set
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v win Containing window
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
init_widgets ( struct widgets *widgets, WINDOW *win ) {
|
||||
init_widgets ( struct widgets *widgets ) {
|
||||
|
||||
INIT_LIST_HEAD ( &widgets->list );
|
||||
widgets->win = ( win ? win : stdscr );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,19 +112,17 @@ add_widget ( struct widgets *widgets, struct widget *widget ) {
|
|||
/**
|
||||
* Draw text widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
draw_widget ( struct widgets *widgets, struct widget *widget ) {
|
||||
draw_widget ( struct widget *widget ) {
|
||||
|
||||
widget->op->draw ( widgets, widget );
|
||||
widget->op->draw ( widget );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit text widget
|
||||
*
|
||||
* @v widgets Text widget set
|
||||
* @v widget Text widget
|
||||
* @v key Key pressed by user
|
||||
* @ret key Key returned to application, or zero
|
||||
|
@ -141,9 +132,9 @@ draw_widget ( struct widgets *widgets, struct widget *widget ) {
|
|||
* user.
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
edit_widget ( struct widgets *widgets, struct widget *widget, int key ) {
|
||||
edit_widget ( struct widget *widget, int key ) {
|
||||
|
||||
return widget->op->edit ( widgets, widget, key );
|
||||
return widget->op->edit ( widget, key );
|
||||
}
|
||||
|
||||
extern int widget_ui ( struct widgets *widgets );
|
||||
|
|
Loading…
Reference in New Issue