blob: 990cb3094eeebb1f273121d32b5bd6c82f6899c4 [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/**
294 * struct scene_obj_txt - information about a text object in a scene
295 *
296 * This is a single-line text object
297 *
298 * @obj: Basic object information
299 * @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
302 */
303struct scene_obj_txt {
304 struct scene_obj obj;
305 uint str_id;
306 const char *font_name;
307 uint font_size;
308};
309
310/**
311 * struct scene_obj_menu - information about a menu object in a scene
312 *
313 * A menu has a number of items which can be selected by the user
314 *
315 * It also has:
316 *
317 * - a text/image object (@pointer_id) which points to the current item
318 * (@cur_item_id)
319 *
320 * - a preview object which shows an image related to the current item
321 *
322 * @obj: Basic object information
323 * @title_id: ID of the title text, or 0 if none
324 * @cur_item_id: ID of the current menu item, or 0 if none
325 * @pointer_id: ID of the object pointing to the current selection
326 * @item_head: List of items in the menu
327 */
328struct scene_obj_menu {
329 struct scene_obj obj;
330 uint title_id;
331 uint cur_item_id;
332 uint pointer_id;
333 struct list_head item_head;
334};
335
336/**
337 * enum scene_menuitem_flags_t - flags for menu items
338 *
339 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
340 */
341enum scene_menuitem_flags_t {
342 SCENEMIF_GAP_BEFORE = 1 << 0,
343};
344
345/**
346 * struct scene_menitem - a menu item in a menu
347 *
348 * A menu item has:
349 *
350 * - text object holding the name (short) and description (can be longer)
351 * - a text object holding the keypress
352 *
353 * @name: Name of the item (this is allocated by this call)
354 * @id: ID number of the object
355 * @key_id: ID of text object to use as the keypress to show
356 * @label_id: ID of text object to use as the label text
357 * @desc_id: ID of text object to use as the description text
358 * @preview_id: ID of the preview object, or 0 if none
359 * @flags: Flags for this item
Simon Glass100389f2024-10-14 16:31:58 -0600360 * @value: Value for this item, or INT_MAX to use sequence
Simon Glassd8adbe92023-01-06 08:52:36 -0600361 * @sibling: Node to link this item to its siblings
362 */
363struct scene_menitem {
364 char *name;
365 uint id;
366 uint key_id;
367 uint label_id;
368 uint desc_id;
369 uint preview_id;
370 uint flags;
Simon Glass100389f2024-10-14 16:31:58 -0600371 int value;
Simon Glassd8adbe92023-01-06 08:52:36 -0600372 struct list_head sibling;
373};
374
375/**
Simon Glass6116e762023-10-01 19:13:32 -0600376 * struct scene_obj_textline - information about a textline in a scene
377 *
378 * A textline has a prompt and a line of editable text
379 *
380 * @obj: Basic object information
381 * @label_id: ID of the label text, or 0 if none
382 * @edit_id: ID of the editable text
383 * @max_chars: Maximum number of characters allowed
384 * @buf: Text buffer containing current text
385 * @pos: Cursor position
386 */
387struct scene_obj_textline {
388 struct scene_obj obj;
389 uint label_id;
390 uint edit_id;
391 uint max_chars;
392 struct abuf buf;
393 uint pos;
394};
395
396/**
Simon Glass377f18e2024-10-14 16:31:55 -0600397 * struct expo_arrange_info - Information used when arranging a scene
398 *
399 * @label_width: Maximum width of labels in scene
400 */
401struct expo_arrange_info {
402 int label_width;
403};
404
405/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600406 * expo_new() - create a new expo
407 *
408 * Allocates a new expo
409 *
410 * @name: Name of expo (this is allocated by this call)
411 * @priv: Private data for the controller
412 * @expp: Returns a pointer to the new expo on success
413 * Returns: 0 if OK, -ENOMEM if out of memory
414 */
415int expo_new(const char *name, void *priv, struct expo **expp);
416
417/**
418 * expo_destroy() - Destroy an expo and free all its memory
419 *
420 * @exp: Expo to destroy
421 */
422void expo_destroy(struct expo *exp);
423
424/**
Simon Glass6e9e4152023-06-01 10:22:47 -0600425 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
426 *
427 * It is common for a set of 'static' IDs to be used to refer to objects in the
428 * expo. These typically use an enum so that they are defined in sequential
429 * order.
430 *
431 * Dynamic IDs (for objects not in the enum) are intended to be used for
432 * objects to which the code does not need to refer. These are ideally located
433 * above the static IDs.
434 *
435 * Use this function to set the start of the dynamic range, making sure that the
436 * value is higher than all the statically allocated IDs.
437 *
438 * @exp: Expo to update
439 * @dyn_start: Start ID that expo should use for dynamic allocation
440 */
441void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
442
443/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600444 * expo_str() - add a new string to an expo
445 *
446 * @exp: Expo to update
447 * @name: Name to use (this is allocated by this call)
448 * @id: ID to use for the new object (0 to allocate one)
449 * @str: Pointer to text to display (allocated by caller)
450 * Returns: ID number for the object (typically @id), or -ve on error
451 */
452int expo_str(struct expo *exp, const char *name, uint id, const char *str);
453
454/**
455 * expo_get_str() - Get a string by ID
456 *
457 * @exp: Expo to use
458 * @id: String ID to look up
459 * @returns string, or NULL if not found
460 */
461const char *expo_get_str(struct expo *exp, uint id);
462
463/**
464 * expo_set_display() - set the display to use for a expo
465 *
466 * @exp: Expo to update
467 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
468 * Returns: 0 (always)
469 */
470int expo_set_display(struct expo *exp, struct udevice *dev);
471
472/**
Simon Glass7a960052023-06-01 10:22:52 -0600473 * expo_calc_dims() - Calculate the dimensions of the objects
474 *
475 * Updates the width and height of all objects based on their contents
476 *
477 * @exp: Expo to update
478 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
479 */
480int expo_calc_dims(struct expo *exp);
481
482/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600483 * expo_set_scene_id() - Set the current scene ID
484 *
485 * @exp: Expo to update
486 * @scene_id: New scene ID to use (0 to select no scene)
487 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
488 */
489int expo_set_scene_id(struct expo *exp, uint scene_id);
490
491/**
Simon Glassc8925112023-06-01 10:23:02 -0600492 * expo_first_scene_id() - Get the ID of the first scene
493 *
494 * @exp: Expo to check
495 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
496 */
497int expo_first_scene_id(struct expo *exp);
498
499/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600500 * expo_render() - render the expo on the display / console
501 *
502 * @exp: Expo to render
503 *
504 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
505 * current scene is not found, other error if something else goes wrong
506 */
507int expo_render(struct expo *exp);
508
509/**
Simon Glassb2c40342023-06-01 10:22:37 -0600510 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600511 *
512 * @exp: Expo to update
513 * @text_mode: true to use text mode, false to use the console
514 */
Simon Glassb2c40342023-06-01 10:22:37 -0600515void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600516
517/**
518 * scene_new() - create a new scene in a expo
519 *
520 * The scene is given the ID @id which must be unique across all scenes, objects
521 * and items. The expo's @next_id is updated to at least @id + 1
522 *
523 * @exp: Expo to update
524 * @name: Name to use (this is allocated by this call)
525 * @id: ID to use for the new scene (0 to allocate one)
526 * @scnp: Returns a pointer to the new scene on success
527 * Returns: ID number for the scene (typically @id), or -ve on error
528 */
529int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
530
531/**
532 * expo_lookup_scene_id() - Look up a scene by ID
533 *
534 * @exp: Expo to check
535 * @scene_id: Scene ID to look up
536 * @returns pointer to scene if found, else NULL
537 */
538struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
539
540/**
Simon Glass01922ec2023-06-01 10:22:57 -0600541 * scene_highlight_first() - Highlight the first item in a scene
542 *
543 * This highlights the first item, so that the user can see that it is pointed
544 * to
545 *
546 * @scn: Scene to update
547 */
548void scene_highlight_first(struct scene *scn);
549
550/**
551 * scene_set_highlight_id() - Set the object which is highlighted
552 *
553 * Sets a new object to highlight in the scene
554 *
555 * @scn: Scene to update
556 * @id: ID of object to highlight
557 */
558void scene_set_highlight_id(struct scene *scn, uint id);
559
560/**
561 * scene_set_open() - Set whether an item is open or not
562 *
563 * @scn: Scene to update
564 * @id: ID of object to update
565 * @open: true to open the object, false to close it
566 * Returns: 0 if OK, -ENOENT if @id is invalid
567 */
568int scene_set_open(struct scene *scn, uint id, bool open);
569
570/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600571 * scene_obj_count() - Count the number of objects in a scene
572 *
573 * @scn: Scene to check
574 * Returns: number of objects in the scene, 0 if none
575 */
576int scene_obj_count(struct scene *scn);
577
578/**
579 * scene_img() - add a new image to a scene
580 *
581 * @scn: Scene to update
582 * @name: Name to use (this is allocated by this call)
583 * @id: ID to use for the new object (0 to allocate one)
584 * @data: Pointer to image data
585 * @imgp: If non-NULL, returns the new object
586 * Returns: ID number for the object (typically @id), or -ve on error
587 */
588int scene_img(struct scene *scn, const char *name, uint id, char *data,
589 struct scene_obj_img **imgp);
590
591/**
592 * scene_txt() - add a new text object to a scene
593 *
594 * @scn: Scene to update
595 * @name: Name to use (this is allocated by this call)
596 * @id: ID to use for the new object (0 to allocate one)
597 * @str_id: ID of the string to use
598 * @txtp: If non-NULL, returns the new object
599 * Returns: ID number for the object (typically @id), or -ve on error
600 */
601int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
602 struct scene_obj_txt **txtp);
603
604/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600605 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600606 *
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 * @str_id: ID of the string to use
611 * @str: Pointer to text to display (allocated by caller)
612 * @txtp: If non-NULL, returns the new object
613 * Returns: ID number for the object (typically @id), or -ve on error
614 */
615int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
616 const char *str, struct scene_obj_txt **txtp);
617
618/**
619 * scene_menu() - create a menu
620 *
621 * @scn: Scene to update
622 * @name: Name to use (this is allocated by this call)
623 * @id: ID to use for the new object (0 to allocate one)
624 * @menup: If non-NULL, returns the new object
625 * Returns: ID number for the object (typically @id), or -ve on error
626 */
627int scene_menu(struct scene *scn, const char *name, uint id,
628 struct scene_obj_menu **menup);
629
630/**
Simon Glass6116e762023-10-01 19:13:32 -0600631 * scene_textline() - create a textline
632 *
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 * @max_chars: Maximum length of the textline in characters
637 * @tlinep: If non-NULL, returns the new object
638 * Returns: ID number for the object (typically @id), or -ve on error
639 */
640int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
641 struct scene_obj_textline **tlinep);
642
643/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600644 * scene_txt_set_font() - Set the font for an object
645 *
646 * @scn: Scene to update
647 * @id: ID of object to update
648 * @font_name: Font name to use (allocated by caller)
649 * @font_size: Font size to use (nominal height in pixels)
650 */
651int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
652 uint font_size);
653
654/**
655 * scene_obj_set_pos() - Set the postion of an object
656 *
657 * @scn: Scene to update
658 * @id: ID of object to update
659 * @x: x position, in pixels from left side
660 * @y: y position, in pixels from top
661 * Returns: 0 if OK, -ENOENT if @id is invalid
662 */
663int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
664
665/**
Simon Glass7a960052023-06-01 10:22:52 -0600666 * scene_obj_set_size() - Set the size of an object
667 *
668 * @scn: Scene to update
669 * @id: ID of object to update
670 * @w: width in pixels
671 * @h: height in pixels
672 * Returns: 0 if OK, -ENOENT if @id is invalid
673 */
674int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
675
676/**
Simon Glassc6143dc2025-05-02 08:46:35 -0600677 * scene_obj_set_width() - Set the width of an object
678 *
679 * @scn: Scene to update
680 * @id: ID of object to update
681 * @w: width in pixels
682 * Returns: 0 if OK, -ENOENT if @id is invalid
683 */
684int scene_obj_set_width(struct scene *scn, uint id, int w);
685
686/**
687 * scene_obj_set_bbox() - Set the bounding box of an object
688 *
689 * @scn: Scene to update
690 * @id: ID of object to update
691 * @x0: x position, in pixels from left side
692 * @y0: y position, in pixels from top
693 * @x1: ending x position (right side)
694 * @y1: ending y position (botton side)
695 * Returns: 0 if OK, -ENOENT if @id is invalid
696 */
697int scene_obj_set_bbox(struct scene *scn, uint id, int x0, int y0, int x1,
698 int y1);
699
700/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600701 * scene_obj_set_hide() - Set whether an object is hidden
702 *
703 * The update happens when the expo is next rendered.
704 *
705 * @scn: Scene to update
706 * @id: ID of object to update
707 * @hide: true to hide the object, false to show it
708 * Returns: 0 if OK, -ENOENT if @id is invalid
709 */
710int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
711
712/**
713 * scene_menu_set_title() - Set the title of a menu
714 *
715 * @scn: Scene to update
716 * @id: ID of menu object to update
717 * @title_id: ID of text object to use as the title
718 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
719 */
720int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
721
722/**
723 * scene_menu_set_pointer() - Set the item pointer for a menu
724 *
725 * This is a visual indicator of the current item, typically a ">" character
726 * which sits next to the current item and moves when the user presses the
727 * up/down arrow keys
728 *
729 * @scn: Scene to update
730 * @id: ID of menu object to update
731 * @cur_item_id: ID of text or image object to use as a pointer to the current
732 * item
733 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
734 */
735int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
736
737/**
Simon Glassbe04b962025-05-02 08:46:24 -0600738 * scene_menu_select_item() - move the pointer/highlight to an item
739 *
740 * @scn: Scene to update
741 * @id: ID of menu object to update
742 * @sel_id: ID of the menuitem to select
743 * Return 0 on success, -ENOENT if there was no such item
744 */
745int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
746
747/**
748 * scene_menu_get_cur_item() - get the currently pointed-to item
749 *
750 * @scn: Scene to update
751 * @id: ID of menu object to update
752 * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
753 * valid, 0 if no item is pointed to
754 */
755int scene_menu_get_cur_item(struct scene *scn, uint id);
756
757/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600758 * scene_obj_get_hw() - Get width and height of an object in a scene
759 *
760 * @scn: Scene to check
761 * @id: ID of menu object to check
762 * @widthp: If non-NULL, returns width of object in pixels
763 * Returns: Height of object in pixels
764 */
765int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
766
767/**
768 * scene_menuitem() - Add an item to a menu
769 *
770 * @scn: Scene to update
771 * @menu_id: ID of menu object to update
772 * @name: Name to use (this is allocated by this call)
773 * @id: ID to use for the new object (0 to allocate one)
774 * @key_id: ID of text object to use as the keypress to show
775 * @label_id: ID of text object to use as the label text
776 * @desc_id: ID of text object to use as the description text
777 * @preview_id: ID of object to use as the preview (text or image)
778 * @flags: Flags for this item (enum scene_menuitem_flags_t)
779 * @itemp: If non-NULL, returns the new object
780 * Returns: ID number for the item (typically @id), or -ve on error
781 */
782int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
783 uint key_id, uint label_id, uint desc_id, uint preview_id,
784 uint flags, struct scene_menitem **itemp);
785
786/**
787 * scene_arrange() - Arrange the scene to deal with object sizes
788 *
789 * Updates any menus in the scene so that their objects are in the right place.
790 *
791 * @scn: Scene to arrange
792 * Returns: 0 if OK, -ve on error
793 */
794int scene_arrange(struct scene *scn);
795
796/**
797 * expo_send_key() - set a keypress to the expo
798 *
799 * @exp: Expo to receive the key
800 * @key: Key to send (ASCII or enum bootmenu_key)
801 * Returns: 0 if OK, -ECHILD if there is no current scene
802 */
803int expo_send_key(struct expo *exp, int key);
804
805/**
806 * expo_action_get() - read user input from the expo
807 *
808 * @exp: Expo to check
809 * @act: Returns action
810 * Returns: 0 if OK, -EAGAIN if there was no action to return
811 */
812int expo_action_get(struct expo *exp, struct expo_action *act);
813
Simon Glassc999e172023-06-01 10:22:53 -0600814/**
815 * expo_apply_theme() - Apply a theme to an expo
816 *
817 * @exp: Expo to update
818 * @node: Node containing the theme
819 */
820int expo_apply_theme(struct expo *exp, ofnode node);
821
Simon Glass61300722023-06-01 10:23:01 -0600822/**
823 * expo_build() - Build an expo from an FDT description
824 *
825 * Build a complete expo from a description in the provided devicetree.
826 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200827 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600828 *
829 * @root: Root node for expo description
830 * @expp: Returns the new expo
831 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
832 * error, -ENOENT if there is a references to a non-existent string
833 */
834int expo_build(ofnode root, struct expo **expp);
835
Simon Glass34344202024-10-14 16:32:11 -0600836/**
837 * cb_expo_build() - Build an expo for coreboot CMOS RAM
838 *
839 * @expp: Returns the expo created
840 * Return: 0 if OK, -ve on error
841 */
842int cb_expo_build(struct expo **expp);
843
Simon Glass137b4422025-05-02 08:46:16 -0600844/**
845 * expo_poll() - render an expo and see if the user takes an action
846 *
847 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
848 * is processed and the resulting action returned, if any
849 *
850 * @exp: Expo to poll
851 * @act: Returns action on success
852 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
853 * went wrong
854 */
855int expo_poll(struct expo *exp, struct expo_action *act);
856
Simon Glass8df4a4e2023-08-14 16:40:25 -0600857#endif /*__EXPO_H */