blob: 63452bbdd6a5662607af8c78f107b3fba79afb28 [file] [log] [blame]
Simon Glassd8adbe92023-01-06 08:52:36 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2022 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
Simon Glass8df4a4e2023-08-14 16:40:25 -06007#ifndef __EXPO_H
8#define __EXPO_H
Simon Glassd8adbe92023-01-06 08:52:36 -06009
Simon Glassa968f5f2023-10-01 19:13:31 -060010#include <abuf.h>
Simon Glassc999e172023-06-01 10:22:53 -060011#include <dm/ofnode_decl.h>
Simon Glassd8adbe92023-01-06 08:52:36 -060012#include <linux/list.h>
13
14struct udevice;
15
Simon Glassa968f5f2023-10-01 19:13:31 -060016#include <cli.h>
17
Simon Glassd8adbe92023-01-06 08:52:36 -060018/**
Simon Glass53a0a2f2024-10-14 16:31:57 -060019 * enum expo_id_t - standard expo IDs
20 *
21 * These are assumed to be in use at all times. Expos should use IDs starting
22 * from EXPOID_BASE_ID,
23 *
24 * @EXPOID_NONE: Not used, invalid ID 0
25 * @EXPOID_SAVE: User has requested that the expo data be saved
26 * @EXPOID_DISCARD: User has requested that the expo data be discarded
27 * @EXPOID_BASE_ID: First ID which can be used for expo objects
28 */
29enum expo_id_t {
30 EXPOID_NONE,
31
32 EXPOID_SAVE,
33 EXPOID_DISCARD,
34
35 EXPOID_BASE_ID = 5,
36};
37
38/**
Simon Glassd8adbe92023-01-06 08:52:36 -060039 * enum expoact_type - types of actions reported by the expo
40 *
41 * @EXPOACT_NONE: no action
Simon Glassf0e1e8c2023-06-01 10:22:59 -060042 * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which)
Simon Glass719a3c62023-06-01 10:22:56 -060043 * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
Simon Glassd8adbe92023-01-06 08:52:36 -060044 * @EXPOACT_SELECT: menu item was selected (@id indicates which)
Simon Glassf0e1e8c2023-06-01 10:22:59 -060045 * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates
46 * which menu object)
47 * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object)
Simon Glassd8adbe92023-01-06 08:52:36 -060048 * @EXPOACT_QUIT: request to exit the menu
49 */
50enum expoact_type {
51 EXPOACT_NONE,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060052 EXPOACT_POINT_OBJ,
Simon Glass719a3c62023-06-01 10:22:56 -060053 EXPOACT_POINT_ITEM,
Simon Glassd8adbe92023-01-06 08:52:36 -060054 EXPOACT_SELECT,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060055 EXPOACT_OPEN,
56 EXPOACT_CLOSE,
Simon Glassd8adbe92023-01-06 08:52:36 -060057 EXPOACT_QUIT,
58};
59
60/**
61 * struct expo_action - an action report by the expo
62 *
63 * @type: Action type (EXPOACT_NONE if there is no action)
Simon Glass719a3c62023-06-01 10:22:56 -060064 * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT
Heinrich Schuchardta99e8fe2024-09-18 23:58:03 +020065 * @select.id: ID number of the object affected.
Simon Glassd8adbe92023-01-06 08:52:36 -060066 */
67struct expo_action {
68 enum expoact_type type;
69 union {
70 struct {
71 int id;
72 } select;
73 };
74};
75
76/**
Simon Glassc999e172023-06-01 10:22:53 -060077 * struct expo_theme - theme for the expo
78 *
79 * @font_size: Default font size for all text
80 * @menu_inset: Inset width (on each side and top/bottom) for menu items
81 * @menuitem_gap_y: Gap between menu items in pixels
Simon Glass377f18e2024-10-14 16:31:55 -060082 * @menu_title_margin_x: Gap between right side of menu title and left size of
83 * menu label
Simon Glassc999e172023-06-01 10:22:53 -060084 */
85struct expo_theme {
86 u32 font_size;
87 u32 menu_inset;
88 u32 menuitem_gap_y;
Simon Glass377f18e2024-10-14 16:31:55 -060089 u32 menu_title_margin_x;
Simon Glassc999e172023-06-01 10:22:53 -060090};
91
92/**
Simon Glassd8adbe92023-01-06 08:52:36 -060093 * struct expo - information about an expo
94 *
95 * A group of scenes which can be presented to the user, typically to obtain
96 * input or to make a selection.
97 *
98 * @name: Name of the expo (allocated)
99 * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
Simon Glass67e2af12023-06-01 10:22:34 -0600100 * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600101 * @scene_id: Current scene ID (0 if none)
102 * @next_id: Next ID number to use, for automatic allocation
103 * @action: Action selected by user. At present only one is supported, with the
104 * type set to EXPOACT_NONE if there is no action
105 * @text_mode: true to use text mode for the menu (no vidconsole)
Simon Glassd353b752023-06-01 10:22:55 -0600106 * @popup: true to use popup menus, instead of showing all items
Simon Glassd8adbe92023-01-06 08:52:36 -0600107 * @priv: Private data for the controller
Simon Glassc999e172023-06-01 10:22:53 -0600108 * @theme: Information about fonts styles, etc.
Simon Glassd8adbe92023-01-06 08:52:36 -0600109 * @scene_head: List of scenes
110 * @str_head: list of strings
Simon Glass683d8832025-05-02 08:46:15 -0600111 * @cch: Keyboard context for input
Simon Glassd8adbe92023-01-06 08:52:36 -0600112 */
113struct expo {
114 char *name;
115 struct udevice *display;
Simon Glass67e2af12023-06-01 10:22:34 -0600116 struct udevice *cons;
Simon Glassd8adbe92023-01-06 08:52:36 -0600117 uint scene_id;
118 uint next_id;
119 struct expo_action action;
120 bool text_mode;
Simon Glassd353b752023-06-01 10:22:55 -0600121 bool popup;
Simon Glassd8adbe92023-01-06 08:52:36 -0600122 void *priv;
Simon Glassc999e172023-06-01 10:22:53 -0600123 struct expo_theme theme;
Simon Glassd8adbe92023-01-06 08:52:36 -0600124 struct list_head scene_head;
125 struct list_head str_head;
Simon Glass683d8832025-05-02 08:46:15 -0600126 struct cli_ch_state cch;
Simon Glassd8adbe92023-01-06 08:52:36 -0600127};
128
129/**
130 * struct expo_string - a string that can be used in an expo
131 *
132 * @id: ID number of the string
133 * @str: String
134 * @sibling: Node to link this object to its siblings
135 */
136struct expo_string {
137 uint id;
138 const char *str;
139 struct list_head sibling;
140};
141
142/**
143 * struct scene - information about a scene in an expo
144 *
145 * A collection of text/image/menu items in an expo
146 *
147 * @expo: Expo this scene is part of
148 * @name: Name of the scene (allocated)
149 * @id: ID number of the scene
Simon Glassea274b62023-06-01 10:22:27 -0600150 * @title_id: String ID of title of the scene (allocated)
Simon Glassd353b752023-06-01 10:22:55 -0600151 * @highlight_id: ID of highlighted object, if any
Simon Glassa968f5f2023-10-01 19:13:31 -0600152 * @cls: cread state to use for input
153 * @buf: Buffer for input
154 * @entry_save: Buffer to hold vidconsole text-entry information
Simon Glassd8adbe92023-01-06 08:52:36 -0600155 * @sibling: Node to link this scene to its siblings
156 * @obj_head: List of objects in the scene
157 */
158struct scene {
159 struct expo *expo;
160 char *name;
161 uint id;
Simon Glassea274b62023-06-01 10:22:27 -0600162 uint title_id;
Simon Glassd353b752023-06-01 10:22:55 -0600163 uint highlight_id;
Simon Glassa968f5f2023-10-01 19:13:31 -0600164 struct cli_line_state cls;
165 struct abuf buf;
166 struct abuf entry_save;
Simon Glassd8adbe92023-01-06 08:52:36 -0600167 struct list_head sibling;
168 struct list_head obj_head;
169};
170
171/**
172 * enum scene_obj_t - type of a scene object
173 *
174 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
175 * @SCENEOBJT_IMAGE: Image data to render
176 * @SCENEOBJT_TEXT: Text line to render
177 * @SCENEOBJT_MENU: Menu containing items the user can select
Simon Glass6116e762023-10-01 19:13:32 -0600178 * @SCENEOBJT_TEXTLINE: Line of text the user can edit
Simon Glassd8adbe92023-01-06 08:52:36 -0600179 */
180enum scene_obj_t {
181 SCENEOBJT_NONE = 0,
182 SCENEOBJT_IMAGE,
183 SCENEOBJT_TEXT,
Simon Glass193bfea2023-10-01 19:13:27 -0600184
185 /* types from here on can be highlighted */
Simon Glassd8adbe92023-01-06 08:52:36 -0600186 SCENEOBJT_MENU,
Simon Glass6116e762023-10-01 19:13:32 -0600187 SCENEOBJT_TEXTLINE,
Simon Glassd8adbe92023-01-06 08:52:36 -0600188};
189
190/**
Simon Glass7b043952023-06-01 10:22:49 -0600191 * struct scene_dim - Dimensions of an object
192 *
193 * @x: x position, in pixels from left side
194 * @y: y position, in pixels from top
195 * @w: width, in pixels
196 * @h: height, in pixels
197 */
198struct scene_dim {
199 int x;
200 int y;
201 int w;
202 int h;
203};
204
205/**
Simon Glass6081b0f2023-06-01 10:22:50 -0600206 * enum scene_obj_flags_t - flags for objects
207 *
208 * @SCENEOF_HIDE: object should be hidden
Simon Glassd353b752023-06-01 10:22:55 -0600209 * @SCENEOF_POINT: object should be highlighted
210 * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
211 * can be selected)
Simon Glass6081b0f2023-06-01 10:22:50 -0600212 */
213enum scene_obj_flags_t {
214 SCENEOF_HIDE = 1 << 0,
Simon Glassd353b752023-06-01 10:22:55 -0600215 SCENEOF_POINT = 1 << 1,
216 SCENEOF_OPEN = 1 << 2,
Simon Glass6081b0f2023-06-01 10:22:50 -0600217};
218
Simon Glassa968f5f2023-10-01 19:13:31 -0600219enum {
220 /* Maximum number of characters allowed in an line editor */
221 EXPO_MAX_CHARS = 250,
222};
223
Simon Glass6081b0f2023-06-01 10:22:50 -0600224/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600225 * struct scene_obj - information about an object in a scene
226 *
227 * @scene: Scene that this object relates to
228 * @name: Name of the object (allocated)
229 * @id: ID number of the object
230 * @type: Type of this object
Simon Glass7b043952023-06-01 10:22:49 -0600231 * @dim: Dimensions for this object
Simon Glass6081b0f2023-06-01 10:22:50 -0600232 * @flags: Flags for this object
Simon Glass2b91ca62023-08-14 16:40:37 -0600233 * @bit_length: Number of bits used for this object in CMOS RAM
234 * @start_bit: Start bit to use for this object in CMOS RAM
Simon Glassd8adbe92023-01-06 08:52:36 -0600235 * @sibling: Node to link this object to its siblings
236 */
237struct scene_obj {
238 struct scene *scene;
239 char *name;
240 uint id;
241 enum scene_obj_t type;
Simon Glass7b043952023-06-01 10:22:49 -0600242 struct scene_dim dim;
Simon Glass2b91ca62023-08-14 16:40:37 -0600243 u8 flags;
244 u8 bit_length;
245 u16 start_bit;
Simon Glassd8adbe92023-01-06 08:52:36 -0600246 struct list_head sibling;
247};
248
Simon Glass193bfea2023-10-01 19:13:27 -0600249/* object can be highlighted when moving around expo */
250static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
251{
252 return obj->type >= SCENEOBJT_MENU;
253}
254
Simon Glassd8adbe92023-01-06 08:52:36 -0600255/**
256 * struct scene_obj_img - information about an image object in a scene
257 *
258 * This is a rectangular image which is blitted onto the display
259 *
260 * @obj: Basic object information
261 * @data: Image data in BMP format
262 */
263struct scene_obj_img {
264 struct scene_obj obj;
265 char *data;
266};
267
268/**
269 * struct scene_obj_txt - information about a text object in a scene
270 *
271 * This is a single-line text object
272 *
273 * @obj: Basic object information
274 * @str_id: ID of the text string to display
275 * @font_name: Name of font (allocated by caller)
276 * @font_size: Nominal size of font in pixels
277 */
278struct scene_obj_txt {
279 struct scene_obj obj;
280 uint str_id;
281 const char *font_name;
282 uint font_size;
283};
284
285/**
286 * struct scene_obj_menu - information about a menu object in a scene
287 *
288 * A menu has a number of items which can be selected by the user
289 *
290 * It also has:
291 *
292 * - a text/image object (@pointer_id) which points to the current item
293 * (@cur_item_id)
294 *
295 * - a preview object which shows an image related to the current item
296 *
297 * @obj: Basic object information
298 * @title_id: ID of the title text, or 0 if none
299 * @cur_item_id: ID of the current menu item, or 0 if none
300 * @pointer_id: ID of the object pointing to the current selection
301 * @item_head: List of items in the menu
302 */
303struct scene_obj_menu {
304 struct scene_obj obj;
305 uint title_id;
306 uint cur_item_id;
307 uint pointer_id;
308 struct list_head item_head;
309};
310
311/**
312 * enum scene_menuitem_flags_t - flags for menu items
313 *
314 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
315 */
316enum scene_menuitem_flags_t {
317 SCENEMIF_GAP_BEFORE = 1 << 0,
318};
319
320/**
321 * struct scene_menitem - a menu item in a menu
322 *
323 * A menu item has:
324 *
325 * - text object holding the name (short) and description (can be longer)
326 * - a text object holding the keypress
327 *
328 * @name: Name of the item (this is allocated by this call)
329 * @id: ID number of the object
330 * @key_id: ID of text object to use as the keypress to show
331 * @label_id: ID of text object to use as the label text
332 * @desc_id: ID of text object to use as the description text
333 * @preview_id: ID of the preview object, or 0 if none
334 * @flags: Flags for this item
Simon Glass100389f2024-10-14 16:31:58 -0600335 * @value: Value for this item, or INT_MAX to use sequence
Simon Glassd8adbe92023-01-06 08:52:36 -0600336 * @sibling: Node to link this item to its siblings
337 */
338struct scene_menitem {
339 char *name;
340 uint id;
341 uint key_id;
342 uint label_id;
343 uint desc_id;
344 uint preview_id;
345 uint flags;
Simon Glass100389f2024-10-14 16:31:58 -0600346 int value;
Simon Glassd8adbe92023-01-06 08:52:36 -0600347 struct list_head sibling;
348};
349
350/**
Simon Glass6116e762023-10-01 19:13:32 -0600351 * struct scene_obj_textline - information about a textline in a scene
352 *
353 * A textline has a prompt and a line of editable text
354 *
355 * @obj: Basic object information
356 * @label_id: ID of the label text, or 0 if none
357 * @edit_id: ID of the editable text
358 * @max_chars: Maximum number of characters allowed
359 * @buf: Text buffer containing current text
360 * @pos: Cursor position
361 */
362struct scene_obj_textline {
363 struct scene_obj obj;
364 uint label_id;
365 uint edit_id;
366 uint max_chars;
367 struct abuf buf;
368 uint pos;
369};
370
371/**
Simon Glass377f18e2024-10-14 16:31:55 -0600372 * struct expo_arrange_info - Information used when arranging a scene
373 *
374 * @label_width: Maximum width of labels in scene
375 */
376struct expo_arrange_info {
377 int label_width;
378};
379
380/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600381 * expo_new() - create a new expo
382 *
383 * Allocates a new expo
384 *
385 * @name: Name of expo (this is allocated by this call)
386 * @priv: Private data for the controller
387 * @expp: Returns a pointer to the new expo on success
388 * Returns: 0 if OK, -ENOMEM if out of memory
389 */
390int expo_new(const char *name, void *priv, struct expo **expp);
391
392/**
393 * expo_destroy() - Destroy an expo and free all its memory
394 *
395 * @exp: Expo to destroy
396 */
397void expo_destroy(struct expo *exp);
398
399/**
Simon Glass6e9e4152023-06-01 10:22:47 -0600400 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
401 *
402 * It is common for a set of 'static' IDs to be used to refer to objects in the
403 * expo. These typically use an enum so that they are defined in sequential
404 * order.
405 *
406 * Dynamic IDs (for objects not in the enum) are intended to be used for
407 * objects to which the code does not need to refer. These are ideally located
408 * above the static IDs.
409 *
410 * Use this function to set the start of the dynamic range, making sure that the
411 * value is higher than all the statically allocated IDs.
412 *
413 * @exp: Expo to update
414 * @dyn_start: Start ID that expo should use for dynamic allocation
415 */
416void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
417
418/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600419 * expo_str() - add a new string to an expo
420 *
421 * @exp: Expo to update
422 * @name: Name to use (this is allocated by this call)
423 * @id: ID to use for the new object (0 to allocate one)
424 * @str: Pointer to text to display (allocated by caller)
425 * Returns: ID number for the object (typically @id), or -ve on error
426 */
427int expo_str(struct expo *exp, const char *name, uint id, const char *str);
428
429/**
430 * expo_get_str() - Get a string by ID
431 *
432 * @exp: Expo to use
433 * @id: String ID to look up
434 * @returns string, or NULL if not found
435 */
436const char *expo_get_str(struct expo *exp, uint id);
437
438/**
439 * expo_set_display() - set the display to use for a expo
440 *
441 * @exp: Expo to update
442 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
443 * Returns: 0 (always)
444 */
445int expo_set_display(struct expo *exp, struct udevice *dev);
446
447/**
Simon Glass7a960052023-06-01 10:22:52 -0600448 * expo_calc_dims() - Calculate the dimensions of the objects
449 *
450 * Updates the width and height of all objects based on their contents
451 *
452 * @exp: Expo to update
453 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
454 */
455int expo_calc_dims(struct expo *exp);
456
457/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600458 * expo_set_scene_id() - Set the current scene ID
459 *
460 * @exp: Expo to update
461 * @scene_id: New scene ID to use (0 to select no scene)
462 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
463 */
464int expo_set_scene_id(struct expo *exp, uint scene_id);
465
466/**
Simon Glassc8925112023-06-01 10:23:02 -0600467 * expo_first_scene_id() - Get the ID of the first scene
468 *
469 * @exp: Expo to check
470 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
471 */
472int expo_first_scene_id(struct expo *exp);
473
474/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600475 * expo_render() - render the expo on the display / console
476 *
477 * @exp: Expo to render
478 *
479 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
480 * current scene is not found, other error if something else goes wrong
481 */
482int expo_render(struct expo *exp);
483
484/**
Simon Glassb2c40342023-06-01 10:22:37 -0600485 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600486 *
487 * @exp: Expo to update
488 * @text_mode: true to use text mode, false to use the console
489 */
Simon Glassb2c40342023-06-01 10:22:37 -0600490void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600491
492/**
493 * scene_new() - create a new scene in a expo
494 *
495 * The scene is given the ID @id which must be unique across all scenes, objects
496 * and items. The expo's @next_id is updated to at least @id + 1
497 *
498 * @exp: Expo to update
499 * @name: Name to use (this is allocated by this call)
500 * @id: ID to use for the new scene (0 to allocate one)
501 * @scnp: Returns a pointer to the new scene on success
502 * Returns: ID number for the scene (typically @id), or -ve on error
503 */
504int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
505
506/**
507 * expo_lookup_scene_id() - Look up a scene by ID
508 *
509 * @exp: Expo to check
510 * @scene_id: Scene ID to look up
511 * @returns pointer to scene if found, else NULL
512 */
513struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
514
515/**
Simon Glass01922ec2023-06-01 10:22:57 -0600516 * scene_highlight_first() - Highlight the first item in a scene
517 *
518 * This highlights the first item, so that the user can see that it is pointed
519 * to
520 *
521 * @scn: Scene to update
522 */
523void scene_highlight_first(struct scene *scn);
524
525/**
526 * scene_set_highlight_id() - Set the object which is highlighted
527 *
528 * Sets a new object to highlight in the scene
529 *
530 * @scn: Scene to update
531 * @id: ID of object to highlight
532 */
533void scene_set_highlight_id(struct scene *scn, uint id);
534
535/**
536 * scene_set_open() - Set whether an item is open or not
537 *
538 * @scn: Scene to update
539 * @id: ID of object to update
540 * @open: true to open the object, false to close it
541 * Returns: 0 if OK, -ENOENT if @id is invalid
542 */
543int scene_set_open(struct scene *scn, uint id, bool open);
544
545/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600546 * scene_obj_count() - Count the number of objects in a scene
547 *
548 * @scn: Scene to check
549 * Returns: number of objects in the scene, 0 if none
550 */
551int scene_obj_count(struct scene *scn);
552
553/**
554 * scene_img() - add a new image to a scene
555 *
556 * @scn: Scene to update
557 * @name: Name to use (this is allocated by this call)
558 * @id: ID to use for the new object (0 to allocate one)
559 * @data: Pointer to image data
560 * @imgp: If non-NULL, returns the new object
561 * Returns: ID number for the object (typically @id), or -ve on error
562 */
563int scene_img(struct scene *scn, const char *name, uint id, char *data,
564 struct scene_obj_img **imgp);
565
566/**
567 * scene_txt() - add a new text object to a scene
568 *
569 * @scn: Scene to update
570 * @name: Name to use (this is allocated by this call)
571 * @id: ID to use for the new object (0 to allocate one)
572 * @str_id: ID of the string to use
573 * @txtp: If non-NULL, returns the new object
574 * Returns: ID number for the object (typically @id), or -ve on error
575 */
576int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
577 struct scene_obj_txt **txtp);
578
579/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600580 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600581 *
582 * @scn: Scene to update
583 * @name: Name to use (this is allocated by this call)
584 * @id: ID to use for the new object (0 to allocate one)
585 * @str_id: ID of the string to use
586 * @str: Pointer to text to display (allocated by caller)
587 * @txtp: If non-NULL, returns the new object
588 * Returns: ID number for the object (typically @id), or -ve on error
589 */
590int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
591 const char *str, struct scene_obj_txt **txtp);
592
593/**
594 * scene_menu() - create a menu
595 *
596 * @scn: Scene to update
597 * @name: Name to use (this is allocated by this call)
598 * @id: ID to use for the new object (0 to allocate one)
599 * @menup: If non-NULL, returns the new object
600 * Returns: ID number for the object (typically @id), or -ve on error
601 */
602int scene_menu(struct scene *scn, const char *name, uint id,
603 struct scene_obj_menu **menup);
604
605/**
Simon Glass6116e762023-10-01 19:13:32 -0600606 * scene_textline() - create a textline
607 *
608 * @scn: Scene to update
609 * @name: Name to use (this is allocated by this call)
610 * @id: ID to use for the new object (0 to allocate one)
611 * @max_chars: Maximum length of the textline in characters
612 * @tlinep: If non-NULL, returns the new object
613 * Returns: ID number for the object (typically @id), or -ve on error
614 */
615int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
616 struct scene_obj_textline **tlinep);
617
618/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600619 * scene_txt_set_font() - Set the font for an object
620 *
621 * @scn: Scene to update
622 * @id: ID of object to update
623 * @font_name: Font name to use (allocated by caller)
624 * @font_size: Font size to use (nominal height in pixels)
625 */
626int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
627 uint font_size);
628
629/**
630 * scene_obj_set_pos() - Set the postion of an object
631 *
632 * @scn: Scene to update
633 * @id: ID of object to update
634 * @x: x position, in pixels from left side
635 * @y: y position, in pixels from top
636 * Returns: 0 if OK, -ENOENT if @id is invalid
637 */
638int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
639
640/**
Simon Glass7a960052023-06-01 10:22:52 -0600641 * scene_obj_set_size() - Set the size of an object
642 *
643 * @scn: Scene to update
644 * @id: ID of object to update
645 * @w: width in pixels
646 * @h: height in pixels
647 * Returns: 0 if OK, -ENOENT if @id is invalid
648 */
649int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
650
651/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600652 * scene_obj_set_hide() - Set whether an object is hidden
653 *
654 * The update happens when the expo is next rendered.
655 *
656 * @scn: Scene to update
657 * @id: ID of object to update
658 * @hide: true to hide the object, false to show it
659 * Returns: 0 if OK, -ENOENT if @id is invalid
660 */
661int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
662
663/**
664 * scene_menu_set_title() - Set the title of a menu
665 *
666 * @scn: Scene to update
667 * @id: ID of menu object to update
668 * @title_id: ID of text object to use as the title
669 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
670 */
671int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
672
673/**
674 * scene_menu_set_pointer() - Set the item pointer for a menu
675 *
676 * This is a visual indicator of the current item, typically a ">" character
677 * which sits next to the current item and moves when the user presses the
678 * up/down arrow keys
679 *
680 * @scn: Scene to update
681 * @id: ID of menu object to update
682 * @cur_item_id: ID of text or image object to use as a pointer to the current
683 * item
684 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
685 */
686int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
687
688/**
689 * scene_obj_get_hw() - Get width and height of an object in a scene
690 *
691 * @scn: Scene to check
692 * @id: ID of menu object to check
693 * @widthp: If non-NULL, returns width of object in pixels
694 * Returns: Height of object in pixels
695 */
696int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
697
698/**
699 * scene_menuitem() - Add an item to a menu
700 *
701 * @scn: Scene to update
702 * @menu_id: ID of menu object to update
703 * @name: Name to use (this is allocated by this call)
704 * @id: ID to use for the new object (0 to allocate one)
705 * @key_id: ID of text object to use as the keypress to show
706 * @label_id: ID of text object to use as the label text
707 * @desc_id: ID of text object to use as the description text
708 * @preview_id: ID of object to use as the preview (text or image)
709 * @flags: Flags for this item (enum scene_menuitem_flags_t)
710 * @itemp: If non-NULL, returns the new object
711 * Returns: ID number for the item (typically @id), or -ve on error
712 */
713int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
714 uint key_id, uint label_id, uint desc_id, uint preview_id,
715 uint flags, struct scene_menitem **itemp);
716
717/**
718 * scene_arrange() - Arrange the scene to deal with object sizes
719 *
720 * Updates any menus in the scene so that their objects are in the right place.
721 *
722 * @scn: Scene to arrange
723 * Returns: 0 if OK, -ve on error
724 */
725int scene_arrange(struct scene *scn);
726
727/**
728 * expo_send_key() - set a keypress to the expo
729 *
730 * @exp: Expo to receive the key
731 * @key: Key to send (ASCII or enum bootmenu_key)
732 * Returns: 0 if OK, -ECHILD if there is no current scene
733 */
734int expo_send_key(struct expo *exp, int key);
735
736/**
737 * expo_action_get() - read user input from the expo
738 *
739 * @exp: Expo to check
740 * @act: Returns action
741 * Returns: 0 if OK, -EAGAIN if there was no action to return
742 */
743int expo_action_get(struct expo *exp, struct expo_action *act);
744
Simon Glassc999e172023-06-01 10:22:53 -0600745/**
746 * expo_apply_theme() - Apply a theme to an expo
747 *
748 * @exp: Expo to update
749 * @node: Node containing the theme
750 */
751int expo_apply_theme(struct expo *exp, ofnode node);
752
Simon Glass61300722023-06-01 10:23:01 -0600753/**
754 * expo_build() - Build an expo from an FDT description
755 *
756 * Build a complete expo from a description in the provided devicetree.
757 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200758 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600759 *
760 * @root: Root node for expo description
761 * @expp: Returns the new expo
762 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
763 * error, -ENOENT if there is a references to a non-existent string
764 */
765int expo_build(ofnode root, struct expo **expp);
766
Simon Glass34344202024-10-14 16:32:11 -0600767/**
768 * cb_expo_build() - Build an expo for coreboot CMOS RAM
769 *
770 * @expp: Returns the expo created
771 * Return: 0 if OK, -ve on error
772 */
773int cb_expo_build(struct expo **expp);
774
Simon Glass137b4422025-05-02 08:46:16 -0600775/**
776 * expo_poll() - render an expo and see if the user takes an action
777 *
778 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
779 * is processed and the resulting action returned, if any
780 *
781 * @exp: Expo to poll
782 * @act: Returns action on success
783 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
784 * went wrong
785 */
786int expo_poll(struct expo *exp, struct expo_action *act);
787
Simon Glass8df4a4e2023-08-14 16:40:25 -0600788#endif /*__EXPO_H */