blob: 7c6ab4bf630641ac317df487c346aea703d3c0df [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 Glassebec4972025-05-02 08:46:33 -060012#include <linux/bitops.h>
Simon Glassd8adbe92023-01-06 08:52:36 -060013#include <linux/list.h>
14
15struct udevice;
16
Simon Glassa968f5f2023-10-01 19:13:31 -060017#include <cli.h>
18
Simon Glassd8adbe92023-01-06 08:52:36 -060019/**
Simon Glass53a0a2f2024-10-14 16:31:57 -060020 * enum expo_id_t - standard expo IDs
21 *
22 * These are assumed to be in use at all times. Expos should use IDs starting
23 * from EXPOID_BASE_ID,
24 *
25 * @EXPOID_NONE: Not used, invalid ID 0
26 * @EXPOID_SAVE: User has requested that the expo data be saved
27 * @EXPOID_DISCARD: User has requested that the expo data be discarded
28 * @EXPOID_BASE_ID: First ID which can be used for expo objects
29 */
30enum expo_id_t {
31 EXPOID_NONE,
32
33 EXPOID_SAVE,
34 EXPOID_DISCARD,
35
36 EXPOID_BASE_ID = 5,
37};
38
39/**
Simon Glassd8adbe92023-01-06 08:52:36 -060040 * enum expoact_type - types of actions reported by the expo
41 *
42 * @EXPOACT_NONE: no action
Simon Glassf0e1e8c2023-06-01 10:22:59 -060043 * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which)
Simon Glass719a3c62023-06-01 10:22:56 -060044 * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
Simon Glassd8adbe92023-01-06 08:52:36 -060045 * @EXPOACT_SELECT: menu item was selected (@id indicates which)
Simon Glassf0e1e8c2023-06-01 10:22:59 -060046 * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates
47 * which menu object)
48 * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object)
Simon Glassd8adbe92023-01-06 08:52:36 -060049 * @EXPOACT_QUIT: request to exit the menu
50 */
51enum expoact_type {
52 EXPOACT_NONE,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060053 EXPOACT_POINT_OBJ,
Simon Glass719a3c62023-06-01 10:22:56 -060054 EXPOACT_POINT_ITEM,
Simon Glassd8adbe92023-01-06 08:52:36 -060055 EXPOACT_SELECT,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060056 EXPOACT_OPEN,
57 EXPOACT_CLOSE,
Simon Glassd8adbe92023-01-06 08:52:36 -060058 EXPOACT_QUIT,
59};
60
61/**
62 * struct expo_action - an action report by the expo
63 *
64 * @type: Action type (EXPOACT_NONE if there is no action)
Simon Glass719a3c62023-06-01 10:22:56 -060065 * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT
Heinrich Schuchardta99e8fe2024-09-18 23:58:03 +020066 * @select.id: ID number of the object affected.
Simon Glassd8adbe92023-01-06 08:52:36 -060067 */
68struct expo_action {
69 enum expoact_type type;
70 union {
71 struct {
72 int id;
73 } select;
74 };
75};
76
77/**
Simon Glassc999e172023-06-01 10:22:53 -060078 * struct expo_theme - theme for the expo
79 *
80 * @font_size: Default font size for all text
81 * @menu_inset: Inset width (on each side and top/bottom) for menu items
82 * @menuitem_gap_y: Gap between menu items in pixels
Simon Glass377f18e2024-10-14 16:31:55 -060083 * @menu_title_margin_x: Gap between right side of menu title and left size of
84 * menu label
Simon Glassc999e172023-06-01 10:22:53 -060085 */
86struct expo_theme {
87 u32 font_size;
88 u32 menu_inset;
89 u32 menuitem_gap_y;
Simon Glass377f18e2024-10-14 16:31:55 -060090 u32 menu_title_margin_x;
Simon Glassc999e172023-06-01 10:22:53 -060091};
92
93/**
Simon Glassd8adbe92023-01-06 08:52:36 -060094 * struct expo - information about an expo
95 *
96 * A group of scenes which can be presented to the user, typically to obtain
97 * input or to make a selection.
98 *
99 * @name: Name of the expo (allocated)
100 * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
Simon Glass67e2af12023-06-01 10:22:34 -0600101 * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600102 * @scene_id: Current scene ID (0 if none)
103 * @next_id: Next ID number to use, for automatic allocation
104 * @action: Action selected by user. At present only one is supported, with the
105 * type set to EXPOACT_NONE if there is no action
106 * @text_mode: true to use text mode for the menu (no vidconsole)
Simon Glassd353b752023-06-01 10:22:55 -0600107 * @popup: true to use popup menus, instead of showing all items
Simon Glassd8adbe92023-01-06 08:52:36 -0600108 * @priv: Private data for the controller
Simon Glass527d8642025-05-02 08:46:20 -0600109 * @done: Indicates that a cedit session is complete and the user has quit
110 * @save: Indicates that cedit data should be saved, rather than discarded
Simon Glassc999e172023-06-01 10:22:53 -0600111 * @theme: Information about fonts styles, etc.
Simon Glassd8adbe92023-01-06 08:52:36 -0600112 * @scene_head: List of scenes
113 * @str_head: list of strings
Simon Glass683d8832025-05-02 08:46:15 -0600114 * @cch: Keyboard context for input
Simon Glassd8adbe92023-01-06 08:52:36 -0600115 */
116struct expo {
117 char *name;
118 struct udevice *display;
Simon Glass67e2af12023-06-01 10:22:34 -0600119 struct udevice *cons;
Simon Glassd8adbe92023-01-06 08:52:36 -0600120 uint scene_id;
121 uint next_id;
122 struct expo_action action;
123 bool text_mode;
Simon Glassd353b752023-06-01 10:22:55 -0600124 bool popup;
Simon Glassd8adbe92023-01-06 08:52:36 -0600125 void *priv;
Simon Glass527d8642025-05-02 08:46:20 -0600126 bool done;
127 bool save;
Simon Glassc999e172023-06-01 10:22:53 -0600128 struct expo_theme theme;
Simon Glassd8adbe92023-01-06 08:52:36 -0600129 struct list_head scene_head;
130 struct list_head str_head;
Simon Glass683d8832025-05-02 08:46:15 -0600131 struct cli_ch_state cch;
Simon Glassd8adbe92023-01-06 08:52:36 -0600132};
133
134/**
135 * struct expo_string - a string that can be used in an expo
136 *
137 * @id: ID number of the string
Simon Glassda337752025-05-02 08:46:32 -0600138 * @buf: String (contains nul terminator)
Simon Glassd8adbe92023-01-06 08:52:36 -0600139 * @sibling: Node to link this object to its siblings
140 */
141struct expo_string {
142 uint id;
Simon Glassda337752025-05-02 08:46:32 -0600143 struct abuf buf;
Simon Glassd8adbe92023-01-06 08:52:36 -0600144 struct list_head sibling;
145};
146
147/**
148 * struct scene - information about a scene in an expo
149 *
150 * A collection of text/image/menu items in an expo
151 *
152 * @expo: Expo this scene is part of
153 * @name: Name of the scene (allocated)
154 * @id: ID number of the scene
Simon Glassea274b62023-06-01 10:22:27 -0600155 * @title_id: String ID of title of the scene (allocated)
Simon Glassd353b752023-06-01 10:22:55 -0600156 * @highlight_id: ID of highlighted object, if any
Simon Glassa968f5f2023-10-01 19:13:31 -0600157 * @cls: cread state to use for input
158 * @buf: Buffer for input
159 * @entry_save: Buffer to hold vidconsole text-entry information
Simon Glassd8adbe92023-01-06 08:52:36 -0600160 * @sibling: Node to link this scene to its siblings
161 * @obj_head: List of objects in the scene
162 */
163struct scene {
164 struct expo *expo;
165 char *name;
166 uint id;
Simon Glassea274b62023-06-01 10:22:27 -0600167 uint title_id;
Simon Glassd353b752023-06-01 10:22:55 -0600168 uint highlight_id;
Simon Glassa968f5f2023-10-01 19:13:31 -0600169 struct cli_line_state cls;
170 struct abuf buf;
171 struct abuf entry_save;
Simon Glassd8adbe92023-01-06 08:52:36 -0600172 struct list_head sibling;
173 struct list_head obj_head;
174};
175
176/**
177 * enum scene_obj_t - type of a scene object
178 *
179 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
180 * @SCENEOBJT_IMAGE: Image data to render
181 * @SCENEOBJT_TEXT: Text line to render
182 * @SCENEOBJT_MENU: Menu containing items the user can select
Simon Glass6116e762023-10-01 19:13:32 -0600183 * @SCENEOBJT_TEXTLINE: Line of text the user can edit
Simon Glassd8adbe92023-01-06 08:52:36 -0600184 */
185enum scene_obj_t {
186 SCENEOBJT_NONE = 0,
187 SCENEOBJT_IMAGE,
188 SCENEOBJT_TEXT,
Simon Glass193bfea2023-10-01 19:13:27 -0600189
190 /* types from here on can be highlighted */
Simon Glassd8adbe92023-01-06 08:52:36 -0600191 SCENEOBJT_MENU,
Simon Glass6116e762023-10-01 19:13:32 -0600192 SCENEOBJT_TEXTLINE,
Simon Glassd8adbe92023-01-06 08:52:36 -0600193};
194
195/**
Simon Glass854ca692025-05-02 08:46:30 -0600196 * struct scene_obj_bbox - Dimensions of an object
Simon Glass7b043952023-06-01 10:22:49 -0600197 *
Simon Glassbc3a15f2025-05-02 08:46:31 -0600198 * @x0: x position, in pixels from left side
199 * @y0: y position, in pixels from top
Simon Glassebec4972025-05-02 08:46:33 -0600200 * @x1: x position of right size
201 * @y1: y position of bottom
Simon Glass7b043952023-06-01 10:22:49 -0600202 */
Simon Glass854ca692025-05-02 08:46:30 -0600203struct scene_obj_bbox {
Simon Glassbc3a15f2025-05-02 08:46:31 -0600204 int x0;
205 int y0;
Simon Glassebec4972025-05-02 08:46:33 -0600206 int x1;
207 int y1;
Simon Glass7b043952023-06-01 10:22:49 -0600208};
209
210/**
Simon Glassebec4972025-05-02 08:46:33 -0600211 * struct scene_obj_dims - Dimensions of the object being drawn
212 *
213 * Image and text objects have a dimension which can change depending on what
214 * they contain. For images this stores the size. For text it stores the size as
215 * rendered on the display
216 *
217 * @x: x dimension
218 * @y: y dimension
219 */
220struct scene_obj_dims {
221 int x;
222 int y;
223};
224
225/**
Simon Glass6081b0f2023-06-01 10:22:50 -0600226 * enum scene_obj_flags_t - flags for objects
227 *
228 * @SCENEOF_HIDE: object should be hidden
Simon Glassd353b752023-06-01 10:22:55 -0600229 * @SCENEOF_POINT: object should be highlighted
230 * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
231 * can be selected)
Simon Glassebec4972025-05-02 08:46:33 -0600232 * @SCENEOF_SIZE_VALID: object's size (width/height) is valid, so any adjustment
233 * to x0/y0 should maintain the width/height of the object
Simon Glass6081b0f2023-06-01 10:22:50 -0600234 */
235enum scene_obj_flags_t {
236 SCENEOF_HIDE = 1 << 0,
Simon Glassd353b752023-06-01 10:22:55 -0600237 SCENEOF_POINT = 1 << 1,
238 SCENEOF_OPEN = 1 << 2,
Simon Glassebec4972025-05-02 08:46:33 -0600239 SCENEOF_SIZE_VALID = BIT(3),
Simon Glass6081b0f2023-06-01 10:22:50 -0600240};
241
Simon Glassa968f5f2023-10-01 19:13:31 -0600242enum {
243 /* Maximum number of characters allowed in an line editor */
244 EXPO_MAX_CHARS = 250,
245};
246
Simon Glass6081b0f2023-06-01 10:22:50 -0600247/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600248 * struct scene_obj - information about an object in a scene
249 *
250 * @scene: Scene that this object relates to
251 * @name: Name of the object (allocated)
252 * @id: ID number of the object
253 * @type: Type of this object
Simon Glassebec4972025-05-02 08:46:33 -0600254 * @bbox: Bounding box for this object
255 * @dims: Dimensions of the text/image (may be smaller than bbox)
Simon Glass6081b0f2023-06-01 10:22:50 -0600256 * @flags: Flags for this object
Simon Glass2b91ca62023-08-14 16:40:37 -0600257 * @bit_length: Number of bits used for this object in CMOS RAM
258 * @start_bit: Start bit to use for this object in CMOS RAM
Simon Glassd8adbe92023-01-06 08:52:36 -0600259 * @sibling: Node to link this object to its siblings
260 */
261struct scene_obj {
262 struct scene *scene;
263 char *name;
264 uint id;
265 enum scene_obj_t type;
Simon Glass854ca692025-05-02 08:46:30 -0600266 struct scene_obj_bbox bbox;
Simon Glassebec4972025-05-02 08:46:33 -0600267 struct scene_obj_dims dims;
Simon Glass2b91ca62023-08-14 16:40:37 -0600268 u8 flags;
269 u8 bit_length;
270 u16 start_bit;
Simon Glassd8adbe92023-01-06 08:52:36 -0600271 struct list_head sibling;
272};
273
Simon Glass193bfea2023-10-01 19:13:27 -0600274/* object can be highlighted when moving around expo */
275static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
276{
277 return obj->type >= SCENEOBJT_MENU;
278}
279
Simon Glassd8adbe92023-01-06 08:52:36 -0600280/**
281 * struct scene_obj_img - information about an image object in a scene
282 *
283 * This is a rectangular image which is blitted onto the display
284 *
285 * @obj: Basic object information
286 * @data: Image data in BMP format
287 */
288struct scene_obj_img {
289 struct scene_obj obj;
290 char *data;
291};
292
293/**
Simon Glass9ef02aa2025-05-02 08:46:37 -0600294 * struct scene_txt_generic - Generic information common to text objects
Simon Glassd8adbe92023-01-06 08:52:36 -0600295 *
Simon Glassd8adbe92023-01-06 08:52:36 -0600296 * @str_id: ID of the text string to display
297 * @font_name: Name of font (allocated by caller)
298 * @font_size: Nominal size of font in pixels
299 */
Simon Glass9ef02aa2025-05-02 08:46:37 -0600300struct scene_txt_generic {
Simon Glassd8adbe92023-01-06 08:52:36 -0600301 uint str_id;
302 const char *font_name;
303 uint font_size;
304};
305
306/**
Simon Glass9ef02aa2025-05-02 08:46:37 -0600307 * struct scene_obj_txt - information about a text object in a scene
308 *
309 * This is a single-line text object
310 *
311 * @obj: Basic object information
312 * @gen: Generic information common to all objects which show text
313 */
314struct scene_obj_txt {
315 struct scene_obj obj;
316 struct scene_txt_generic gen;
317};
318
319/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600320 * struct scene_obj_menu - information about a menu object in a scene
321 *
322 * A menu has a number of items which can be selected by the user
323 *
324 * It also has:
325 *
326 * - a text/image object (@pointer_id) which points to the current item
327 * (@cur_item_id)
328 *
329 * - a preview object which shows an image related to the current item
330 *
331 * @obj: Basic object information
332 * @title_id: ID of the title text, or 0 if none
333 * @cur_item_id: ID of the current menu item, or 0 if none
334 * @pointer_id: ID of the object pointing to the current selection
335 * @item_head: List of items in the menu
336 */
337struct scene_obj_menu {
338 struct scene_obj obj;
339 uint title_id;
340 uint cur_item_id;
341 uint pointer_id;
342 struct list_head item_head;
343};
344
345/**
346 * enum scene_menuitem_flags_t - flags for menu items
347 *
348 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
349 */
350enum scene_menuitem_flags_t {
351 SCENEMIF_GAP_BEFORE = 1 << 0,
352};
353
354/**
355 * struct scene_menitem - a menu item in a menu
356 *
357 * A menu item has:
358 *
359 * - text object holding the name (short) and description (can be longer)
360 * - a text object holding the keypress
361 *
362 * @name: Name of the item (this is allocated by this call)
363 * @id: ID number of the object
364 * @key_id: ID of text object to use as the keypress to show
365 * @label_id: ID of text object to use as the label text
366 * @desc_id: ID of text object to use as the description text
367 * @preview_id: ID of the preview object, or 0 if none
368 * @flags: Flags for this item
Simon Glass100389f2024-10-14 16:31:58 -0600369 * @value: Value for this item, or INT_MAX to use sequence
Simon Glassd8adbe92023-01-06 08:52:36 -0600370 * @sibling: Node to link this item to its siblings
371 */
372struct scene_menitem {
373 char *name;
374 uint id;
375 uint key_id;
376 uint label_id;
377 uint desc_id;
378 uint preview_id;
379 uint flags;
Simon Glass100389f2024-10-14 16:31:58 -0600380 int value;
Simon Glassd8adbe92023-01-06 08:52:36 -0600381 struct list_head sibling;
382};
383
384/**
Simon Glass6116e762023-10-01 19:13:32 -0600385 * struct scene_obj_textline - information about a textline in a scene
386 *
387 * A textline has a prompt and a line of editable text
388 *
389 * @obj: Basic object information
390 * @label_id: ID of the label text, or 0 if none
391 * @edit_id: ID of the editable text
392 * @max_chars: Maximum number of characters allowed
393 * @buf: Text buffer containing current text
394 * @pos: Cursor position
395 */
396struct scene_obj_textline {
397 struct scene_obj obj;
398 uint label_id;
399 uint edit_id;
400 uint max_chars;
401 struct abuf buf;
402 uint pos;
403};
404
405/**
Simon Glass377f18e2024-10-14 16:31:55 -0600406 * struct expo_arrange_info - Information used when arranging a scene
407 *
408 * @label_width: Maximum width of labels in scene
409 */
410struct expo_arrange_info {
411 int label_width;
412};
413
414/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600415 * expo_new() - create a new expo
416 *
417 * Allocates a new expo
418 *
419 * @name: Name of expo (this is allocated by this call)
420 * @priv: Private data for the controller
421 * @expp: Returns a pointer to the new expo on success
422 * Returns: 0 if OK, -ENOMEM if out of memory
423 */
424int expo_new(const char *name, void *priv, struct expo **expp);
425
426/**
427 * expo_destroy() - Destroy an expo and free all its memory
428 *
429 * @exp: Expo to destroy
430 */
431void expo_destroy(struct expo *exp);
432
433/**
Simon Glass6e9e4152023-06-01 10:22:47 -0600434 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
435 *
436 * It is common for a set of 'static' IDs to be used to refer to objects in the
437 * expo. These typically use an enum so that they are defined in sequential
438 * order.
439 *
440 * Dynamic IDs (for objects not in the enum) are intended to be used for
441 * objects to which the code does not need to refer. These are ideally located
442 * above the static IDs.
443 *
444 * Use this function to set the start of the dynamic range, making sure that the
445 * value is higher than all the statically allocated IDs.
446 *
447 * @exp: Expo to update
448 * @dyn_start: Start ID that expo should use for dynamic allocation
449 */
450void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
451
452/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600453 * expo_str() - add a new string to an expo
454 *
455 * @exp: Expo to update
456 * @name: Name to use (this is allocated by this call)
457 * @id: ID to use for the new object (0 to allocate one)
458 * @str: Pointer to text to display (allocated by caller)
459 * Returns: ID number for the object (typically @id), or -ve on error
460 */
461int expo_str(struct expo *exp, const char *name, uint id, const char *str);
462
463/**
464 * expo_get_str() - Get a string by ID
465 *
466 * @exp: Expo to use
467 * @id: String ID to look up
468 * @returns string, or NULL if not found
469 */
470const char *expo_get_str(struct expo *exp, uint id);
471
472/**
Simon Glassc5ae5b12025-05-02 08:46:40 -0600473 * expo_edit_str() - Make a string writeable
474 *
475 * This allows a string to be updated under the control of the caller. The
476 * buffer must remain valid while the expo is active.
477 *
478 * @exp: Expo to use
479 * @id: String ID to look up
480 * @orig: If non-NULL, returns the original buffer, which can be used by the
481 * caller. It is no-longer used by expo so must be uninited by the caller.
482 * It contains a snapshot of the string contents
483 * @copyp: Returns a pointer to the new, writeable buffer
484 * Return: 0 if OK, -ENOENT if the id was not found, -ENOMEM if out of memory
485 */
486int expo_edit_str(struct expo *exp, uint id, struct abuf *orig,
487 struct abuf **copyp);
488
489/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600490 * expo_set_display() - set the display to use for a expo
491 *
492 * @exp: Expo to update
493 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
494 * Returns: 0 (always)
495 */
496int expo_set_display(struct expo *exp, struct udevice *dev);
497
498/**
Simon Glass7a960052023-06-01 10:22:52 -0600499 * expo_calc_dims() - Calculate the dimensions of the objects
500 *
501 * Updates the width and height of all objects based on their contents
502 *
503 * @exp: Expo to update
504 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
505 */
506int expo_calc_dims(struct expo *exp);
507
508/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600509 * expo_set_scene_id() - Set the current scene ID
510 *
511 * @exp: Expo to update
512 * @scene_id: New scene ID to use (0 to select no scene)
513 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
514 */
515int expo_set_scene_id(struct expo *exp, uint scene_id);
516
517/**
Simon Glassc8925112023-06-01 10:23:02 -0600518 * expo_first_scene_id() - Get the ID of the first scene
519 *
520 * @exp: Expo to check
521 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
522 */
523int expo_first_scene_id(struct expo *exp);
524
525/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600526 * expo_render() - render the expo on the display / console
527 *
528 * @exp: Expo to render
529 *
530 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
531 * current scene is not found, other error if something else goes wrong
532 */
533int expo_render(struct expo *exp);
534
535/**
Simon Glassb2c40342023-06-01 10:22:37 -0600536 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600537 *
538 * @exp: Expo to update
539 * @text_mode: true to use text mode, false to use the console
540 */
Simon Glassb2c40342023-06-01 10:22:37 -0600541void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600542
543/**
544 * scene_new() - create a new scene in a expo
545 *
546 * The scene is given the ID @id which must be unique across all scenes, objects
547 * and items. The expo's @next_id is updated to at least @id + 1
548 *
549 * @exp: Expo to update
550 * @name: Name to use (this is allocated by this call)
551 * @id: ID to use for the new scene (0 to allocate one)
552 * @scnp: Returns a pointer to the new scene on success
553 * Returns: ID number for the scene (typically @id), or -ve on error
554 */
555int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
556
557/**
558 * expo_lookup_scene_id() - Look up a scene by ID
559 *
560 * @exp: Expo to check
561 * @scene_id: Scene ID to look up
562 * @returns pointer to scene if found, else NULL
563 */
564struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
565
566/**
Simon Glass01922ec2023-06-01 10:22:57 -0600567 * scene_highlight_first() - Highlight the first item in a scene
568 *
569 * This highlights the first item, so that the user can see that it is pointed
570 * to
571 *
572 * @scn: Scene to update
573 */
574void scene_highlight_first(struct scene *scn);
575
576/**
577 * scene_set_highlight_id() - Set the object which is highlighted
578 *
579 * Sets a new object to highlight in the scene
580 *
581 * @scn: Scene to update
582 * @id: ID of object to highlight
583 */
584void scene_set_highlight_id(struct scene *scn, uint id);
585
586/**
587 * scene_set_open() - Set whether an item is open or not
588 *
589 * @scn: Scene to update
590 * @id: ID of object to update
591 * @open: true to open the object, false to close it
592 * Returns: 0 if OK, -ENOENT if @id is invalid
593 */
594int scene_set_open(struct scene *scn, uint id, bool open);
595
596/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600597 * scene_obj_count() - Count the number of objects in a scene
598 *
599 * @scn: Scene to check
600 * Returns: number of objects in the scene, 0 if none
601 */
602int scene_obj_count(struct scene *scn);
603
604/**
605 * scene_img() - add a new image to a scene
606 *
607 * @scn: Scene to update
608 * @name: Name to use (this is allocated by this call)
609 * @id: ID to use for the new object (0 to allocate one)
610 * @data: Pointer to image data
611 * @imgp: If non-NULL, returns the new object
612 * Returns: ID number for the object (typically @id), or -ve on error
613 */
614int scene_img(struct scene *scn, const char *name, uint id, char *data,
615 struct scene_obj_img **imgp);
616
617/**
618 * scene_txt() - add a new text object to a scene
619 *
620 * @scn: Scene to update
621 * @name: Name to use (this is allocated by this call)
622 * @id: ID to use for the new object (0 to allocate one)
623 * @str_id: ID of the string to use
624 * @txtp: If non-NULL, returns the new object
625 * Returns: ID number for the object (typically @id), or -ve on error
626 */
627int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
628 struct scene_obj_txt **txtp);
629
630/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600631 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600632 *
633 * @scn: Scene to update
634 * @name: Name to use (this is allocated by this call)
635 * @id: ID to use for the new object (0 to allocate one)
636 * @str_id: ID of the string to use
637 * @str: Pointer to text to display (allocated by caller)
638 * @txtp: If non-NULL, returns the new object
639 * Returns: ID number for the object (typically @id), or -ve on error
640 */
641int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
642 const char *str, struct scene_obj_txt **txtp);
643
644/**
645 * scene_menu() - create a menu
646 *
647 * @scn: Scene to update
648 * @name: Name to use (this is allocated by this call)
649 * @id: ID to use for the new object (0 to allocate one)
650 * @menup: If non-NULL, returns the new object
651 * Returns: ID number for the object (typically @id), or -ve on error
652 */
653int scene_menu(struct scene *scn, const char *name, uint id,
654 struct scene_obj_menu **menup);
655
656/**
Simon Glass6116e762023-10-01 19:13:32 -0600657 * scene_textline() - create a textline
658 *
659 * @scn: Scene to update
660 * @name: Name to use (this is allocated by this call)
661 * @id: ID to use for the new object (0 to allocate one)
662 * @max_chars: Maximum length of the textline in characters
663 * @tlinep: If non-NULL, returns the new object
664 * Returns: ID number for the object (typically @id), or -ve on error
665 */
666int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
667 struct scene_obj_textline **tlinep);
668
669/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600670 * scene_txt_set_font() - Set the font for an object
671 *
672 * @scn: Scene to update
673 * @id: ID of object to update
674 * @font_name: Font name to use (allocated by caller)
675 * @font_size: Font size to use (nominal height in pixels)
676 */
677int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
678 uint font_size);
679
680/**
681 * scene_obj_set_pos() - Set the postion of an object
682 *
683 * @scn: Scene to update
684 * @id: ID of object to update
685 * @x: x position, in pixels from left side
686 * @y: y position, in pixels from top
687 * Returns: 0 if OK, -ENOENT if @id is invalid
688 */
689int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
690
691/**
Simon Glass7a960052023-06-01 10:22:52 -0600692 * scene_obj_set_size() - Set the size of an object
693 *
694 * @scn: Scene to update
695 * @id: ID of object to update
696 * @w: width in pixels
697 * @h: height in pixels
698 * Returns: 0 if OK, -ENOENT if @id is invalid
699 */
700int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
701
702/**
Simon Glassc6143dc2025-05-02 08:46:35 -0600703 * scene_obj_set_width() - Set the width of an object
704 *
705 * @scn: Scene to update
706 * @id: ID of object to update
707 * @w: width in pixels
708 * Returns: 0 if OK, -ENOENT if @id is invalid
709 */
710int scene_obj_set_width(struct scene *scn, uint id, int w);
711
712/**
713 * scene_obj_set_bbox() - Set the bounding box of an object
714 *
715 * @scn: Scene to update
716 * @id: ID of object to update
717 * @x0: x position, in pixels from left side
718 * @y0: y position, in pixels from top
719 * @x1: ending x position (right side)
720 * @y1: ending y position (botton side)
721 * Returns: 0 if OK, -ENOENT if @id is invalid
722 */
723int scene_obj_set_bbox(struct scene *scn, uint id, int x0, int y0, int x1,
724 int y1);
725
726/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600727 * scene_obj_set_hide() - Set whether an object is hidden
728 *
729 * The update happens when the expo is next rendered.
730 *
731 * @scn: Scene to update
732 * @id: ID of object to update
733 * @hide: true to hide the object, false to show it
734 * Returns: 0 if OK, -ENOENT if @id is invalid
735 */
736int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
737
738/**
739 * scene_menu_set_title() - Set the title of a menu
740 *
741 * @scn: Scene to update
742 * @id: ID of menu object to update
743 * @title_id: ID of text object to use as the title
744 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
745 */
746int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
747
748/**
749 * scene_menu_set_pointer() - Set the item pointer for a menu
750 *
751 * This is a visual indicator of the current item, typically a ">" character
752 * which sits next to the current item and moves when the user presses the
753 * up/down arrow keys
754 *
755 * @scn: Scene to update
756 * @id: ID of menu object to update
757 * @cur_item_id: ID of text or image object to use as a pointer to the current
758 * item
759 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
760 */
761int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
762
763/**
Simon Glassbe04b962025-05-02 08:46:24 -0600764 * scene_menu_select_item() - move the pointer/highlight to an item
765 *
766 * @scn: Scene to update
767 * @id: ID of menu object to update
768 * @sel_id: ID of the menuitem to select
769 * Return 0 on success, -ENOENT if there was no such item
770 */
771int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
772
773/**
774 * scene_menu_get_cur_item() - get the currently pointed-to item
775 *
776 * @scn: Scene to update
777 * @id: ID of menu object to update
778 * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
779 * valid, 0 if no item is pointed to
780 */
781int scene_menu_get_cur_item(struct scene *scn, uint id);
782
783/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600784 * scene_obj_get_hw() - Get width and height of an object in a scene
785 *
786 * @scn: Scene to check
787 * @id: ID of menu object to check
788 * @widthp: If non-NULL, returns width of object in pixels
789 * Returns: Height of object in pixels
790 */
791int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
792
793/**
794 * scene_menuitem() - Add an item to a menu
795 *
796 * @scn: Scene to update
797 * @menu_id: ID of menu object to update
798 * @name: Name to use (this is allocated by this call)
799 * @id: ID to use for the new object (0 to allocate one)
800 * @key_id: ID of text object to use as the keypress to show
801 * @label_id: ID of text object to use as the label text
802 * @desc_id: ID of text object to use as the description text
803 * @preview_id: ID of object to use as the preview (text or image)
804 * @flags: Flags for this item (enum scene_menuitem_flags_t)
805 * @itemp: If non-NULL, returns the new object
806 * Returns: ID number for the item (typically @id), or -ve on error
807 */
808int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
809 uint key_id, uint label_id, uint desc_id, uint preview_id,
810 uint flags, struct scene_menitem **itemp);
811
812/**
813 * scene_arrange() - Arrange the scene to deal with object sizes
814 *
815 * Updates any menus in the scene so that their objects are in the right place.
816 *
817 * @scn: Scene to arrange
818 * Returns: 0 if OK, -ve on error
819 */
820int scene_arrange(struct scene *scn);
821
822/**
823 * expo_send_key() - set a keypress to the expo
824 *
825 * @exp: Expo to receive the key
826 * @key: Key to send (ASCII or enum bootmenu_key)
827 * Returns: 0 if OK, -ECHILD if there is no current scene
828 */
829int expo_send_key(struct expo *exp, int key);
830
831/**
832 * expo_action_get() - read user input from the expo
833 *
834 * @exp: Expo to check
835 * @act: Returns action
836 * Returns: 0 if OK, -EAGAIN if there was no action to return
837 */
838int expo_action_get(struct expo *exp, struct expo_action *act);
839
Simon Glassc999e172023-06-01 10:22:53 -0600840/**
841 * expo_apply_theme() - Apply a theme to an expo
842 *
843 * @exp: Expo to update
844 * @node: Node containing the theme
845 */
846int expo_apply_theme(struct expo *exp, ofnode node);
847
Simon Glass61300722023-06-01 10:23:01 -0600848/**
849 * expo_build() - Build an expo from an FDT description
850 *
851 * Build a complete expo from a description in the provided devicetree.
852 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200853 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600854 *
855 * @root: Root node for expo description
856 * @expp: Returns the new expo
857 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
858 * error, -ENOENT if there is a references to a non-existent string
859 */
860int expo_build(ofnode root, struct expo **expp);
861
Simon Glass34344202024-10-14 16:32:11 -0600862/**
863 * cb_expo_build() - Build an expo for coreboot CMOS RAM
864 *
865 * @expp: Returns the expo created
866 * Return: 0 if OK, -ve on error
867 */
868int cb_expo_build(struct expo **expp);
869
Simon Glass137b4422025-05-02 08:46:16 -0600870/**
871 * expo_poll() - render an expo and see if the user takes an action
872 *
873 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
874 * is processed and the resulting action returned, if any
875 *
876 * @exp: Expo to poll
877 * @act: Returns action on success
878 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
879 * went wrong
880 */
881int expo_poll(struct expo *exp, struct expo_action *act);
882
Simon Glass8df4a4e2023-08-14 16:40:25 -0600883#endif /*__EXPO_H */