blob: 16f2f18c4fa1f21463d6ffdedf4c31a33653bfa3 [file] [log] [blame]
Simon Glassd8adbe92023-01-06 08:52:36 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2022 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
Simon Glass8df4a4e2023-08-14 16:40:25 -06007#ifndef __EXPO_H
8#define __EXPO_H
Simon Glassd8adbe92023-01-06 08:52:36 -06009
Simon Glassa968f5f2023-10-01 19:13:31 -060010#include <abuf.h>
Simon Glasscfb4f2c2025-05-02 08:46:42 -060011#include <alist.h>
Simon Glassc999e172023-06-01 10:22:53 -060012#include <dm/ofnode_decl.h>
Simon Glassebec4972025-05-02 08:46:33 -060013#include <linux/bitops.h>
Simon Glassd8adbe92023-01-06 08:52:36 -060014#include <linux/list.h>
15
16struct udevice;
17
Simon Glassa968f5f2023-10-01 19:13:31 -060018#include <cli.h>
19
Simon Glassd8adbe92023-01-06 08:52:36 -060020/**
Simon Glass53a0a2f2024-10-14 16:31:57 -060021 * enum expo_id_t - standard expo IDs
22 *
23 * These are assumed to be in use at all times. Expos should use IDs starting
24 * from EXPOID_BASE_ID,
25 *
26 * @EXPOID_NONE: Not used, invalid ID 0
27 * @EXPOID_SAVE: User has requested that the expo data be saved
28 * @EXPOID_DISCARD: User has requested that the expo data be discarded
29 * @EXPOID_BASE_ID: First ID which can be used for expo objects
30 */
31enum expo_id_t {
32 EXPOID_NONE,
33
34 EXPOID_SAVE,
35 EXPOID_DISCARD,
36
37 EXPOID_BASE_ID = 5,
38};
39
40/**
Simon Glassd8adbe92023-01-06 08:52:36 -060041 * enum expoact_type - types of actions reported by the expo
42 *
43 * @EXPOACT_NONE: no action
Simon Glassf0e1e8c2023-06-01 10:22:59 -060044 * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which)
Simon Glass719a3c62023-06-01 10:22:56 -060045 * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
Simon Glassd8adbe92023-01-06 08:52:36 -060046 * @EXPOACT_SELECT: menu item was selected (@id indicates which)
Simon Glassf0e1e8c2023-06-01 10:22:59 -060047 * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates
48 * which menu object)
49 * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object)
Simon Glassd8adbe92023-01-06 08:52:36 -060050 * @EXPOACT_QUIT: request to exit the menu
51 */
52enum expoact_type {
53 EXPOACT_NONE,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060054 EXPOACT_POINT_OBJ,
Simon Glass719a3c62023-06-01 10:22:56 -060055 EXPOACT_POINT_ITEM,
Simon Glassd8adbe92023-01-06 08:52:36 -060056 EXPOACT_SELECT,
Simon Glassf0e1e8c2023-06-01 10:22:59 -060057 EXPOACT_OPEN,
58 EXPOACT_CLOSE,
Simon Glassd8adbe92023-01-06 08:52:36 -060059 EXPOACT_QUIT,
60};
61
62/**
63 * struct expo_action - an action report by the expo
64 *
65 * @type: Action type (EXPOACT_NONE if there is no action)
Simon Glass719a3c62023-06-01 10:22:56 -060066 * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT
Heinrich Schuchardta99e8fe2024-09-18 23:58:03 +020067 * @select.id: ID number of the object affected.
Simon Glassd8adbe92023-01-06 08:52:36 -060068 */
69struct expo_action {
70 enum expoact_type type;
71 union {
72 struct {
73 int id;
74 } select;
75 };
76};
77
78/**
Simon Glassc999e172023-06-01 10:22:53 -060079 * struct expo_theme - theme for the expo
80 *
81 * @font_size: Default font size for all text
82 * @menu_inset: Inset width (on each side and top/bottom) for menu items
83 * @menuitem_gap_y: Gap between menu items in pixels
Simon Glass377f18e2024-10-14 16:31:55 -060084 * @menu_title_margin_x: Gap between right side of menu title and left size of
85 * menu label
Simon Glassc999e172023-06-01 10:22:53 -060086 */
87struct expo_theme {
88 u32 font_size;
89 u32 menu_inset;
90 u32 menuitem_gap_y;
Simon Glass377f18e2024-10-14 16:31:55 -060091 u32 menu_title_margin_x;
Simon Glassc999e172023-06-01 10:22:53 -060092};
93
94/**
Simon Glassd8adbe92023-01-06 08:52:36 -060095 * struct expo - information about an expo
96 *
97 * A group of scenes which can be presented to the user, typically to obtain
98 * input or to make a selection.
99 *
100 * @name: Name of the expo (allocated)
101 * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
Simon Glass67e2af12023-06-01 10:22:34 -0600102 * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600103 * @scene_id: Current scene ID (0 if none)
104 * @next_id: Next ID number to use, for automatic allocation
105 * @action: Action selected by user. At present only one is supported, with the
106 * type set to EXPOACT_NONE if there is no action
107 * @text_mode: true to use text mode for the menu (no vidconsole)
Simon Glassd353b752023-06-01 10:22:55 -0600108 * @popup: true to use popup menus, instead of showing all items
Simon Glassd8adbe92023-01-06 08:52:36 -0600109 * @priv: Private data for the controller
Simon Glass527d8642025-05-02 08:46:20 -0600110 * @done: Indicates that a cedit session is complete and the user has quit
111 * @save: Indicates that cedit data should be saved, rather than discarded
Simon Glassc999e172023-06-01 10:22:53 -0600112 * @theme: Information about fonts styles, etc.
Simon Glassd8adbe92023-01-06 08:52:36 -0600113 * @scene_head: List of scenes
114 * @str_head: list of strings
Simon Glass683d8832025-05-02 08:46:15 -0600115 * @cch: Keyboard context for input
Simon Glassd8adbe92023-01-06 08:52:36 -0600116 */
117struct expo {
118 char *name;
119 struct udevice *display;
Simon Glass67e2af12023-06-01 10:22:34 -0600120 struct udevice *cons;
Simon Glassd8adbe92023-01-06 08:52:36 -0600121 uint scene_id;
122 uint next_id;
123 struct expo_action action;
124 bool text_mode;
Simon Glassd353b752023-06-01 10:22:55 -0600125 bool popup;
Simon Glassd8adbe92023-01-06 08:52:36 -0600126 void *priv;
Simon Glass527d8642025-05-02 08:46:20 -0600127 bool done;
128 bool save;
Simon Glassc999e172023-06-01 10:22:53 -0600129 struct expo_theme theme;
Simon Glassd8adbe92023-01-06 08:52:36 -0600130 struct list_head scene_head;
131 struct list_head str_head;
Simon Glass683d8832025-05-02 08:46:15 -0600132 struct cli_ch_state cch;
Simon Glassd8adbe92023-01-06 08:52:36 -0600133};
134
135/**
136 * struct expo_string - a string that can be used in an expo
137 *
138 * @id: ID number of the string
Simon Glassda337752025-05-02 08:46:32 -0600139 * @buf: String (contains nul terminator)
Simon Glassd8adbe92023-01-06 08:52:36 -0600140 * @sibling: Node to link this object to its siblings
141 */
142struct expo_string {
143 uint id;
Simon Glassda337752025-05-02 08:46:32 -0600144 struct abuf buf;
Simon Glassd8adbe92023-01-06 08:52:36 -0600145 struct list_head sibling;
146};
147
148/**
149 * struct scene - information about a scene in an expo
150 *
151 * A collection of text/image/menu items in an expo
152 *
153 * @expo: Expo this scene is part of
154 * @name: Name of the scene (allocated)
155 * @id: ID number of the scene
Simon Glassea274b62023-06-01 10:22:27 -0600156 * @title_id: String ID of title of the scene (allocated)
Simon Glassd353b752023-06-01 10:22:55 -0600157 * @highlight_id: ID of highlighted object, if any
Simon Glassa968f5f2023-10-01 19:13:31 -0600158 * @cls: cread state to use for input
159 * @buf: Buffer for input
160 * @entry_save: Buffer to hold vidconsole text-entry information
Simon Glassd8adbe92023-01-06 08:52:36 -0600161 * @sibling: Node to link this scene to its siblings
162 * @obj_head: List of objects in the scene
163 */
164struct scene {
165 struct expo *expo;
166 char *name;
167 uint id;
Simon Glassea274b62023-06-01 10:22:27 -0600168 uint title_id;
Simon Glassd353b752023-06-01 10:22:55 -0600169 uint highlight_id;
Simon Glassa968f5f2023-10-01 19:13:31 -0600170 struct cli_line_state cls;
171 struct abuf buf;
172 struct abuf entry_save;
Simon Glassd8adbe92023-01-06 08:52:36 -0600173 struct list_head sibling;
174 struct list_head obj_head;
175};
176
177/**
178 * enum scene_obj_t - type of a scene object
179 *
180 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
181 * @SCENEOBJT_IMAGE: Image data to render
Simon Glass138a3972025-05-02 08:46:44 -0600182 * @SCENEOBJT_BOX: Rectangular box
Simon Glassd8adbe92023-01-06 08:52:36 -0600183 * @SCENEOBJT_TEXT: Text line to render
184 * @SCENEOBJT_MENU: Menu containing items the user can select
Simon Glass6116e762023-10-01 19:13:32 -0600185 * @SCENEOBJT_TEXTLINE: Line of text the user can edit
Simon Glass5dc887d2025-05-02 08:46:46 -0600186 * @SCENEOBJT_TEXTEDIT: Simple text editor
Simon Glassd8adbe92023-01-06 08:52:36 -0600187 */
188enum scene_obj_t {
189 SCENEOBJT_NONE = 0,
190 SCENEOBJT_IMAGE,
191 SCENEOBJT_TEXT,
Simon Glass138a3972025-05-02 08:46:44 -0600192 SCENEOBJT_BOX,
Simon Glass5dc887d2025-05-02 08:46:46 -0600193 SCENEOBJT_TEXTEDIT,
Simon Glass193bfea2023-10-01 19:13:27 -0600194
195 /* types from here on can be highlighted */
Simon Glassd8adbe92023-01-06 08:52:36 -0600196 SCENEOBJT_MENU,
Simon Glass6116e762023-10-01 19:13:32 -0600197 SCENEOBJT_TEXTLINE,
Simon Glassd8adbe92023-01-06 08:52:36 -0600198};
199
200/**
Simon Glass854ca692025-05-02 08:46:30 -0600201 * struct scene_obj_bbox - Dimensions of an object
Simon Glass7b043952023-06-01 10:22:49 -0600202 *
Simon Glassbc3a15f2025-05-02 08:46:31 -0600203 * @x0: x position, in pixels from left side
204 * @y0: y position, in pixels from top
Simon Glassebec4972025-05-02 08:46:33 -0600205 * @x1: x position of right size
206 * @y1: y position of bottom
Simon Glass7b043952023-06-01 10:22:49 -0600207 */
Simon Glass854ca692025-05-02 08:46:30 -0600208struct scene_obj_bbox {
Simon Glassbc3a15f2025-05-02 08:46:31 -0600209 int x0;
210 int y0;
Simon Glassebec4972025-05-02 08:46:33 -0600211 int x1;
212 int y1;
Simon Glass7b043952023-06-01 10:22:49 -0600213};
214
215/**
Simon Glass5beb0572025-05-02 08:46:45 -0600216 * struct scene_obj_offset - Offsets for drawing the object
217 *
218 * Stores the offset from x0, x1 at which objects are drawn
219 *
220 * @xofs: x offset
221 * @yofs: y offset
222 */
223struct scene_obj_offset {
224 int xofs;
225 int yofs;
226};
227
228/**
Simon Glassebec4972025-05-02 08:46:33 -0600229 * struct scene_obj_dims - Dimensions of the object being drawn
230 *
231 * Image and text objects have a dimension which can change depending on what
232 * they contain. For images this stores the size. For text it stores the size as
233 * rendered on the display
234 *
235 * @x: x dimension
236 * @y: y dimension
237 */
238struct scene_obj_dims {
239 int x;
240 int y;
241};
242
243/**
Simon Glass5beb0572025-05-02 08:46:45 -0600244 * enum scene_obj_halign - Horizontal alignment of objects
245 *
246 * Objects are normally drawn on the left size of their bounding box. This
247 * properly allows aligning on the right or having the object centred.
248 *
249 * @SCENEOA_LEFT: Left of object is aligned with its x coordinate
250 * @SCENEOA_RIGHT: Right of object is aligned with x + w
251 * @SCENEOA_CENTRE: Centre of object is aligned with centre of bounding box
252 * @SCENEOA_TOP: Left of object is aligned with its x coordinate
253 * @SCENEOA_BOTTOM: Right of object is aligned with x + w
254 *
255 * Note: It would be nice to make this a char type but Sphinx riddles:
256 * ./include/expo.h:258: error: Cannot parse enum!
257 * enum scene_obj_align : char {
258 */
259enum scene_obj_align {
260 SCENEOA_LEFT,
261 SCENEOA_RIGHT,
262 SCENEOA_CENTRE,
263 SCENEOA_TOP = SCENEOA_LEFT,
264 SCENEOA_BOTTOM = SCENEOA_RIGHT,
265};
266
267/**
Simon Glass6081b0f2023-06-01 10:22:50 -0600268 * enum scene_obj_flags_t - flags for objects
269 *
270 * @SCENEOF_HIDE: object should be hidden
Simon Glassd353b752023-06-01 10:22:55 -0600271 * @SCENEOF_POINT: object should be highlighted
272 * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
273 * can be selected)
Simon Glassebec4972025-05-02 08:46:33 -0600274 * @SCENEOF_SIZE_VALID: object's size (width/height) is valid, so any adjustment
275 * to x0/y0 should maintain the width/height of the object
Simon Glass6081b0f2023-06-01 10:22:50 -0600276 */
277enum scene_obj_flags_t {
278 SCENEOF_HIDE = 1 << 0,
Simon Glassd353b752023-06-01 10:22:55 -0600279 SCENEOF_POINT = 1 << 1,
280 SCENEOF_OPEN = 1 << 2,
Simon Glassebec4972025-05-02 08:46:33 -0600281 SCENEOF_SIZE_VALID = BIT(3),
Simon Glass6081b0f2023-06-01 10:22:50 -0600282};
283
Simon Glassa968f5f2023-10-01 19:13:31 -0600284enum {
285 /* Maximum number of characters allowed in an line editor */
286 EXPO_MAX_CHARS = 250,
287};
288
Simon Glass6081b0f2023-06-01 10:22:50 -0600289/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600290 * struct scene_obj - information about an object in a scene
291 *
292 * @scene: Scene that this object relates to
293 * @name: Name of the object (allocated)
294 * @id: ID number of the object
295 * @type: Type of this object
Simon Glassebec4972025-05-02 08:46:33 -0600296 * @bbox: Bounding box for this object
Simon Glass5beb0572025-05-02 08:46:45 -0600297 * @ofs: Offset from x0, y0 where the object is drawn
Simon Glassebec4972025-05-02 08:46:33 -0600298 * @dims: Dimensions of the text/image (may be smaller than bbox)
Simon Glass5beb0572025-05-02 08:46:45 -0600299 * @horiz: Horizonal alignment
300 * @vert: Vertical alignment
Simon Glass6081b0f2023-06-01 10:22:50 -0600301 * @flags: Flags for this object
Simon Glass2b91ca62023-08-14 16:40:37 -0600302 * @bit_length: Number of bits used for this object in CMOS RAM
303 * @start_bit: Start bit to use for this object in CMOS RAM
Simon Glassd8adbe92023-01-06 08:52:36 -0600304 * @sibling: Node to link this object to its siblings
305 */
306struct scene_obj {
307 struct scene *scene;
308 char *name;
309 uint id;
310 enum scene_obj_t type;
Simon Glass854ca692025-05-02 08:46:30 -0600311 struct scene_obj_bbox bbox;
Simon Glass5beb0572025-05-02 08:46:45 -0600312 struct scene_obj_offset ofs;
Simon Glassebec4972025-05-02 08:46:33 -0600313 struct scene_obj_dims dims;
Simon Glass5beb0572025-05-02 08:46:45 -0600314 enum scene_obj_align horiz;
315 enum scene_obj_align vert;
Simon Glass2b91ca62023-08-14 16:40:37 -0600316 u8 flags;
317 u8 bit_length;
318 u16 start_bit;
Simon Glassd8adbe92023-01-06 08:52:36 -0600319 struct list_head sibling;
320};
321
Simon Glass193bfea2023-10-01 19:13:27 -0600322/* object can be highlighted when moving around expo */
323static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
324{
325 return obj->type >= SCENEOBJT_MENU;
326}
327
Simon Glassd8adbe92023-01-06 08:52:36 -0600328/**
329 * struct scene_obj_img - information about an image object in a scene
330 *
331 * This is a rectangular image which is blitted onto the display
332 *
333 * @obj: Basic object information
334 * @data: Image data in BMP format
335 */
336struct scene_obj_img {
337 struct scene_obj obj;
338 char *data;
339};
340
341/**
Simon Glass9ef02aa2025-05-02 08:46:37 -0600342 * struct scene_txt_generic - Generic information common to text objects
Simon Glassd8adbe92023-01-06 08:52:36 -0600343 *
Simon Glassd8adbe92023-01-06 08:52:36 -0600344 * @str_id: ID of the text string to display
345 * @font_name: Name of font (allocated by caller)
346 * @font_size: Nominal size of font in pixels
Simon Glasscfb4f2c2025-05-02 08:46:42 -0600347 * @lines: alist of struct vidconsole_mline with a separate record for each
348 * line of text
Simon Glassd8adbe92023-01-06 08:52:36 -0600349 */
Simon Glass9ef02aa2025-05-02 08:46:37 -0600350struct scene_txt_generic {
Simon Glassd8adbe92023-01-06 08:52:36 -0600351 uint str_id;
352 const char *font_name;
353 uint font_size;
Simon Glasscfb4f2c2025-05-02 08:46:42 -0600354 struct alist lines;
Simon Glassd8adbe92023-01-06 08:52:36 -0600355};
356
357/**
Simon Glass9ef02aa2025-05-02 08:46:37 -0600358 * struct scene_obj_txt - information about a text object in a scene
359 *
360 * This is a single-line text object
361 *
362 * @obj: Basic object information
363 * @gen: Generic information common to all objects which show text
364 */
365struct scene_obj_txt {
366 struct scene_obj obj;
367 struct scene_txt_generic gen;
368};
369
370/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600371 * struct scene_obj_menu - information about a menu object in a scene
372 *
373 * A menu has a number of items which can be selected by the user
374 *
375 * It also has:
376 *
377 * - a text/image object (@pointer_id) which points to the current item
378 * (@cur_item_id)
379 *
380 * - a preview object which shows an image related to the current item
381 *
382 * @obj: Basic object information
383 * @title_id: ID of the title text, or 0 if none
384 * @cur_item_id: ID of the current menu item, or 0 if none
385 * @pointer_id: ID of the object pointing to the current selection
386 * @item_head: List of items in the menu
387 */
388struct scene_obj_menu {
389 struct scene_obj obj;
390 uint title_id;
391 uint cur_item_id;
392 uint pointer_id;
393 struct list_head item_head;
394};
395
396/**
397 * enum scene_menuitem_flags_t - flags for menu items
398 *
399 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
400 */
401enum scene_menuitem_flags_t {
402 SCENEMIF_GAP_BEFORE = 1 << 0,
403};
404
405/**
406 * struct scene_menitem - a menu item in a menu
407 *
408 * A menu item has:
409 *
410 * - text object holding the name (short) and description (can be longer)
411 * - a text object holding the keypress
412 *
413 * @name: Name of the item (this is allocated by this call)
414 * @id: ID number of the object
415 * @key_id: ID of text object to use as the keypress to show
416 * @label_id: ID of text object to use as the label text
417 * @desc_id: ID of text object to use as the description text
418 * @preview_id: ID of the preview object, or 0 if none
419 * @flags: Flags for this item
Simon Glass100389f2024-10-14 16:31:58 -0600420 * @value: Value for this item, or INT_MAX to use sequence
Simon Glassd8adbe92023-01-06 08:52:36 -0600421 * @sibling: Node to link this item to its siblings
422 */
423struct scene_menitem {
424 char *name;
425 uint id;
426 uint key_id;
427 uint label_id;
428 uint desc_id;
429 uint preview_id;
430 uint flags;
Simon Glass100389f2024-10-14 16:31:58 -0600431 int value;
Simon Glassd8adbe92023-01-06 08:52:36 -0600432 struct list_head sibling;
433};
434
435/**
Simon Glass6116e762023-10-01 19:13:32 -0600436 * struct scene_obj_textline - information about a textline in a scene
437 *
438 * A textline has a prompt and a line of editable text
439 *
440 * @obj: Basic object information
441 * @label_id: ID of the label text, or 0 if none
442 * @edit_id: ID of the editable text
443 * @max_chars: Maximum number of characters allowed
444 * @buf: Text buffer containing current text
445 * @pos: Cursor position
446 */
447struct scene_obj_textline {
448 struct scene_obj obj;
449 uint label_id;
450 uint edit_id;
451 uint max_chars;
452 struct abuf buf;
453 uint pos;
454};
455
456/**
Simon Glass138a3972025-05-02 08:46:44 -0600457 * struct scene_obj_box - information about a box in a scene
458 *
459 * A box surrounds a part of the screen with a border
460 *
461 * @obj: Basic object information
462 * @width: Line-width in pixels
463 */
464struct scene_obj_box {
465 struct scene_obj obj;
466 uint width;
467};
468
469/**
Simon Glass5dc887d2025-05-02 08:46:46 -0600470 * struct scene_obj_txtedit - information about a box in a scene
471 *
472 * A text editor which allows users to edit a small text file
473 *
474 * @obj: Basic object information
475 * @gen: Generic information common to all objects which show text
476 * @buf: Text buffer containing current text
477 */
478struct scene_obj_txtedit {
479 struct scene_obj obj;
480 struct scene_txt_generic gen;
481 struct abuf buf;
482};
483
484/**
Simon Glass377f18e2024-10-14 16:31:55 -0600485 * struct expo_arrange_info - Information used when arranging a scene
486 *
487 * @label_width: Maximum width of labels in scene
488 */
489struct expo_arrange_info {
490 int label_width;
491};
492
493/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600494 * expo_new() - create a new expo
495 *
496 * Allocates a new expo
497 *
498 * @name: Name of expo (this is allocated by this call)
499 * @priv: Private data for the controller
500 * @expp: Returns a pointer to the new expo on success
501 * Returns: 0 if OK, -ENOMEM if out of memory
502 */
503int expo_new(const char *name, void *priv, struct expo **expp);
504
505/**
506 * expo_destroy() - Destroy an expo and free all its memory
507 *
508 * @exp: Expo to destroy
509 */
510void expo_destroy(struct expo *exp);
511
512/**
Simon Glass6e9e4152023-06-01 10:22:47 -0600513 * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
514 *
515 * It is common for a set of 'static' IDs to be used to refer to objects in the
516 * expo. These typically use an enum so that they are defined in sequential
517 * order.
518 *
519 * Dynamic IDs (for objects not in the enum) are intended to be used for
520 * objects to which the code does not need to refer. These are ideally located
521 * above the static IDs.
522 *
523 * Use this function to set the start of the dynamic range, making sure that the
524 * value is higher than all the statically allocated IDs.
525 *
526 * @exp: Expo to update
527 * @dyn_start: Start ID that expo should use for dynamic allocation
528 */
529void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
530
531/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600532 * expo_str() - add a new string to an expo
533 *
534 * @exp: Expo to update
535 * @name: Name to use (this is allocated by this call)
536 * @id: ID to use for the new object (0 to allocate one)
537 * @str: Pointer to text to display (allocated by caller)
538 * Returns: ID number for the object (typically @id), or -ve on error
539 */
540int expo_str(struct expo *exp, const char *name, uint id, const char *str);
541
542/**
543 * expo_get_str() - Get a string by ID
544 *
545 * @exp: Expo to use
546 * @id: String ID to look up
547 * @returns string, or NULL if not found
548 */
549const char *expo_get_str(struct expo *exp, uint id);
550
551/**
Simon Glassc5ae5b12025-05-02 08:46:40 -0600552 * expo_edit_str() - Make a string writeable
553 *
554 * This allows a string to be updated under the control of the caller. The
555 * buffer must remain valid while the expo is active.
556 *
557 * @exp: Expo to use
558 * @id: String ID to look up
559 * @orig: If non-NULL, returns the original buffer, which can be used by the
560 * caller. It is no-longer used by expo so must be uninited by the caller.
561 * It contains a snapshot of the string contents
562 * @copyp: Returns a pointer to the new, writeable buffer
563 * Return: 0 if OK, -ENOENT if the id was not found, -ENOMEM if out of memory
564 */
565int expo_edit_str(struct expo *exp, uint id, struct abuf *orig,
566 struct abuf **copyp);
567
568/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600569 * expo_set_display() - set the display to use for a expo
570 *
571 * @exp: Expo to update
572 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
573 * Returns: 0 (always)
574 */
575int expo_set_display(struct expo *exp, struct udevice *dev);
576
577/**
Simon Glass7a960052023-06-01 10:22:52 -0600578 * expo_calc_dims() - Calculate the dimensions of the objects
579 *
580 * Updates the width and height of all objects based on their contents
581 *
582 * @exp: Expo to update
583 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
584 */
585int expo_calc_dims(struct expo *exp);
586
587/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600588 * expo_set_scene_id() - Set the current scene ID
589 *
590 * @exp: Expo to update
591 * @scene_id: New scene ID to use (0 to select no scene)
592 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
593 */
594int expo_set_scene_id(struct expo *exp, uint scene_id);
595
596/**
Simon Glassc8925112023-06-01 10:23:02 -0600597 * expo_first_scene_id() - Get the ID of the first scene
598 *
599 * @exp: Expo to check
600 * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
601 */
602int expo_first_scene_id(struct expo *exp);
603
604/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600605 * expo_render() - render the expo on the display / console
606 *
607 * @exp: Expo to render
608 *
609 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
610 * current scene is not found, other error if something else goes wrong
611 */
612int expo_render(struct expo *exp);
613
614/**
Simon Glassb2c40342023-06-01 10:22:37 -0600615 * expo_set_text_mode() - Controls whether the expo renders in text mode
Simon Glassd8adbe92023-01-06 08:52:36 -0600616 *
617 * @exp: Expo to update
618 * @text_mode: true to use text mode, false to use the console
619 */
Simon Glassb2c40342023-06-01 10:22:37 -0600620void expo_set_text_mode(struct expo *exp, bool text_mode);
Simon Glassd8adbe92023-01-06 08:52:36 -0600621
622/**
623 * scene_new() - create a new scene in a expo
624 *
625 * The scene is given the ID @id which must be unique across all scenes, objects
626 * and items. The expo's @next_id is updated to at least @id + 1
627 *
628 * @exp: Expo to update
629 * @name: Name to use (this is allocated by this call)
630 * @id: ID to use for the new scene (0 to allocate one)
631 * @scnp: Returns a pointer to the new scene on success
632 * Returns: ID number for the scene (typically @id), or -ve on error
633 */
634int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
635
636/**
637 * expo_lookup_scene_id() - Look up a scene by ID
638 *
639 * @exp: Expo to check
640 * @scene_id: Scene ID to look up
641 * @returns pointer to scene if found, else NULL
642 */
643struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
644
645/**
Simon Glass01922ec2023-06-01 10:22:57 -0600646 * scene_highlight_first() - Highlight the first item in a scene
647 *
648 * This highlights the first item, so that the user can see that it is pointed
649 * to
650 *
651 * @scn: Scene to update
652 */
653void scene_highlight_first(struct scene *scn);
654
655/**
656 * scene_set_highlight_id() - Set the object which is highlighted
657 *
658 * Sets a new object to highlight in the scene
659 *
660 * @scn: Scene to update
661 * @id: ID of object to highlight
662 */
663void scene_set_highlight_id(struct scene *scn, uint id);
664
665/**
666 * scene_set_open() - Set whether an item is open or not
667 *
668 * @scn: Scene to update
669 * @id: ID of object to update
670 * @open: true to open the object, false to close it
671 * Returns: 0 if OK, -ENOENT if @id is invalid
672 */
673int scene_set_open(struct scene *scn, uint id, bool open);
674
675/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600676 * scene_obj_count() - Count the number of objects in a scene
677 *
678 * @scn: Scene to check
679 * Returns: number of objects in the scene, 0 if none
680 */
681int scene_obj_count(struct scene *scn);
682
683/**
684 * scene_img() - add a new image to a scene
685 *
686 * @scn: Scene to update
687 * @name: Name to use (this is allocated by this call)
688 * @id: ID to use for the new object (0 to allocate one)
689 * @data: Pointer to image data
690 * @imgp: If non-NULL, returns the new object
691 * Returns: ID number for the object (typically @id), or -ve on error
692 */
693int scene_img(struct scene *scn, const char *name, uint id, char *data,
694 struct scene_obj_img **imgp);
695
696/**
697 * scene_txt() - add a new text object to a scene
698 *
699 * @scn: Scene to update
700 * @name: Name to use (this is allocated by this call)
701 * @id: ID to use for the new object (0 to allocate one)
702 * @str_id: ID of the string to use
703 * @txtp: If non-NULL, returns the new object
704 * Returns: ID number for the object (typically @id), or -ve on error
705 */
706int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
707 struct scene_obj_txt **txtp);
708
709/**
Simon Glassdb6a0512023-10-01 19:13:23 -0600710 * scene_txt_str() - add a new string to expo and text object to a scene
Simon Glassd8adbe92023-01-06 08:52:36 -0600711 *
712 * @scn: Scene to update
713 * @name: Name to use (this is allocated by this call)
714 * @id: ID to use for the new object (0 to allocate one)
715 * @str_id: ID of the string to use
716 * @str: Pointer to text to display (allocated by caller)
717 * @txtp: If non-NULL, returns the new object
718 * Returns: ID number for the object (typically @id), or -ve on error
719 */
720int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
721 const char *str, struct scene_obj_txt **txtp);
722
723/**
724 * scene_menu() - create a menu
725 *
726 * @scn: Scene to update
727 * @name: Name to use (this is allocated by this call)
728 * @id: ID to use for the new object (0 to allocate one)
729 * @menup: If non-NULL, returns the new object
730 * Returns: ID number for the object (typically @id), or -ve on error
731 */
732int scene_menu(struct scene *scn, const char *name, uint id,
733 struct scene_obj_menu **menup);
734
735/**
Simon Glass6116e762023-10-01 19:13:32 -0600736 * scene_textline() - create a textline
737 *
738 * @scn: Scene to update
739 * @name: Name to use (this is allocated by this call)
740 * @id: ID to use for the new object (0 to allocate one)
741 * @max_chars: Maximum length of the textline in characters
742 * @tlinep: If non-NULL, returns the new object
743 * Returns: ID number for the object (typically @id), or -ve on error
744 */
745int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars,
746 struct scene_obj_textline **tlinep);
747
748/**
Simon Glass138a3972025-05-02 08:46:44 -0600749 * scene_box() - create a box
750 *
751 * @scn: Scene to update
752 * @name: Name to use (this is allocated by this call)
753 * @id: ID to use for the new object (0 to allocate one)
754 * @width: Line-width in pixels
755 * @boxp: If non-NULL, returns the new object
756 * Returns: ID number for the object (typically @id), or -ve on error
757 */
758int scene_box(struct scene *scn, const char *name, uint id, uint width,
759 struct scene_obj_box **boxp);
760
761/**
Simon Glass5dc887d2025-05-02 08:46:46 -0600762 * scene_texted() - create a text editor
763 *
764 * @scn: Scene to update
765 * @name: Name to use (this is allocated by this call)
766 * @id: ID to use for the new object (0 to allocate one)
767 * @strid: ID of the string to edit
768 * @teditp: If non-NULL, returns the new object
769 * Returns: ID number for the object (typically @id), or -ve on error
770 */
771int scene_texted(struct scene *scn, const char *name, uint id, uint strid,
772 struct scene_obj_txtedit **teditp);
773
774/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600775 * scene_txt_set_font() - Set the font for an object
776 *
777 * @scn: Scene to update
778 * @id: ID of object to update
779 * @font_name: Font name to use (allocated by caller)
780 * @font_size: Font size to use (nominal height in pixels)
781 */
782int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
783 uint font_size);
784
785/**
Simon Glass5dc887d2025-05-02 08:46:46 -0600786 * scene_txted_set_font() - Set the font for an object
787 *
788 * @scn: Scene to update
789 * @id: ID of object to update
790 * @font_name: Font name to use (allocated by caller)
791 * @font_size: Font size to use (nominal height in pixels)
792 */
793int scene_txted_set_font(struct scene *scn, uint id, const char *font_name,
794 uint font_size);
795
796/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600797 * scene_obj_set_pos() - Set the postion of an object
798 *
799 * @scn: Scene to update
800 * @id: ID of object to update
801 * @x: x position, in pixels from left side
802 * @y: y position, in pixels from top
803 * Returns: 0 if OK, -ENOENT if @id is invalid
804 */
805int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
806
807/**
Simon Glass7a960052023-06-01 10:22:52 -0600808 * scene_obj_set_size() - Set the size of an object
809 *
810 * @scn: Scene to update
811 * @id: ID of object to update
812 * @w: width in pixels
813 * @h: height in pixels
814 * Returns: 0 if OK, -ENOENT if @id is invalid
815 */
816int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
817
818/**
Simon Glassc6143dc2025-05-02 08:46:35 -0600819 * scene_obj_set_width() - Set the width of an object
820 *
821 * @scn: Scene to update
822 * @id: ID of object to update
823 * @w: width in pixels
824 * Returns: 0 if OK, -ENOENT if @id is invalid
825 */
826int scene_obj_set_width(struct scene *scn, uint id, int w);
827
828/**
829 * scene_obj_set_bbox() - Set the bounding box of an object
830 *
831 * @scn: Scene to update
832 * @id: ID of object to update
833 * @x0: x position, in pixels from left side
834 * @y0: y position, in pixels from top
835 * @x1: ending x position (right side)
836 * @y1: ending y position (botton side)
837 * Returns: 0 if OK, -ENOENT if @id is invalid
838 */
839int scene_obj_set_bbox(struct scene *scn, uint id, int x0, int y0, int x1,
840 int y1);
841
842/**
Simon Glass5beb0572025-05-02 08:46:45 -0600843 * scene_obj_set_halign() - Set the horizontal alignment of an object
844 *
845 * @scn: Scene to update
846 * @id: ID of object to update
847 * @aln: Horizontal alignment to use
848 * Returns: 0 if OK, -ENOENT if @id is invalid
849 */
850int scene_obj_set_halign(struct scene *scn, uint id, enum scene_obj_align aln);
851
852/**
853 * scene_obj_set_valign() - Set the vertical alignment of an object
854 *
855 * @scn: Scene to update
856 * @id: ID of object to update
857 * @aln: Vertical alignment to use
858 * Returns: 0 if OK, -ENOENT if @id is invalid
859 */
860int scene_obj_set_valign(struct scene *scn, uint id, enum scene_obj_align aln);
861
862/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600863 * scene_obj_set_hide() - Set whether an object is hidden
864 *
865 * The update happens when the expo is next rendered.
866 *
867 * @scn: Scene to update
868 * @id: ID of object to update
869 * @hide: true to hide the object, false to show it
870 * Returns: 0 if OK, -ENOENT if @id is invalid
871 */
872int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
873
874/**
875 * scene_menu_set_title() - Set the title of a menu
876 *
877 * @scn: Scene to update
878 * @id: ID of menu object to update
879 * @title_id: ID of text object to use as the title
880 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
881 */
882int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
883
884/**
885 * scene_menu_set_pointer() - Set the item pointer for a menu
886 *
887 * This is a visual indicator of the current item, typically a ">" character
888 * which sits next to the current item and moves when the user presses the
889 * up/down arrow keys
890 *
891 * @scn: Scene to update
892 * @id: ID of menu object to update
893 * @cur_item_id: ID of text or image object to use as a pointer to the current
894 * item
895 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
896 */
897int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
898
899/**
Simon Glassbe04b962025-05-02 08:46:24 -0600900 * scene_menu_select_item() - move the pointer/highlight to an item
901 *
902 * @scn: Scene to update
903 * @id: ID of menu object to update
904 * @sel_id: ID of the menuitem to select
905 * Return 0 on success, -ENOENT if there was no such item
906 */
907int scene_menu_select_item(struct scene *scn, uint id, uint sel_id);
908
909/**
910 * scene_menu_get_cur_item() - get the currently pointed-to item
911 *
912 * @scn: Scene to update
913 * @id: ID of menu object to update
914 * Return ID of the current item the menu is pointing to, -ENOENT if @id is not
915 * valid, 0 if no item is pointed to
916 */
917int scene_menu_get_cur_item(struct scene *scn, uint id);
918
919/**
Simon Glassd8adbe92023-01-06 08:52:36 -0600920 * scene_obj_get_hw() - Get width and height of an object in a scene
921 *
922 * @scn: Scene to check
923 * @id: ID of menu object to check
924 * @widthp: If non-NULL, returns width of object in pixels
925 * Returns: Height of object in pixels
926 */
927int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
928
929/**
930 * scene_menuitem() - Add an item to a menu
931 *
932 * @scn: Scene to update
933 * @menu_id: ID of menu object to update
934 * @name: Name to use (this is allocated by this call)
935 * @id: ID to use for the new object (0 to allocate one)
936 * @key_id: ID of text object to use as the keypress to show
937 * @label_id: ID of text object to use as the label text
938 * @desc_id: ID of text object to use as the description text
939 * @preview_id: ID of object to use as the preview (text or image)
940 * @flags: Flags for this item (enum scene_menuitem_flags_t)
941 * @itemp: If non-NULL, returns the new object
942 * Returns: ID number for the item (typically @id), or -ve on error
943 */
944int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
945 uint key_id, uint label_id, uint desc_id, uint preview_id,
946 uint flags, struct scene_menitem **itemp);
947
948/**
949 * scene_arrange() - Arrange the scene to deal with object sizes
950 *
951 * Updates any menus in the scene so that their objects are in the right place.
952 *
953 * @scn: Scene to arrange
954 * Returns: 0 if OK, -ve on error
955 */
956int scene_arrange(struct scene *scn);
957
958/**
959 * expo_send_key() - set a keypress to the expo
960 *
961 * @exp: Expo to receive the key
962 * @key: Key to send (ASCII or enum bootmenu_key)
963 * Returns: 0 if OK, -ECHILD if there is no current scene
964 */
965int expo_send_key(struct expo *exp, int key);
966
967/**
968 * expo_action_get() - read user input from the expo
969 *
970 * @exp: Expo to check
971 * @act: Returns action
972 * Returns: 0 if OK, -EAGAIN if there was no action to return
973 */
974int expo_action_get(struct expo *exp, struct expo_action *act);
975
Simon Glassc999e172023-06-01 10:22:53 -0600976/**
977 * expo_apply_theme() - Apply a theme to an expo
978 *
979 * @exp: Expo to update
980 * @node: Node containing the theme
981 */
982int expo_apply_theme(struct expo *exp, ofnode node);
983
Simon Glass61300722023-06-01 10:23:01 -0600984/**
985 * expo_build() - Build an expo from an FDT description
986 *
987 * Build a complete expo from a description in the provided devicetree.
988 *
Massimo Pegorerc8c70022023-09-09 12:32:28 +0200989 * See doc/develop/expo.rst for a description of the format
Simon Glass61300722023-06-01 10:23:01 -0600990 *
991 * @root: Root node for expo description
992 * @expp: Returns the new expo
993 * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
994 * error, -ENOENT if there is a references to a non-existent string
995 */
996int expo_build(ofnode root, struct expo **expp);
997
Simon Glass34344202024-10-14 16:32:11 -0600998/**
999 * cb_expo_build() - Build an expo for coreboot CMOS RAM
1000 *
1001 * @expp: Returns the expo created
1002 * Return: 0 if OK, -ve on error
1003 */
1004int cb_expo_build(struct expo **expp);
1005
Simon Glass137b4422025-05-02 08:46:16 -06001006/**
1007 * expo_poll() - render an expo and see if the user takes an action
1008 *
1009 * Thsi calls expo_render() and then checks for a keypress. If there is one, it
1010 * is processed and the resulting action returned, if any
1011 *
1012 * @exp: Expo to poll
1013 * @act: Returns action on success
1014 * Return: 0 if an action was obtained, -EAGAIN if not, other error if something
1015 * went wrong
1016 */
1017int expo_poll(struct expo *exp, struct expo_action *act);
1018
Simon Glass8df4a4e2023-08-14 16:40:25 -06001019#endif /*__EXPO_H */