blob: 8833dcceb7e5f791c46fc635df45296aa2a223a5 [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 Glasscfb4f2c2025-05-02 08:46:42 -060011#include <alist.h>
Simon Glassc999e172023-06-01 10:22:53 -060012#include <dm/ofnode_decl.h>
Simon Glassebec4972025-05-02 08:46:33 -060013#include <linux/bitops.h>
Simon Glassd8adbe92023-01-06 08:52:36 -060014#include <linux/list.h>
15
16struct udevice;
17
Simon Glassa968f5f2023-10-01 19:13:31 -060018#include <cli.h>
19
Simon Glassd8adbe92023-01-06 08:52:36 -060020/**
Simon Glass53a0a2f2024-10-14 16:31:57 -060021 * enum expo_id_t - standard expo IDs
22 *
23 * These are assumed to be in use at all times. Expos should use IDs starting
24 * from EXPOID_BASE_ID,
25 *
26 * @EXPOID_NONE: Not used, invalid ID 0
27 * @EXPOID_SAVE: User has requested that the expo data be saved
28 * @EXPOID_DISCARD: User has requested that the expo data be discarded
29 * @EXPOID_BASE_ID: First ID which can be used for expo objects
30 */
31enum expo_id_t {
32 EXPOID_NONE,
33
34 EXPOID_SAVE,
35 EXPOID_DISCARD,
36
37 EXPOID_BASE_ID = 5,
38};
39
40/**
Simon Glassd8adbe92023-01-06 08:52:36 -060041 * enum expoact_type - types of actions reported by the expo
42 *
43 * @EXPOACT_NONE: no action
Simon Glassf0e1e8c2023-06-01 10:22:59 -060044 * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which)
Simon Glass719a3c62023-06-01 10:22:56 -060045 * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
Simon Glassd8adbe92023-01-06 08:52:36 -060046 * @EXPOACT_SELECT: menu item was selected (@id indicates which)
Simon Glassf0e1e8c2023-06-01 10:22:59 -060047 * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates
48 * which menu object)
49 * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object)
Simon Glassd8adbe92023-01-06 08:52:36 -060050 * @EXPOACT_QUIT: request to exit the menu
51 */
52enum expoact_type {
53 EXPOACT_NONE,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060054 EXPOACT_POINT_OBJ,
Simon Glass719a3c62023-06-01 10:22:56 -060055 EXPOACT_POINT_ITEM,
Simon Glassd8adbe92023-01-06 08:52:36 -060056 EXPOACT_SELECT,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060057 EXPOACT_OPEN,
58 EXPOACT_CLOSE,
Simon Glassd8adbe92023-01-06 08:52:36 -060059 EXPOACT_QUIT,
60};
61
62/**
63 * struct expo_action - an action report by the expo
64 *
65 * @type: Action type (EXPOACT_NONE if there is no action)
Simon Glass719a3c62023-06-01 10:22:56 -060066 * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT
Heinrich Schuchardta99e8fe2024-09-18 23:58:03 +020067 * @select.id: ID number of the object affected.
Simon Glassd8adbe92023-01-06 08:52:36 -060068 */
69struct expo_action {
70 enum expoact_type type;
71 union {
72 struct {
73 int id;
74 } select;
75 };
76};
77
78/**
Simon Glassc999e172023-06-01 10:22:53 -060079 * struct expo_theme - theme for the expo
80 *
81 * @font_size: Default font size for all text
82 * @menu_inset: Inset width (on each side and top/bottom) for menu items
83 * @menuitem_gap_y: Gap between menu items in pixels
Simon Glass377f18e2024-10-14 16:31:55 -060084 * @menu_title_margin_x: Gap between right side of menu title and left size of
85 * menu label
Simon Glassc999e172023-06-01 10:22:53 -060086 */
87struct expo_theme {
88 u32 font_size;
89 u32 menu_inset;
90 u32 menuitem_gap_y;
Simon Glass377f18e2024-10-14 16:31:55 -060091 u32 menu_title_margin_x;
Simon Glassc999e172023-06-01 10:22:53 -060092};
93
94/**
Simon Glassd8adbe92023-01-06 08:52:36 -060095 * struct expo - information about an expo
96 *
97 * A group of scenes which can be presented to the user, typically to obtain
98 * input or to make a selection.
99 *
100 * @name: Name of the expo (allocated)
101 * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
Simon Glass67e2af12023-06-01 10:22:34 -0600102 * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600103 * @scene_id: Current scene ID (0 if none)
104 * @next_id: Next ID number to use, for automatic allocation
105 * @action: Action selected by user. At present only one is supported, with the
106 * type set to EXPOACT_NONE if there is no action
107 * @text_mode: true to use text mode for the menu (no vidconsole)
Simon Glassd353b752023-06-01 10:22:55 -0600108 * @popup: true to use popup menus, instead of showing all items
Simon Glassd8adbe92023-01-06 08:52:36 -0600109 * @priv: Private data for the controller
Simon Glass527d8642025-05-02 08:46:20 -0600110 * @done: Indicates that a cedit session is complete and the user has quit
111 * @save: Indicates that cedit data should be saved, rather than discarded
Simon Glassc999e172023-06-01 10:22:53 -0600112 * @theme: Information about fonts styles, etc.
Simon Glassd8adbe92023-01-06 08:52:36 -0600113 * @scene_head: List of scenes
114 * @str_head: list of strings
Simon Glass683d8832025-05-02 08:46:15 -0600115 * @cch: Keyboard context for input
Simon Glassd8adbe92023-01-06 08:52:36 -0600116 */
117struct expo {
118 char *name;
119 struct udevice *display;
Simon Glass67e2af12023-06-01 10:22:34 -0600120 struct udevice *cons;
Simon Glassd8adbe92023-01-06 08:52:36 -0600121 uint scene_id;
122 uint next_id;
123 struct expo_action action;
124 bool text_mode;
Simon Glassd353b752023-06-01 10:22:55 -0600125 bool popup;
Simon Glassd8adbe92023-01-06 08:52:36 -0600126 void *priv;
Simon Glass527d8642025-05-02 08:46:20 -0600127 bool done;
128 bool save;
Simon Glassc999e172023-06-01 10:22:53 -0600129 struct expo_theme theme;
Simon Glassd8adbe92023-01-06 08:52:36 -0600130 struct list_head scene_head;
131 struct list_head str_head;
Simon Glass683d8832025-05-02 08:46:15 -0600132 struct cli_ch_state cch;
Simon Glassd8adbe92023-01-06 08:52:36 -0600133};
134
135/**
136 * struct expo_string - a string that can be used in an expo
137 *
138 * @id: ID number of the string
Simon Glassda337752025-05-02 08:46:32 -0600139 * @buf: String (contains nul terminator)
Simon Glassd8adbe92023-01-06 08:52:36 -0600140 * @sibling: Node to link this object to its siblings
141 */
142struct expo_string {
143 uint id;
Simon Glassda337752025-05-02 08:46:32 -0600144 struct abuf buf;
Simon Glassd8adbe92023-01-06 08:52:36 -0600145 struct list_head sibling;
146};
147
148/**
149 * struct scene - information about a scene in an expo
150 *
151 * A collection of text/image/menu items in an expo
152 *
153 * @expo: Expo this scene is part of
154 * @name: Name of the scene (allocated)
155 * @id: ID number of the scene
Simon Glassea274b62023-06-01 10:22:27 -0600156 * @title_id: String ID of title of the scene (allocated)
Simon Glassd353b752023-06-01 10:22:55 -0600157 * @highlight_id: ID of highlighted object, if any
Simon Glassa968f5f2023-10-01 19:13:31 -0600158 * @cls: cread state to use for input
159 * @buf: Buffer for input
160 * @entry_save: Buffer to hold vidconsole text-entry information
Simon Glassd8adbe92023-01-06 08:52:36 -0600161 * @sibling: Node to link this scene to its siblings
162 * @obj_head: List of objects in the scene
163 */
164struct scene {
165 struct expo *expo;
166 char *name;
167 uint id;
Simon Glassea274b62023-06-01 10:22:27 -0600168 uint title_id;
Simon Glassd353b752023-06-01 10:22:55 -0600169 uint highlight_id;
Simon Glassa968f5f2023-10-01 19:13:31 -0600170 struct cli_line_state cls;
171 struct abuf buf;
172 struct abuf entry_save;
Simon Glassd8adbe92023-01-06 08:52:36 -0600173 struct list_head sibling;
174 struct list_head obj_head;
175};
176
177/**
178 * enum scene_obj_t - type of a scene object
179 *
180 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
181 * @SCENEOBJT_IMAGE: Image data to render
Simon Glass138a3972025-05-02 08:46:44 -0600182 * @SCENEOBJT_BOX: Rectangular box
Simon Glassd8adbe92023-01-06 08:52:36 -0600183 * @SCENEOBJT_TEXT: Text line to render
184 * @SCENEOBJT_MENU: Menu containing items the user can select
Simon Glass6116e762023-10-01 19:13:32 -0600185 * @SCENEOBJT_TEXTLINE: Line of text the user can edit
Simon Glassd8adbe92023-01-06 08:52:36 -0600186 */
187enum scene_obj_t {
188 SCENEOBJT_NONE = 0,
189 SCENEOBJT_IMAGE,
190 SCENEOBJT_TEXT,
Simon Glass138a3972025-05-02 08:46:44 -0600191 SCENEOBJT_BOX,
Simon Glass193bfea2023-10-01 19:13:27 -0600192
193 /* types from here on can be highlighted */
Simon Glassd8adbe92023-01-06 08:52:36 -0600194 SCENEOBJT_MENU,
Simon Glass6116e762023-10-01 19:13:32 -0600195 SCENEOBJT_TEXTLINE,
Simon Glassd8adbe92023-01-06 08:52:36 -0600196};
197
198/**
Simon Glass854ca692025-05-02 08:46:30 -0600199 * struct scene_obj_bbox - Dimensions of an object
Simon Glass7b043952023-06-01 10:22:49 -0600200 *
Simon Glassbc3a15f2025-05-02 08:46:31 -0600201 * @x0: x position, in pixels from left side
202 * @y0: y position, in pixels from top
Simon Glassebec4972025-05-02 08:46:33 -0600203 * @x1: x position of right size
204 * @y1: y position of bottom
Simon Glass7b043952023-06-01 10:22:49 -0600205 */
Simon Glass854ca692025-05-02 08:46:30 -0600206struct scene_obj_bbox {
Simon Glassbc3a15f2025-05-02 08:46:31 -0600207 int x0;
208 int y0;
Simon Glassebec4972025-05-02 08:46:33 -0600209 int x1;
210 int y1;
Simon Glass7b043952023-06-01 10:22:49 -0600211};
212
213/**
Simon Glassebec4972025-05-02 08:46:33 -0600214 * struct scene_obj_dims - Dimensions of the object being drawn
215 *
216 * Image and text objects have a dimension which can change depending on what
217 * they contain. For images this stores the size. For text it stores the size as
218 * rendered on the display
219 *
220 * @x: x dimension
221 * @y: y dimension
222 */
223struct scene_obj_dims {
224 int x;
225 int y;
226};
227
228/**
Simon Glass6081b0f2023-06-01 10:22:50 -0600229 * enum scene_obj_flags_t - flags for objects
230 *
231 * @SCENEOF_HIDE: object should be hidden
Simon Glassd353b752023-06-01 10:22:55 -0600232 * @SCENEOF_POINT: object should be highlighted
233 * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
234 * can be selected)
Simon Glassebec4972025-05-02 08:46:33 -0600235 * @SCENEOF_SIZE_VALID: object's size (width/height) is valid, so any adjustment
236 * to x0/y0 should maintain the width/height of the object
Simon Glass6081b0f2023-06-01 10:22:50 -0600237 */
238enum scene_obj_flags_t {
239 SCENEOF_HIDE = 1 << 0,
Simon Glassd353b752023-06-01 10:22:55 -0600240 SCENEOF_POINT = 1 << 1,
241 SCENEOF_OPEN = 1 << 2,
Simon Glassebec4972025-05-02 08:46:33 -0600242 SCENEOF_SIZE_VALID = BIT(3),
Simon Glass6081b0f2023-06-01 10:22:50 -0600243};
244
Simon Glassa968f5f2023-10-01 19:13:31 -0600245enum {
246 /* Maximum number of characters allowed in an line editor */
247 EXPO_MAX_CHARS = 250,
248};
249
Simon Glass6081b0f2023-06-01 10:22:50 -0600250/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600251 * struct scene_obj - information about an object in a scene
252 *
253 * @scene: Scene that this object relates to
254 * @name: Name of the object (allocated)
255 * @id: ID number of the object
256 * @type: Type of this object
Simon Glassebec4972025-05-02 08:46:33 -0600257 * @bbox: Bounding box for this object
258 * @dims: Dimensions of the text/image (may be smaller than bbox)
Simon Glass6081b0f2023-06-01 10:22:50 -0600259 * @flags: Flags for this object
Simon Glass2b91ca62023-08-14 16:40:37 -0600260 * @bit_length: Number of bits used for this object in CMOS RAM
261 * @start_bit: Start bit to use for this object in CMOS RAM
Simon Glassd8adbe92023-01-06 08:52:36 -0600262 * @sibling: Node to link this object to its siblings
263 */
264struct scene_obj {
265 struct scene *scene;
266 char *name;
267 uint id;
268 enum scene_obj_t type;
Simon Glass854ca692025-05-02 08:46:30 -0600269 struct scene_obj_bbox bbox;
Simon Glassebec4972025-05-02 08:46:33 -0600270 struct scene_obj_dims dims;
Simon Glass2b91ca62023-08-14 16:40:37 -0600271 u8 flags;
272 u8 bit_length;
273 u16 start_bit;
Simon Glassd8adbe92023-01-06 08:52:36 -0600274 struct list_head sibling;
275};
276
Simon Glass193bfea2023-10-01 19:13:27 -0600277/* object can be highlighted when moving around expo */
278static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
279{
280 return obj->type >= SCENEOBJT_MENU;
281}
282
Simon Glassd8adbe92023-01-06 08:52:36 -0600283/**
284 * struct scene_obj_img - information about an image object in a scene
285 *
286 * This is a rectangular image which is blitted onto the display
287 *
288 * @obj: Basic object information
289 * @data: Image data in BMP format
290 */
291struct scene_obj_img {
292 struct scene_obj obj;
293 char *data;
294};
295
296/**
Simon Glass9ef02aa2025-05-02 08:46:37 -0600297 * struct scene_txt_generic - Generic information common to text objects
Simon Glassd8adbe92023-01-06 08:52:36 -0600298 *
Simon Glassd8adbe92023-01-06 08:52:36 -0600299 * @str_id: ID of the text string to display
300 * @font_name: Name of font (allocated by caller)
301 * @font_size: Nominal size of font in pixels
Simon Glasscfb4f2c2025-05-02 08:46:42 -0600302 * @lines: alist of struct vidconsole_mline with a separate record for each
303 * line of text
Simon Glassd8adbe92023-01-06 08:52:36 -0600304 */
Simon Glass9ef02aa2025-05-02 08:46:37 -0600305struct scene_txt_generic {
Simon Glassd8adbe92023-01-06 08:52:36 -0600306 uint str_id;
307 const char *font_name;
308 uint font_size;
Simon Glasscfb4f2c2025-05-02 08:46:42 -0600309 struct alist lines;
Simon Glassd8adbe92023-01-06 08:52:36 -0600310};
311
312/**
Simon Glass9ef02aa2025-05-02 08:46:37 -0600313 * struct scene_obj_txt - information about a text object in a scene
314 *
315 * This is a single-line text object
316 *
317 * @obj: Basic object information
318 * @gen: Generic information common to all objects which show text
319 */
320struct scene_obj_txt {
321 struct scene_obj obj;
322 struct scene_txt_generic gen;
323};
324
325/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600326 * struct scene_obj_menu - information about a menu object in a scene
327 *
328 * A menu has a number of items which can be selected by the user
329 *
330 * It also has:
331 *
332 * - a text/image object (@pointer_id) which points to the current item
333 * (@cur_item_id)
334 *
335 * - a preview object which shows an image related to the current item
336 *
337 * @obj: Basic object information
338 * @title_id: ID of the title text, or 0 if none
339 * @cur_item_id: ID of the current menu item, or 0 if none
340 * @pointer_id: ID of the object pointing to the current selection
341 * @item_head: List of items in the menu
342 */
343struct scene_obj_menu {
344 struct scene_obj obj;
345 uint title_id;
346 uint cur_item_id;
347 uint pointer_id;
348 struct list_head item_head;
349};
350
351/**
352 * enum scene_menuitem_flags_t - flags for menu items
353 *
354 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
355 */
356enum scene_menuitem_flags_t {
357 SCENEMIF_GAP_BEFORE = 1 << 0,
358};
359
360/**
361 * struct scene_menitem - a menu item in a menu
362 *
363 * A menu item has:
364 *
365 * - text object holding the name (short) and description (can be longer)
366 * - a text object holding the keypress
367 *
368 * @name: Name of the item (this is allocated by this call)
369 * @id: ID number of the object
370 * @key_id: ID of text object to use as the keypress to show
371 * @label_id: ID of text object to use as the label text
372 * @desc_id: ID of text object to use as the description text
373 * @preview_id: ID of the preview object, or 0 if none
374 * @flags: Flags for this item
Simon Glass100389f2024-10-14 16:31:58 -0600375 * @value: Value for this item, or INT_MAX to use sequence
Simon Glassd8adbe92023-01-06 08:52:36 -0600376 * @sibling: Node to link this item to its siblings
377 */
378struct scene_menitem {
379 char *name;
380 uint id;
381 uint key_id;
382 uint label_id;
383 uint desc_id;
384 uint preview_id;
385 uint flags;
Simon Glass100389f2024-10-14 16:31:58 -0600386 int value;
Simon Glassd8adbe92023-01-06 08:52:36 -0600387 struct list_head sibling;
388};
389
390/**
Simon Glass6116e762023-10-01 19:13:32 -0600391 * struct scene_obj_textline - information about a textline in a scene
392 *
393 * A textline has a prompt and a line of editable text
394 *
395 * @obj: Basic object information
396 * @label_id: ID of the label text, or 0 if none
397 * @edit_id: ID of the editable text
398 * @max_chars: Maximum number of characters allowed
399 * @buf: Text buffer containing current text
400 * @pos: Cursor position
401 */
402struct scene_obj_textline {
403 struct scene_obj obj;
404 uint label_id;
405 uint edit_id;
406 uint max_chars;
407 struct abuf buf;
408 uint pos;
409};
410
411/**
Simon Glass138a3972025-05-02 08:46:44 -0600412 * struct scene_obj_box - information about a box in a scene
413 *
414 * A box surrounds a part of the screen with a border
415 *
416 * @obj: Basic object information
417 * @width: Line-width in pixels
418 */
419struct scene_obj_box {
420 struct scene_obj obj;
421 uint width;
422};
423
424/**
Simon Glass377f18e2024-10-14 16:31:55 -0600425 * struct expo_arrange_info - Information used when arranging a scene
426 *
427 * @label_width: Maximum width of labels in scene
428 */
429struct expo_arrange_info {
430 int label_width;
431};
432
433/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600434 * expo_new() - create a new expo
435 *
436 * Allocates a new expo
437 *
438 * @name: Name of expo (this is allocated by this call)
439 * @priv: Private data for the controller
440 * @expp: Returns a pointer to the new expo on success
441 * Returns: 0 if OK, -ENOMEM if out of memory
442 */
443int expo_new(const char *name, void *priv, struct expo **expp);
444
445/**
446 * expo_destroy() - Destroy an expo and free all its memory
447 *
448 * @exp: Expo to destroy
449 */
450void expo_destroy(struct expo *exp);
451
452/**
Simon Glass6e9e4152023-06-01 10:22:47 -0600453 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
454 *
455 * It is common for a set of 'static' IDs to be used to refer to objects in the
456 * expo. These typically use an enum so that they are defined in sequential
457 * order.
458 *
459 * Dynamic IDs (for objects not in the enum) are intended to be used for
460 * objects to which the code does not need to refer. These are ideally located
461 * above the static IDs.
462 *
463 * Use this function to set the start of the dynamic range, making sure that the
464 * value is higher than all the statically allocated IDs.
465 *
466 * @exp: Expo to update
467 * @dyn_start: Start ID that expo should use for dynamic allocation
468 */
469void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
470
471/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600472 * expo_str() - add a new string to an expo
473 *
474 * @exp: Expo to update
475 * @name: Name to use (this is allocated by this call)
476 * @id: ID to use for the new object (0 to allocate one)
477 * @str: Pointer to text to display (allocated by caller)
478 * Returns: ID number for the object (typically @id), or -ve on error
479 */
480int expo_str(struct expo *exp, const char *name, uint id, const char *str);
481
482/**
483 * expo_get_str() - Get a string by ID
484 *
485 * @exp: Expo to use
486 * @id: String ID to look up
487 * @returns string, or NULL if not found
488 */
489const char *expo_get_str(struct expo *exp, uint id);
490
491/**
Simon Glassc5ae5b12025-05-02 08:46:40 -0600492 * expo_edit_str() - Make a string writeable
493 *
494 * This allows a string to be updated under the control of the caller. The
495 * buffer must remain valid while the expo is active.
496 *
497 * @exp: Expo to use
498 * @id: String ID to look up
499 * @orig: If non-NULL, returns the original buffer, which can be used by the
500 * caller. It is no-longer used by expo so must be uninited by the caller.
501 * It contains a snapshot of the string contents
502 * @copyp: Returns a pointer to the new, writeable buffer
503 * Return: 0 if OK, -ENOENT if the id was not found, -ENOMEM if out of memory
504 */
505int expo_edit_str(struct expo *exp, uint id, struct abuf *orig,
506 struct abuf **copyp);
507
508/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600509 * expo_set_display() - set the display to use for a expo
510 *
511 * @exp: Expo to update
512 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
513 * Returns: 0 (always)
514 */
515int expo_set_display(struct expo *exp, struct udevice *dev);
516
517/**
Simon Glass7a960052023-06-01 10:22:52 -0600518 * expo_calc_dims() - Calculate the dimensions of the objects
519 *
520 * Updates the width and height of all objects based on their contents
521 *
522 * @exp: Expo to update
523 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
524 */
525int expo_calc_dims(struct expo *exp);
526
527/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600528 * expo_set_scene_id() - Set the current scene ID
529 *
530 * @exp: Expo to update
531 * @scene_id: New scene ID to use (0 to select no scene)
532 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
533 */
534int expo_set_scene_id(struct expo *exp, uint scene_id);
535
536/**
Simon Glassc8925112023-06-01 10:23:02 -0600537 * expo_first_scene_id() - Get the ID of the first scene
538 *
539 * @exp: Expo to check
540 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
541 */
542int expo_first_scene_id(struct expo *exp);
543
544/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600545 * expo_render() - render the expo on the display / console
546 *
547 * @exp: Expo to render
548 *
549 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
550 * current scene is not found, other error if something else goes wrong
551 */
552int expo_render(struct expo *exp);
553
554/**
Simon Glassb2c40342023-06-01 10:22:37 -0600555 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600556 *
557 * @exp: Expo to update
558 * @text_mode: true to use text mode, false to use the console
559 */
Simon Glassb2c40342023-06-01 10:22:37 -0600560void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600561
562/**
563 * scene_new() - create a new scene in a expo
564 *
565 * The scene is given the ID @id which must be unique across all scenes, objects
566 * and items. The expo's @next_id is updated to at least @id + 1
567 *
568 * @exp: Expo to update
569 * @name: Name to use (this is allocated by this call)
570 * @id: ID to use for the new scene (0 to allocate one)
571 * @scnp: Returns a pointer to the new scene on success
572 * Returns: ID number for the scene (typically @id), or -ve on error
573 */
574int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
575
576/**
577 * expo_lookup_scene_id() - Look up a scene by ID
578 *
579 * @exp: Expo to check
580 * @scene_id: Scene ID to look up
581 * @returns pointer to scene if found, else NULL
582 */
583struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
584
585/**
Simon Glass01922ec2023-06-01 10:22:57 -0600586 * scene_highlight_first() - Highlight the first item in a scene
587 *
588 * This highlights the first item, so that the user can see that it is pointed
589 * to
590 *
591 * @scn: Scene to update
592 */
593void scene_highlight_first(struct scene *scn);
594
595/**
596 * scene_set_highlight_id() - Set the object which is highlighted
597 *
598 * Sets a new object to highlight in the scene
599 *
600 * @scn: Scene to update
601 * @id: ID of object to highlight
602 */
603void scene_set_highlight_id(struct scene *scn, uint id);
604
605/**
606 * scene_set_open() - Set whether an item is open or not
607 *
608 * @scn: Scene to update
609 * @id: ID of object to update
610 * @open: true to open the object, false to close it
611 * Returns: 0 if OK, -ENOENT if @id is invalid
612 */
613int scene_set_open(struct scene *scn, uint id, bool open);
614
615/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600616 * scene_obj_count() - Count the number of objects in a scene
617 *
618 * @scn: Scene to check
619 * Returns: number of objects in the scene, 0 if none
620 */
621int scene_obj_count(struct scene *scn);
622
623/**
624 * scene_img() - add a new image to a scene
625 *
626 * @scn: Scene to update
627 * @name: Name to use (this is allocated by this call)
628 * @id: ID to use for the new object (0 to allocate one)
629 * @data: Pointer to image data
630 * @imgp: If non-NULL, returns the new object
631 * Returns: ID number for the object (typically @id), or -ve on error
632 */
633int scene_img(struct scene *scn, const char *name, uint id, char *data,
634 struct scene_obj_img **imgp);
635
636/**
637 * scene_txt() - add a new text object to a scene
638 *
639 * @scn: Scene to update
640 * @name: Name to use (this is allocated by this call)
641 * @id: ID to use for the new object (0 to allocate one)
642 * @str_id: ID of the string to use
643 * @txtp: If non-NULL, returns the new object
644 * Returns: ID number for the object (typically @id), or -ve on error
645 */
646int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
647 struct scene_obj_txt **txtp);
648
649/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600650 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600651 *
652 * @scn: Scene to update
653 * @name: Name to use (this is allocated by this call)
654 * @id: ID to use for the new object (0 to allocate one)
655 * @str_id: ID of the string to use
656 * @str: Pointer to text to display (allocated by caller)
657 * @txtp: If non-NULL, returns the new object
658 * Returns: ID number for the object (typically @id), or -ve on error
659 */
660int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
661 const char *str, struct scene_obj_txt **txtp);
662
663/**
664 * scene_menu() - create a menu
665 *
666 * @scn: Scene to update
667 * @name: Name to use (this is allocated by this call)
668 * @id: ID to use for the new object (0 to allocate one)
669 * @menup: If non-NULL, returns the new object
670 * Returns: ID number for the object (typically @id), or -ve on error
671 */
672int scene_menu(struct scene *scn, const char *name, uint id,
673 struct scene_obj_menu **menup);
674
675/**
Simon Glass6116e762023-10-01 19:13:32 -0600676 * scene_textline() - create a textline
677 *
678 * @scn: Scene to update
679 * @name: Name to use (this is allocated by this call)
680 * @id: ID to use for the new object (0 to allocate one)
681 * @max_chars: Maximum length of the textline in characters
682 * @tlinep: If non-NULL, returns the new object
683 * Returns: ID number for the object (typically @id), or -ve on error
684 */
685int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
686 struct scene_obj_textline **tlinep);
687
688/**
Simon Glass138a3972025-05-02 08:46:44 -0600689 * scene_box() - create a box
690 *
691 * @scn: Scene to update
692 * @name: Name to use (this is allocated by this call)
693 * @id: ID to use for the new object (0 to allocate one)
694 * @width: Line-width in pixels
695 * @boxp: If non-NULL, returns the new object
696 * Returns: ID number for the object (typically @id), or -ve on error
697 */
698int scene_box(struct scene *scn, const char *name, uint id, uint width,
699 struct scene_obj_box **boxp);
700
701/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600702 * scene_txt_set_font() - Set the font for an object
703 *
704 * @scn: Scene to update
705 * @id: ID of object to update
706 * @font_name: Font name to use (allocated by caller)
707 * @font_size: Font size to use (nominal height in pixels)
708 */
709int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
710 uint font_size);
711
712/**
713 * scene_obj_set_pos() - Set the postion of an object
714 *
715 * @scn: Scene to update
716 * @id: ID of object to update
717 * @x: x position, in pixels from left side
718 * @y: y position, in pixels from top
719 * Returns: 0 if OK, -ENOENT if @id is invalid
720 */
721int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
722
723/**
Simon Glass7a960052023-06-01 10:22:52 -0600724 * scene_obj_set_size() - Set the size of an object
725 *
726 * @scn: Scene to update
727 * @id: ID of object to update
728 * @w: width in pixels
729 * @h: height in pixels
730 * Returns: 0 if OK, -ENOENT if @id is invalid
731 */
732int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
733
734/**
Simon Glassc6143dc2025-05-02 08:46:35 -0600735 * scene_obj_set_width() - Set the width of an object
736 *
737 * @scn: Scene to update
738 * @id: ID of object to update
739 * @w: width in pixels
740 * Returns: 0 if OK, -ENOENT if @id is invalid
741 */
742int scene_obj_set_width(struct scene *scn, uint id, int w);
743
744/**
745 * scene_obj_set_bbox() - Set the bounding box of an object
746 *
747 * @scn: Scene to update
748 * @id: ID of object to update
749 * @x0: x position, in pixels from left side
750 * @y0: y position, in pixels from top
751 * @x1: ending x position (right side)
752 * @y1: ending y position (botton side)
753 * Returns: 0 if OK, -ENOENT if @id is invalid
754 */
755int scene_obj_set_bbox(struct scene *scn, uint id, int x0, int y0, int x1,
756 int y1);
757
758/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600759 * scene_obj_set_hide() - Set whether an object is hidden
760 *
761 * The update happens when the expo is next rendered.
762 *
763 * @scn: Scene to update
764 * @id: ID of object to update
765 * @hide: true to hide the object, false to show it
766 * Returns: 0 if OK, -ENOENT if @id is invalid
767 */
768int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
769
770/**
771 * scene_menu_set_title() - Set the title of a menu
772 *
773 * @scn: Scene to update
774 * @id: ID of menu object to update
775 * @title_id: ID of text object to use as the title
776 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
777 */
778int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
779
780/**
781 * scene_menu_set_pointer() - Set the item pointer for a menu
782 *
783 * This is a visual indicator of the current item, typically a ">" character
784 * which sits next to the current item and moves when the user presses the
785 * up/down arrow keys
786 *
787 * @scn: Scene to update
788 * @id: ID of menu object to update
789 * @cur_item_id: ID of text or image object to use as a pointer to the current
790 * item
791 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
792 */
793int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
794
795/**
Simon Glassbe04b962025-05-02 08:46:24 -0600796 * scene_menu_select_item() - move the pointer/highlight to an item
797 *
798 * @scn: Scene to update
799 * @id: ID of menu object to update
800 * @sel_id: ID of the menuitem to select
801 * Return 0 on success, -ENOENT if there was no such item
802 */
803int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
804
805/**
806 * scene_menu_get_cur_item() - get the currently pointed-to item
807 *
808 * @scn: Scene to update
809 * @id: ID of menu object to update
810 * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
811 * valid, 0 if no item is pointed to
812 */
813int scene_menu_get_cur_item(struct scene *scn, uint id);
814
815/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600816 * scene_obj_get_hw() - Get width and height of an object in a scene
817 *
818 * @scn: Scene to check
819 * @id: ID of menu object to check
820 * @widthp: If non-NULL, returns width of object in pixels
821 * Returns: Height of object in pixels
822 */
823int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
824
825/**
826 * scene_menuitem() - Add an item to a menu
827 *
828 * @scn: Scene to update
829 * @menu_id: ID of menu object to update
830 * @name: Name to use (this is allocated by this call)
831 * @id: ID to use for the new object (0 to allocate one)
832 * @key_id: ID of text object to use as the keypress to show
833 * @label_id: ID of text object to use as the label text
834 * @desc_id: ID of text object to use as the description text
835 * @preview_id: ID of object to use as the preview (text or image)
836 * @flags: Flags for this item (enum scene_menuitem_flags_t)
837 * @itemp: If non-NULL, returns the new object
838 * Returns: ID number for the item (typically @id), or -ve on error
839 */
840int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
841 uint key_id, uint label_id, uint desc_id, uint preview_id,
842 uint flags, struct scene_menitem **itemp);
843
844/**
845 * scene_arrange() - Arrange the scene to deal with object sizes
846 *
847 * Updates any menus in the scene so that their objects are in the right place.
848 *
849 * @scn: Scene to arrange
850 * Returns: 0 if OK, -ve on error
851 */
852int scene_arrange(struct scene *scn);
853
854/**
855 * expo_send_key() - set a keypress to the expo
856 *
857 * @exp: Expo to receive the key
858 * @key: Key to send (ASCII or enum bootmenu_key)
859 * Returns: 0 if OK, -ECHILD if there is no current scene
860 */
861int expo_send_key(struct expo *exp, int key);
862
863/**
864 * expo_action_get() - read user input from the expo
865 *
866 * @exp: Expo to check
867 * @act: Returns action
868 * Returns: 0 if OK, -EAGAIN if there was no action to return
869 */
870int expo_action_get(struct expo *exp, struct expo_action *act);
871
Simon Glassc999e172023-06-01 10:22:53 -0600872/**
873 * expo_apply_theme() - Apply a theme to an expo
874 *
875 * @exp: Expo to update
876 * @node: Node containing the theme
877 */
878int expo_apply_theme(struct expo *exp, ofnode node);
879
Simon Glass61300722023-06-01 10:23:01 -0600880/**
881 * expo_build() - Build an expo from an FDT description
882 *
883 * Build a complete expo from a description in the provided devicetree.
884 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200885 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600886 *
887 * @root: Root node for expo description
888 * @expp: Returns the new expo
889 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
890 * error, -ENOENT if there is a references to a non-existent string
891 */
892int expo_build(ofnode root, struct expo **expp);
893
Simon Glass34344202024-10-14 16:32:11 -0600894/**
895 * cb_expo_build() - Build an expo for coreboot CMOS RAM
896 *
897 * @expp: Returns the expo created
898 * Return: 0 if OK, -ve on error
899 */
900int cb_expo_build(struct expo **expp);
901
Simon Glass137b4422025-05-02 08:46:16 -0600902/**
903 * expo_poll() - render an expo and see if the user takes an action
904 *
905 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
906 * is processed and the resulting action returned, if any
907 *
908 * @exp: Expo to poll
909 * @act: Returns action on success
910 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
911 * went wrong
912 */
913int expo_poll(struct expo *exp, struct expo_action *act);
914
Simon Glass8df4a4e2023-08-14 16:40:25 -0600915#endif /*__EXPO_H */