blob: 32d69f269a7445f70c5a4c047b1a8071b46e77f8 [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/**
473 * expo_set_display() - set the display to use for a expo
474 *
475 * @exp: Expo to update
476 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
477 * Returns: 0 (always)
478 */
479int expo_set_display(struct expo *exp, struct udevice *dev);
480
481/**
Simon Glass7a960052023-06-01 10:22:52 -0600482 * expo_calc_dims() - Calculate the dimensions of the objects
483 *
484 * Updates the width and height of all objects based on their contents
485 *
486 * @exp: Expo to update
487 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
488 */
489int expo_calc_dims(struct expo *exp);
490
491/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600492 * expo_set_scene_id() - Set the current scene ID
493 *
494 * @exp: Expo to update
495 * @scene_id: New scene ID to use (0 to select no scene)
496 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
497 */
498int expo_set_scene_id(struct expo *exp, uint scene_id);
499
500/**
Simon Glassc8925112023-06-01 10:23:02 -0600501 * expo_first_scene_id() - Get the ID of the first scene
502 *
503 * @exp: Expo to check
504 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
505 */
506int expo_first_scene_id(struct expo *exp);
507
508/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600509 * expo_render() - render the expo on the display / console
510 *
511 * @exp: Expo to render
512 *
513 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
514 * current scene is not found, other error if something else goes wrong
515 */
516int expo_render(struct expo *exp);
517
518/**
Simon Glassb2c40342023-06-01 10:22:37 -0600519 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600520 *
521 * @exp: Expo to update
522 * @text_mode: true to use text mode, false to use the console
523 */
Simon Glassb2c40342023-06-01 10:22:37 -0600524void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600525
526/**
527 * scene_new() - create a new scene in a expo
528 *
529 * The scene is given the ID @id which must be unique across all scenes, objects
530 * and items. The expo's @next_id is updated to at least @id + 1
531 *
532 * @exp: Expo to update
533 * @name: Name to use (this is allocated by this call)
534 * @id: ID to use for the new scene (0 to allocate one)
535 * @scnp: Returns a pointer to the new scene on success
536 * Returns: ID number for the scene (typically @id), or -ve on error
537 */
538int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
539
540/**
541 * expo_lookup_scene_id() - Look up a scene by ID
542 *
543 * @exp: Expo to check
544 * @scene_id: Scene ID to look up
545 * @returns pointer to scene if found, else NULL
546 */
547struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
548
549/**
Simon Glass01922ec2023-06-01 10:22:57 -0600550 * scene_highlight_first() - Highlight the first item in a scene
551 *
552 * This highlights the first item, so that the user can see that it is pointed
553 * to
554 *
555 * @scn: Scene to update
556 */
557void scene_highlight_first(struct scene *scn);
558
559/**
560 * scene_set_highlight_id() - Set the object which is highlighted
561 *
562 * Sets a new object to highlight in the scene
563 *
564 * @scn: Scene to update
565 * @id: ID of object to highlight
566 */
567void scene_set_highlight_id(struct scene *scn, uint id);
568
569/**
570 * scene_set_open() - Set whether an item is open or not
571 *
572 * @scn: Scene to update
573 * @id: ID of object to update
574 * @open: true to open the object, false to close it
575 * Returns: 0 if OK, -ENOENT if @id is invalid
576 */
577int scene_set_open(struct scene *scn, uint id, bool open);
578
579/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600580 * scene_obj_count() - Count the number of objects in a scene
581 *
582 * @scn: Scene to check
583 * Returns: number of objects in the scene, 0 if none
584 */
585int scene_obj_count(struct scene *scn);
586
587/**
588 * scene_img() - add a new image to a scene
589 *
590 * @scn: Scene to update
591 * @name: Name to use (this is allocated by this call)
592 * @id: ID to use for the new object (0 to allocate one)
593 * @data: Pointer to image data
594 * @imgp: If non-NULL, returns the new object
595 * Returns: ID number for the object (typically @id), or -ve on error
596 */
597int scene_img(struct scene *scn, const char *name, uint id, char *data,
598 struct scene_obj_img **imgp);
599
600/**
601 * scene_txt() - add a new text object to a scene
602 *
603 * @scn: Scene to update
604 * @name: Name to use (this is allocated by this call)
605 * @id: ID to use for the new object (0 to allocate one)
606 * @str_id: ID of the string to use
607 * @txtp: If non-NULL, returns the new object
608 * Returns: ID number for the object (typically @id), or -ve on error
609 */
610int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
611 struct scene_obj_txt **txtp);
612
613/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600614 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600615 *
616 * @scn: Scene to update
617 * @name: Name to use (this is allocated by this call)
618 * @id: ID to use for the new object (0 to allocate one)
619 * @str_id: ID of the string to use
620 * @str: Pointer to text to display (allocated by caller)
621 * @txtp: If non-NULL, returns the new object
622 * Returns: ID number for the object (typically @id), or -ve on error
623 */
624int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
625 const char *str, struct scene_obj_txt **txtp);
626
627/**
628 * scene_menu() - create a menu
629 *
630 * @scn: Scene to update
631 * @name: Name to use (this is allocated by this call)
632 * @id: ID to use for the new object (0 to allocate one)
633 * @menup: If non-NULL, returns the new object
634 * Returns: ID number for the object (typically @id), or -ve on error
635 */
636int scene_menu(struct scene *scn, const char *name, uint id,
637 struct scene_obj_menu **menup);
638
639/**
Simon Glass6116e762023-10-01 19:13:32 -0600640 * scene_textline() - create a textline
641 *
642 * @scn: Scene to update
643 * @name: Name to use (this is allocated by this call)
644 * @id: ID to use for the new object (0 to allocate one)
645 * @max_chars: Maximum length of the textline in characters
646 * @tlinep: If non-NULL, returns the new object
647 * Returns: ID number for the object (typically @id), or -ve on error
648 */
649int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
650 struct scene_obj_textline **tlinep);
651
652/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600653 * scene_txt_set_font() - Set the font for an object
654 *
655 * @scn: Scene to update
656 * @id: ID of object to update
657 * @font_name: Font name to use (allocated by caller)
658 * @font_size: Font size to use (nominal height in pixels)
659 */
660int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
661 uint font_size);
662
663/**
664 * scene_obj_set_pos() - Set the postion of an object
665 *
666 * @scn: Scene to update
667 * @id: ID of object to update
668 * @x: x position, in pixels from left side
669 * @y: y position, in pixels from top
670 * Returns: 0 if OK, -ENOENT if @id is invalid
671 */
672int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
673
674/**
Simon Glass7a960052023-06-01 10:22:52 -0600675 * scene_obj_set_size() - Set the size of an object
676 *
677 * @scn: Scene to update
678 * @id: ID of object to update
679 * @w: width in pixels
680 * @h: height in pixels
681 * Returns: 0 if OK, -ENOENT if @id is invalid
682 */
683int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
684
685/**
Simon Glassc6143dc2025-05-02 08:46:35 -0600686 * scene_obj_set_width() - Set the width of an object
687 *
688 * @scn: Scene to update
689 * @id: ID of object to update
690 * @w: width in pixels
691 * Returns: 0 if OK, -ENOENT if @id is invalid
692 */
693int scene_obj_set_width(struct scene *scn, uint id, int w);
694
695/**
696 * scene_obj_set_bbox() - Set the bounding box of an object
697 *
698 * @scn: Scene to update
699 * @id: ID of object to update
700 * @x0: x position, in pixels from left side
701 * @y0: y position, in pixels from top
702 * @x1: ending x position (right side)
703 * @y1: ending y position (botton side)
704 * Returns: 0 if OK, -ENOENT if @id is invalid
705 */
706int scene_obj_set_bbox(struct scene *scn, uint id, int x0, int y0, int x1,
707 int y1);
708
709/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600710 * scene_obj_set_hide() - Set whether an object is hidden
711 *
712 * The update happens when the expo is next rendered.
713 *
714 * @scn: Scene to update
715 * @id: ID of object to update
716 * @hide: true to hide the object, false to show it
717 * Returns: 0 if OK, -ENOENT if @id is invalid
718 */
719int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
720
721/**
722 * scene_menu_set_title() - Set the title of a menu
723 *
724 * @scn: Scene to update
725 * @id: ID of menu object to update
726 * @title_id: ID of text object to use as the title
727 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
728 */
729int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
730
731/**
732 * scene_menu_set_pointer() - Set the item pointer for a menu
733 *
734 * This is a visual indicator of the current item, typically a ">" character
735 * which sits next to the current item and moves when the user presses the
736 * up/down arrow keys
737 *
738 * @scn: Scene to update
739 * @id: ID of menu object to update
740 * @cur_item_id: ID of text or image object to use as a pointer to the current
741 * item
742 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
743 */
744int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
745
746/**
Simon Glassbe04b962025-05-02 08:46:24 -0600747 * scene_menu_select_item() - move the pointer/highlight to an item
748 *
749 * @scn: Scene to update
750 * @id: ID of menu object to update
751 * @sel_id: ID of the menuitem to select
752 * Return 0 on success, -ENOENT if there was no such item
753 */
754int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
755
756/**
757 * scene_menu_get_cur_item() - get the currently pointed-to item
758 *
759 * @scn: Scene to update
760 * @id: ID of menu object to update
761 * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
762 * valid, 0 if no item is pointed to
763 */
764int scene_menu_get_cur_item(struct scene *scn, uint id);
765
766/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600767 * scene_obj_get_hw() - Get width and height of an object in a scene
768 *
769 * @scn: Scene to check
770 * @id: ID of menu object to check
771 * @widthp: If non-NULL, returns width of object in pixels
772 * Returns: Height of object in pixels
773 */
774int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
775
776/**
777 * scene_menuitem() - Add an item to a menu
778 *
779 * @scn: Scene to update
780 * @menu_id: ID of menu object to update
781 * @name: Name to use (this is allocated by this call)
782 * @id: ID to use for the new object (0 to allocate one)
783 * @key_id: ID of text object to use as the keypress to show
784 * @label_id: ID of text object to use as the label text
785 * @desc_id: ID of text object to use as the description text
786 * @preview_id: ID of object to use as the preview (text or image)
787 * @flags: Flags for this item (enum scene_menuitem_flags_t)
788 * @itemp: If non-NULL, returns the new object
789 * Returns: ID number for the item (typically @id), or -ve on error
790 */
791int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
792 uint key_id, uint label_id, uint desc_id, uint preview_id,
793 uint flags, struct scene_menitem **itemp);
794
795/**
796 * scene_arrange() - Arrange the scene to deal with object sizes
797 *
798 * Updates any menus in the scene so that their objects are in the right place.
799 *
800 * @scn: Scene to arrange
801 * Returns: 0 if OK, -ve on error
802 */
803int scene_arrange(struct scene *scn);
804
805/**
806 * expo_send_key() - set a keypress to the expo
807 *
808 * @exp: Expo to receive the key
809 * @key: Key to send (ASCII or enum bootmenu_key)
810 * Returns: 0 if OK, -ECHILD if there is no current scene
811 */
812int expo_send_key(struct expo *exp, int key);
813
814/**
815 * expo_action_get() - read user input from the expo
816 *
817 * @exp: Expo to check
818 * @act: Returns action
819 * Returns: 0 if OK, -EAGAIN if there was no action to return
820 */
821int expo_action_get(struct expo *exp, struct expo_action *act);
822
Simon Glassc999e172023-06-01 10:22:53 -0600823/**
824 * expo_apply_theme() - Apply a theme to an expo
825 *
826 * @exp: Expo to update
827 * @node: Node containing the theme
828 */
829int expo_apply_theme(struct expo *exp, ofnode node);
830
Simon Glass61300722023-06-01 10:23:01 -0600831/**
832 * expo_build() - Build an expo from an FDT description
833 *
834 * Build a complete expo from a description in the provided devicetree.
835 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200836 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600837 *
838 * @root: Root node for expo description
839 * @expp: Returns the new expo
840 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
841 * error, -ENOENT if there is a references to a non-existent string
842 */
843int expo_build(ofnode root, struct expo **expp);
844
Simon Glass34344202024-10-14 16:32:11 -0600845/**
846 * cb_expo_build() - Build an expo for coreboot CMOS RAM
847 *
848 * @expp: Returns the expo created
849 * Return: 0 if OK, -ve on error
850 */
851int cb_expo_build(struct expo **expp);
852
Simon Glass137b4422025-05-02 08:46:16 -0600853/**
854 * expo_poll() - render an expo and see if the user takes an action
855 *
856 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
857 * is processed and the resulting action returned, if any
858 *
859 * @exp: Expo to poll
860 * @act: Returns action on success
861 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
862 * went wrong
863 */
864int expo_poll(struct expo *exp, struct expo_action *act);
865
Simon Glass8df4a4e2023-08-14 16:40:25 -0600866#endif /*__EXPO_H */