diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-06-20 14:16:18 -0700 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-06-20 14:51:28 -0700 |
commit | c8e50bb0fd3d9d1629e5c78f92bbf7bc9af84f2c (patch) | |
tree | 52b1a12a1a3b7af0210f7b84d09bbda4e5114608 /src/core | |
parent | 5719cde838b6e86a02831373dae81642653b872f (diff) | |
download | ipxe-c8e50bb0fd3d9d1629e5c78f92bbf7bc9af84f2c.tar.gz |
[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>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/dynui.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/dynui.c b/src/core/dynui.c index 6e053b905..33218f598 100644 --- a/src/core/dynui.c +++ b/src/core/dynui.c @@ -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; +} |