blob: b6de0310071d3e2c70c5271e7448e4bac9744b2c [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 Glass527d8642025-05-02 08:46:20 -0600108 * @done: Indicates that a cedit session is complete and the user has quit
109 * @save: Indicates that cedit data should be saved, rather than discarded
Simon Glassc999e172023-06-01 10:22:53 -0600110 * @theme: Information about fonts styles, etc.
Simon Glassd8adbe92023-01-06 08:52:36 -0600111 * @scene_head: List of scenes
112 * @str_head: list of strings
Simon Glass683d8832025-05-02 08:46:15 -0600113 * @cch: Keyboard context for input
Simon Glassd8adbe92023-01-06 08:52:36 -0600114 */
115struct expo {
116 char *name;
117 struct udevice *display;
Simon Glass67e2af12023-06-01 10:22:34 -0600118 struct udevice *cons;
Simon Glassd8adbe92023-01-06 08:52:36 -0600119 uint scene_id;
120 uint next_id;
121 struct expo_action action;
122 bool text_mode;
Simon Glassd353b752023-06-01 10:22:55 -0600123 bool popup;
Simon Glassd8adbe92023-01-06 08:52:36 -0600124 void *priv;
Simon Glass527d8642025-05-02 08:46:20 -0600125 bool done;
126 bool save;
Simon Glassc999e172023-06-01 10:22:53 -0600127 struct expo_theme theme;
Simon Glassd8adbe92023-01-06 08:52:36 -0600128 struct list_head scene_head;
129 struct list_head str_head;
Simon Glass683d8832025-05-02 08:46:15 -0600130 struct cli_ch_state cch;
Simon Glassd8adbe92023-01-06 08:52:36 -0600131};
132
133/**
134 * struct expo_string - a string that can be used in an expo
135 *
136 * @id: ID number of the string
Simon Glassda337752025-05-02 08:46:32 -0600137 * @buf: String (contains nul terminator)
Simon Glassd8adbe92023-01-06 08:52:36 -0600138 * @sibling: Node to link this object to its siblings
139 */
140struct expo_string {
141 uint id;
Simon Glassda337752025-05-02 08:46:32 -0600142 struct abuf buf;
Simon Glassd8adbe92023-01-06 08:52:36 -0600143 struct list_head sibling;
144};
145
146/**
147 * struct scene - information about a scene in an expo
148 *
149 * A collection of text/image/menu items in an expo
150 *
151 * @expo: Expo this scene is part of
152 * @name: Name of the scene (allocated)
153 * @id: ID number of the scene
Simon Glassea274b62023-06-01 10:22:27 -0600154 * @title_id: String ID of title of the scene (allocated)
Simon Glassd353b752023-06-01 10:22:55 -0600155 * @highlight_id: ID of highlighted object, if any
Simon Glassa968f5f2023-10-01 19:13:31 -0600156 * @cls: cread state to use for input
157 * @buf: Buffer for input
158 * @entry_save: Buffer to hold vidconsole text-entry information
Simon Glassd8adbe92023-01-06 08:52:36 -0600159 * @sibling: Node to link this scene to its siblings
160 * @obj_head: List of objects in the scene
161 */
162struct scene {
163 struct expo *expo;
164 char *name;
165 uint id;
Simon Glassea274b62023-06-01 10:22:27 -0600166 uint title_id;
Simon Glassd353b752023-06-01 10:22:55 -0600167 uint highlight_id;
Simon Glassa968f5f2023-10-01 19:13:31 -0600168 struct cli_line_state cls;
169 struct abuf buf;
170 struct abuf entry_save;
Simon Glassd8adbe92023-01-06 08:52:36 -0600171 struct list_head sibling;
172 struct list_head obj_head;
173};
174
175/**
176 * enum scene_obj_t - type of a scene object
177 *
178 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
179 * @SCENEOBJT_IMAGE: Image data to render
180 * @SCENEOBJT_TEXT: Text line to render
181 * @SCENEOBJT_MENU: Menu containing items the user can select
Simon Glass6116e762023-10-01 19:13:32 -0600182 * @SCENEOBJT_TEXTLINE: Line of text the user can edit
Simon Glassd8adbe92023-01-06 08:52:36 -0600183 */
184enum scene_obj_t {
185 SCENEOBJT_NONE = 0,
186 SCENEOBJT_IMAGE,
187 SCENEOBJT_TEXT,
Simon Glass193bfea2023-10-01 19:13:27 -0600188
189 /* types from here on can be highlighted */
Simon Glassd8adbe92023-01-06 08:52:36 -0600190 SCENEOBJT_MENU,
Simon Glass6116e762023-10-01 19:13:32 -0600191 SCENEOBJT_TEXTLINE,
Simon Glassd8adbe92023-01-06 08:52:36 -0600192};
193
194/**
Simon Glass854ca692025-05-02 08:46:30 -0600195 * struct scene_obj_bbox - Dimensions of an object
Simon Glass7b043952023-06-01 10:22:49 -0600196 *
Simon Glassbc3a15f2025-05-02 08:46:31 -0600197 * @x0: x position, in pixels from left side
198 * @y0: y position, in pixels from top
Simon Glass7b043952023-06-01 10:22:49 -0600199 * @w: width, in pixels
200 * @h: height, in pixels
201 */
Simon Glass854ca692025-05-02 08:46:30 -0600202struct scene_obj_bbox {
Simon Glassbc3a15f2025-05-02 08:46:31 -0600203 int x0;
204 int y0;
Simon Glass7b043952023-06-01 10:22:49 -0600205 int w;
206 int h;
207};
208
209/**
Simon Glass6081b0f2023-06-01 10:22:50 -0600210 * enum scene_obj_flags_t - flags for objects
211 *
212 * @SCENEOF_HIDE: object should be hidden
Simon Glassd353b752023-06-01 10:22:55 -0600213 * @SCENEOF_POINT: object should be highlighted
214 * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
215 * can be selected)
Simon Glass6081b0f2023-06-01 10:22:50 -0600216 */
217enum scene_obj_flags_t {
218 SCENEOF_HIDE = 1 << 0,
Simon Glassd353b752023-06-01 10:22:55 -0600219 SCENEOF_POINT = 1 << 1,
220 SCENEOF_OPEN = 1 << 2,
Simon Glass6081b0f2023-06-01 10:22:50 -0600221};
222
Simon Glassa968f5f2023-10-01 19:13:31 -0600223enum {
224 /* Maximum number of characters allowed in an line editor */
225 EXPO_MAX_CHARS = 250,
226};
227
Simon Glass6081b0f2023-06-01 10:22:50 -0600228/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600229 * struct scene_obj - information about an object in a scene
230 *
231 * @scene: Scene that this object relates to
232 * @name: Name of the object (allocated)
233 * @id: ID number of the object
234 * @type: Type of this object
Simon Glass854ca692025-05-02 08:46:30 -0600235 * @bbox: Dimensions for this object
Simon Glass6081b0f2023-06-01 10:22:50 -0600236 * @flags: Flags for this object
Simon Glass2b91ca62023-08-14 16:40:37 -0600237 * @bit_length: Number of bits used for this object in CMOS RAM
238 * @start_bit: Start bit to use for this object in CMOS RAM
Simon Glassd8adbe92023-01-06 08:52:36 -0600239 * @sibling: Node to link this object to its siblings
240 */
241struct scene_obj {
242 struct scene *scene;
243 char *name;
244 uint id;
245 enum scene_obj_t type;
Simon Glass854ca692025-05-02 08:46:30 -0600246 struct scene_obj_bbox bbox;
Simon Glass2b91ca62023-08-14 16:40:37 -0600247 u8 flags;
248 u8 bit_length;
249 u16 start_bit;
Simon Glassd8adbe92023-01-06 08:52:36 -0600250 struct list_head sibling;
251};
252
Simon Glass193bfea2023-10-01 19:13:27 -0600253/* object can be highlighted when moving around expo */
254static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
255{
256 return obj->type >= SCENEOBJT_MENU;
257}
258
Simon Glassd8adbe92023-01-06 08:52:36 -0600259/**
260 * struct scene_obj_img - information about an image object in a scene
261 *
262 * This is a rectangular image which is blitted onto the display
263 *
264 * @obj: Basic object information
265 * @data: Image data in BMP format
266 */
267struct scene_obj_img {
268 struct scene_obj obj;
269 char *data;
270};
271
272/**
273 * struct scene_obj_txt - information about a text object in a scene
274 *
275 * This is a single-line text object
276 *
277 * @obj: Basic object information
278 * @str_id: ID of the text string to display
279 * @font_name: Name of font (allocated by caller)
280 * @font_size: Nominal size of font in pixels
281 */
282struct scene_obj_txt {
283 struct scene_obj obj;
284 uint str_id;
285 const char *font_name;
286 uint font_size;
287};
288
289/**
290 * struct scene_obj_menu - information about a menu object in a scene
291 *
292 * A menu has a number of items which can be selected by the user
293 *
294 * It also has:
295 *
296 * - a text/image object (@pointer_id) which points to the current item
297 * (@cur_item_id)
298 *
299 * - a preview object which shows an image related to the current item
300 *
301 * @obj: Basic object information
302 * @title_id: ID of the title text, or 0 if none
303 * @cur_item_id: ID of the current menu item, or 0 if none
304 * @pointer_id: ID of the object pointing to the current selection
305 * @item_head: List of items in the menu
306 */
307struct scene_obj_menu {
308 struct scene_obj obj;
309 uint title_id;
310 uint cur_item_id;
311 uint pointer_id;
312 struct list_head item_head;
313};
314
315/**
316 * enum scene_menuitem_flags_t - flags for menu items
317 *
318 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
319 */
320enum scene_menuitem_flags_t {
321 SCENEMIF_GAP_BEFORE = 1 << 0,
322};
323
324/**
325 * struct scene_menitem - a menu item in a menu
326 *
327 * A menu item has:
328 *
329 * - text object holding the name (short) and description (can be longer)
330 * - a text object holding the keypress
331 *
332 * @name: Name of the item (this is allocated by this call)
333 * @id: ID number of the object
334 * @key_id: ID of text object to use as the keypress to show
335 * @label_id: ID of text object to use as the label text
336 * @desc_id: ID of text object to use as the description text
337 * @preview_id: ID of the preview object, or 0 if none
338 * @flags: Flags for this item
Simon Glass100389f2024-10-14 16:31:58 -0600339 * @value: Value for this item, or INT_MAX to use sequence
Simon Glassd8adbe92023-01-06 08:52:36 -0600340 * @sibling: Node to link this item to its siblings
341 */
342struct scene_menitem {
343 char *name;
344 uint id;
345 uint key_id;
346 uint label_id;
347 uint desc_id;
348 uint preview_id;
349 uint flags;
Simon Glass100389f2024-10-14 16:31:58 -0600350 int value;
Simon Glassd8adbe92023-01-06 08:52:36 -0600351 struct list_head sibling;
352};
353
354/**
Simon Glass6116e762023-10-01 19:13:32 -0600355 * struct scene_obj_textline - information about a textline in a scene
356 *
357 * A textline has a prompt and a line of editable text
358 *
359 * @obj: Basic object information
360 * @label_id: ID of the label text, or 0 if none
361 * @edit_id: ID of the editable text
362 * @max_chars: Maximum number of characters allowed
363 * @buf: Text buffer containing current text
364 * @pos: Cursor position
365 */
366struct scene_obj_textline {
367 struct scene_obj obj;
368 uint label_id;
369 uint edit_id;
370 uint max_chars;
371 struct abuf buf;
372 uint pos;
373};
374
375/**
Simon Glass377f18e2024-10-14 16:31:55 -0600376 * struct expo_arrange_info - Information used when arranging a scene
377 *
378 * @label_width: Maximum width of labels in scene
379 */
380struct expo_arrange_info {
381 int label_width;
382};
383
384/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600385 * expo_new() - create a new expo
386 *
387 * Allocates a new expo
388 *
389 * @name: Name of expo (this is allocated by this call)
390 * @priv: Private data for the controller
391 * @expp: Returns a pointer to the new expo on success
392 * Returns: 0 if OK, -ENOMEM if out of memory
393 */
394int expo_new(const char *name, void *priv, struct expo **expp);
395
396/**
397 * expo_destroy() - Destroy an expo and free all its memory
398 *
399 * @exp: Expo to destroy
400 */
401void expo_destroy(struct expo *exp);
402
403/**
Simon Glass6e9e4152023-06-01 10:22:47 -0600404 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
405 *
406 * It is common for a set of 'static' IDs to be used to refer to objects in the
407 * expo. These typically use an enum so that they are defined in sequential
408 * order.
409 *
410 * Dynamic IDs (for objects not in the enum) are intended to be used for
411 * objects to which the code does not need to refer. These are ideally located
412 * above the static IDs.
413 *
414 * Use this function to set the start of the dynamic range, making sure that the
415 * value is higher than all the statically allocated IDs.
416 *
417 * @exp: Expo to update
418 * @dyn_start: Start ID that expo should use for dynamic allocation
419 */
420void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
421
422/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600423 * expo_str() - add a new string to an expo
424 *
425 * @exp: Expo to update
426 * @name: Name to use (this is allocated by this call)
427 * @id: ID to use for the new object (0 to allocate one)
428 * @str: Pointer to text to display (allocated by caller)
429 * Returns: ID number for the object (typically @id), or -ve on error
430 */
431int expo_str(struct expo *exp, const char *name, uint id, const char *str);
432
433/**
434 * expo_get_str() - Get a string by ID
435 *
436 * @exp: Expo to use
437 * @id: String ID to look up
438 * @returns string, or NULL if not found
439 */
440const char *expo_get_str(struct expo *exp, uint id);
441
442/**
443 * expo_set_display() - set the display to use for a expo
444 *
445 * @exp: Expo to update
446 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
447 * Returns: 0 (always)
448 */
449int expo_set_display(struct expo *exp, struct udevice *dev);
450
451/**
Simon Glass7a960052023-06-01 10:22:52 -0600452 * expo_calc_dims() - Calculate the dimensions of the objects
453 *
454 * Updates the width and height of all objects based on their contents
455 *
456 * @exp: Expo to update
457 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
458 */
459int expo_calc_dims(struct expo *exp);
460
461/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600462 * expo_set_scene_id() - Set the current scene ID
463 *
464 * @exp: Expo to update
465 * @scene_id: New scene ID to use (0 to select no scene)
466 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
467 */
468int expo_set_scene_id(struct expo *exp, uint scene_id);
469
470/**
Simon Glassc8925112023-06-01 10:23:02 -0600471 * expo_first_scene_id() - Get the ID of the first scene
472 *
473 * @exp: Expo to check
474 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
475 */
476int expo_first_scene_id(struct expo *exp);
477
478/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600479 * expo_render() - render the expo on the display / console
480 *
481 * @exp: Expo to render
482 *
483 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
484 * current scene is not found, other error if something else goes wrong
485 */
486int expo_render(struct expo *exp);
487
488/**
Simon Glassb2c40342023-06-01 10:22:37 -0600489 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600490 *
491 * @exp: Expo to update
492 * @text_mode: true to use text mode, false to use the console
493 */
Simon Glassb2c40342023-06-01 10:22:37 -0600494void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600495
496/**
497 * scene_new() - create a new scene in a expo
498 *
499 * The scene is given the ID @id which must be unique across all scenes, objects
500 * and items. The expo's @next_id is updated to at least @id + 1
501 *
502 * @exp: Expo to update
503 * @name: Name to use (this is allocated by this call)
504 * @id: ID to use for the new scene (0 to allocate one)
505 * @scnp: Returns a pointer to the new scene on success
506 * Returns: ID number for the scene (typically @id), or -ve on error
507 */
508int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
509
510/**
511 * expo_lookup_scene_id() - Look up a scene by ID
512 *
513 * @exp: Expo to check
514 * @scene_id: Scene ID to look up
515 * @returns pointer to scene if found, else NULL
516 */
517struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
518
519/**
Simon Glass01922ec2023-06-01 10:22:57 -0600520 * scene_highlight_first() - Highlight the first item in a scene
521 *
522 * This highlights the first item, so that the user can see that it is pointed
523 * to
524 *
525 * @scn: Scene to update
526 */
527void scene_highlight_first(struct scene *scn);
528
529/**
530 * scene_set_highlight_id() - Set the object which is highlighted
531 *
532 * Sets a new object to highlight in the scene
533 *
534 * @scn: Scene to update
535 * @id: ID of object to highlight
536 */
537void scene_set_highlight_id(struct scene *scn, uint id);
538
539/**
540 * scene_set_open() - Set whether an item is open or not
541 *
542 * @scn: Scene to update
543 * @id: ID of object to update
544 * @open: true to open the object, false to close it
545 * Returns: 0 if OK, -ENOENT if @id is invalid
546 */
547int scene_set_open(struct scene *scn, uint id, bool open);
548
549/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600550 * scene_obj_count() - Count the number of objects in a scene
551 *
552 * @scn: Scene to check
553 * Returns: number of objects in the scene, 0 if none
554 */
555int scene_obj_count(struct scene *scn);
556
557/**
558 * scene_img() - add a new image to a scene
559 *
560 * @scn: Scene to update
561 * @name: Name to use (this is allocated by this call)
562 * @id: ID to use for the new object (0 to allocate one)
563 * @data: Pointer to image data
564 * @imgp: If non-NULL, returns the new object
565 * Returns: ID number for the object (typically @id), or -ve on error
566 */
567int scene_img(struct scene *scn, const char *name, uint id, char *data,
568 struct scene_obj_img **imgp);
569
570/**
571 * scene_txt() - add a new text object to a scene
572 *
573 * @scn: Scene to update
574 * @name: Name to use (this is allocated by this call)
575 * @id: ID to use for the new object (0 to allocate one)
576 * @str_id: ID of the string to use
577 * @txtp: If non-NULL, returns the new object
578 * Returns: ID number for the object (typically @id), or -ve on error
579 */
580int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
581 struct scene_obj_txt **txtp);
582
583/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600584 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600585 *
586 * @scn: Scene to update
587 * @name: Name to use (this is allocated by this call)
588 * @id: ID to use for the new object (0 to allocate one)
589 * @str_id: ID of the string to use
590 * @str: Pointer to text to display (allocated by caller)
591 * @txtp: If non-NULL, returns the new object
592 * Returns: ID number for the object (typically @id), or -ve on error
593 */
594int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
595 const char *str, struct scene_obj_txt **txtp);
596
597/**
598 * scene_menu() - create a menu
599 *
600 * @scn: Scene to update
601 * @name: Name to use (this is allocated by this call)
602 * @id: ID to use for the new object (0 to allocate one)
603 * @menup: If non-NULL, returns the new object
604 * Returns: ID number for the object (typically @id), or -ve on error
605 */
606int scene_menu(struct scene *scn, const char *name, uint id,
607 struct scene_obj_menu **menup);
608
609/**
Simon Glass6116e762023-10-01 19:13:32 -0600610 * scene_textline() - create a textline
611 *
612 * @scn: Scene to update
613 * @name: Name to use (this is allocated by this call)
614 * @id: ID to use for the new object (0 to allocate one)
615 * @max_chars: Maximum length of the textline in characters
616 * @tlinep: If non-NULL, returns the new object
617 * Returns: ID number for the object (typically @id), or -ve on error
618 */
619int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
620 struct scene_obj_textline **tlinep);
621
622/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600623 * scene_txt_set_font() - Set the font for an object
624 *
625 * @scn: Scene to update
626 * @id: ID of object to update
627 * @font_name: Font name to use (allocated by caller)
628 * @font_size: Font size to use (nominal height in pixels)
629 */
630int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
631 uint font_size);
632
633/**
634 * scene_obj_set_pos() - Set the postion of an object
635 *
636 * @scn: Scene to update
637 * @id: ID of object to update
638 * @x: x position, in pixels from left side
639 * @y: y position, in pixels from top
640 * Returns: 0 if OK, -ENOENT if @id is invalid
641 */
642int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
643
644/**
Simon Glass7a960052023-06-01 10:22:52 -0600645 * scene_obj_set_size() - Set the size of an object
646 *
647 * @scn: Scene to update
648 * @id: ID of object to update
649 * @w: width in pixels
650 * @h: height in pixels
651 * Returns: 0 if OK, -ENOENT if @id is invalid
652 */
653int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
654
655/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600656 * scene_obj_set_hide() - Set whether an object is hidden
657 *
658 * The update happens when the expo is next rendered.
659 *
660 * @scn: Scene to update
661 * @id: ID of object to update
662 * @hide: true to hide the object, false to show it
663 * Returns: 0 if OK, -ENOENT if @id is invalid
664 */
665int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
666
667/**
668 * scene_menu_set_title() - Set the title of a menu
669 *
670 * @scn: Scene to update
671 * @id: ID of menu object to update
672 * @title_id: ID of text object to use as the title
673 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
674 */
675int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
676
677/**
678 * scene_menu_set_pointer() - Set the item pointer for a menu
679 *
680 * This is a visual indicator of the current item, typically a ">" character
681 * which sits next to the current item and moves when the user presses the
682 * up/down arrow keys
683 *
684 * @scn: Scene to update
685 * @id: ID of menu object to update
686 * @cur_item_id: ID of text or image object to use as a pointer to the current
687 * item
688 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
689 */
690int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
691
692/**
Simon Glassbe04b962025-05-02 08:46:24 -0600693 * scene_menu_select_item() - move the pointer/highlight to an item
694 *
695 * @scn: Scene to update
696 * @id: ID of menu object to update
697 * @sel_id: ID of the menuitem to select
698 * Return 0 on success, -ENOENT if there was no such item
699 */
700int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
701
702/**
703 * scene_menu_get_cur_item() - get the currently pointed-to item
704 *
705 * @scn: Scene to update
706 * @id: ID of menu object to update
707 * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
708 * valid, 0 if no item is pointed to
709 */
710int scene_menu_get_cur_item(struct scene *scn, uint id);
711
712/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600713 * scene_obj_get_hw() - Get width and height of an object in a scene
714 *
715 * @scn: Scene to check
716 * @id: ID of menu object to check
717 * @widthp: If non-NULL, returns width of object in pixels
718 * Returns: Height of object in pixels
719 */
720int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
721
722/**
723 * scene_menuitem() - Add an item to a menu
724 *
725 * @scn: Scene to update
726 * @menu_id: ID of menu object to update
727 * @name: Name to use (this is allocated by this call)
728 * @id: ID to use for the new object (0 to allocate one)
729 * @key_id: ID of text object to use as the keypress to show
730 * @label_id: ID of text object to use as the label text
731 * @desc_id: ID of text object to use as the description text
732 * @preview_id: ID of object to use as the preview (text or image)
733 * @flags: Flags for this item (enum scene_menuitem_flags_t)
734 * @itemp: If non-NULL, returns the new object
735 * Returns: ID number for the item (typically @id), or -ve on error
736 */
737int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
738 uint key_id, uint label_id, uint desc_id, uint preview_id,
739 uint flags, struct scene_menitem **itemp);
740
741/**
742 * scene_arrange() - Arrange the scene to deal with object sizes
743 *
744 * Updates any menus in the scene so that their objects are in the right place.
745 *
746 * @scn: Scene to arrange
747 * Returns: 0 if OK, -ve on error
748 */
749int scene_arrange(struct scene *scn);
750
751/**
752 * expo_send_key() - set a keypress to the expo
753 *
754 * @exp: Expo to receive the key
755 * @key: Key to send (ASCII or enum bootmenu_key)
756 * Returns: 0 if OK, -ECHILD if there is no current scene
757 */
758int expo_send_key(struct expo *exp, int key);
759
760/**
761 * expo_action_get() - read user input from the expo
762 *
763 * @exp: Expo to check
764 * @act: Returns action
765 * Returns: 0 if OK, -EAGAIN if there was no action to return
766 */
767int expo_action_get(struct expo *exp, struct expo_action *act);
768
Simon Glassc999e172023-06-01 10:22:53 -0600769/**
770 * expo_apply_theme() - Apply a theme to an expo
771 *
772 * @exp: Expo to update
773 * @node: Node containing the theme
774 */
775int expo_apply_theme(struct expo *exp, ofnode node);
776
Simon Glass61300722023-06-01 10:23:01 -0600777/**
778 * expo_build() - Build an expo from an FDT description
779 *
780 * Build a complete expo from a description in the provided devicetree.
781 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200782 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600783 *
784 * @root: Root node for expo description
785 * @expp: Returns the new expo
786 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
787 * error, -ENOENT if there is a references to a non-existent string
788 */
789int expo_build(ofnode root, struct expo **expp);
790
Simon Glass34344202024-10-14 16:32:11 -0600791/**
792 * cb_expo_build() - Build an expo for coreboot CMOS RAM
793 *
794 * @expp: Returns the expo created
795 * Return: 0 if OK, -ve on error
796 */
797int cb_expo_build(struct expo **expp);
798
Simon Glass137b4422025-05-02 08:46:16 -0600799/**
800 * expo_poll() - render an expo and see if the user takes an action
801 *
802 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
803 * is processed and the resulting action returned, if any
804 *
805 * @exp: Expo to poll
806 * @act: Returns action on success
807 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
808 * went wrong
809 */
810int expo_poll(struct expo *exp, struct expo_action *act);
811
Simon Glass8df4a4e2023-08-14 16:40:25 -0600812#endif /*__EXPO_H */