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