1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Implementation of a menu in a scene
4 *
5 * Copyright 2025 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9 #define LOG_CATEGORY LOGC_EXPO
10
11 #include <expo.h>
12 #include <log.h>
13 #include <linux/err.h>
14 #include <linux/sizes.h>
15 #include "scene_internal.h"
16
17 enum {
18 INITIAL_SIZE = SZ_4K,
19 };
20
scene_texted(struct scene * scn,const char * name,uint id,uint str_id,struct scene_obj_txtedit ** teditp)21 int scene_texted(struct scene *scn, const char *name, uint id, uint str_id,
22 struct scene_obj_txtedit **teditp)
23 {
24 struct scene_obj_txtedit *ted;
25 char *buf;
26 int ret;
27
28 ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXTEDIT,
29 sizeof(struct scene_obj_txtedit),
30 (struct scene_obj **)&ted);
31 if (ret < 0)
32 return log_msg_ret("obj", ret);
33
34 abuf_init(&ted->buf);
35 if (!abuf_realloc(&ted->buf, INITIAL_SIZE))
36 return log_msg_ret("buf", -ENOMEM);
37 buf = abuf_data(&ted->buf);
38 *buf = '\0';
39
40 ret = scene_txt_generic_init(scn->expo, &ted->gen, name, str_id, buf);
41 if (ret)
42 return log_msg_ret("teg", ret);
43 if (teditp)
44 *teditp = ted;
45
46 return ted->obj.id;
47 }
48
scene_txted_set_font(struct scene * scn,uint id,const char * font_name,uint font_size)49 int scene_txted_set_font(struct scene *scn, uint id, const char *font_name,
50 uint font_size)
51 {
52 struct scene_obj_txtedit *ted;
53
54 ted = scene_obj_find(scn, id, SCENEOBJT_TEXTEDIT);
55 if (!ted)
56 return log_msg_ret("find", -ENOENT);
57 ted->gen.font_name = font_name;
58 ted->gen.font_size = font_size;
59
60 return 0;
61 }
62