mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 20:10:18 +03:00
[dynui] Generalise mechanisms for looking up user interface items
Generalise the ability to look up a dynamic user interface item by index or by shortcut key, to allow for reuse of this code for interactive forms. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -131,6 +131,7 @@ struct dynamic_item * add_dynui_item ( struct dynamic_ui *dynui,
|
||||
}
|
||||
strcpy ( text_copy, text );
|
||||
item->text = text_copy;
|
||||
item->index = dynui->count++;
|
||||
item->shortcut = shortcut;
|
||||
item->is_default = is_default;
|
||||
|
||||
@@ -180,3 +181,40 @@ struct dynamic_ui * find_dynui ( const char *name ) {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find dynamic user interface item by index
|
||||
*
|
||||
* @v dynui Dynamic user interface
|
||||
* @v index Index
|
||||
* @ret item User interface item, or NULL if not found
|
||||
*/
|
||||
struct dynamic_item * dynui_item ( struct dynamic_ui *dynui,
|
||||
unsigned int index ) {
|
||||
struct dynamic_item *item;
|
||||
|
||||
list_for_each_entry ( item, &dynui->items, list ) {
|
||||
if ( index-- == 0 )
|
||||
return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find dynamic user interface item by shortcut key
|
||||
*
|
||||
* @v dynui Dynamic user interface
|
||||
* @v key Shortcut key
|
||||
* @ret item User interface item, or NULL if not found
|
||||
*/
|
||||
struct dynamic_item * dynui_shortcut ( struct dynamic_ui *dynui, int key ) {
|
||||
struct dynamic_item *item;
|
||||
|
||||
list_for_each_entry ( item, &dynui->items, list ) {
|
||||
if ( key && ( key == item->shortcut ) )
|
||||
return item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user