blob: 823648b0e3c31b0f45739e26d7a617c1f4ccb739 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/******************************************************************************
2*(C) Copyright 2014 Marvell International Ltd.
3* All Rights Reserved
4******************************************************************************/
5/*******************************************************************************
6 *
7 * Filename: TextBox.c
8 *
9 * Authors: Boaz Sommer
10 *
11 * Description: A Text Box class
12 *
13 * HISTORY:
14 *
15 *
16 *
17 * Notes:
18 *
19 ******************************************************************************/
20#include <stdarg.h>
21#include <stdlib.h>
22#include <string.h>
23#include "TextBox.h"
24#include "String.h"
25#include "mgui_utils.h"
26
27typedef struct S_TEXTBOX_PRIV
28{
29 void *dfb;
30 STRING *string;
31 OBJECT_COLOR color;
32 OBJECT_POS pos;
33 int size;
34 void *h;
35}TEXTBOX_PRIV;
36
37TEXTBOX *TextBoxInit (void *dfb, int height, int width, const char *font_path)
38{
39 TEXTBOX_PRIV *textbox = calloc(1, sizeof(*textbox));
40 //OBJECT_SCREEN dim;
41
42 textbox->dfb = dfb;
43 GuiAddObject(dfb, textbox, (ObjectDrawFunc)TextBoxDraw);
44 textbox->string = StringInit(0);
45
46 //dim.height = height;
47 //dim.width = width;
48 textbox->h = lvgl_create_textbox();
49 return (TEXTBOX *)textbox;
50}
51void TextBoxDeinit (TEXTBOX *pt)
52{
53 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
54 if (pt)
55 {
56 StringDeinit(textbox->string);
57 GuiRemoveObject(textbox->dfb, textbox);
58 free (pt);
59 pt = NULL;
60 }
61}
62
63char *TextBoxGetText(TEXTBOX *pt)
64{
65 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
66
67 if (textbox)
68 return StringGet(textbox->string);
69
70 return NULL;
71}
72
73void TextBoxSetText (TEXTBOX *pt, const char *text)
74{
75 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
76
77
78 if (textbox)
79 {
80 if (text)
81 {
82 StringSet(textbox->string, text);
83 }
84 }
85}
86
87void TextBoxSetup(TEXTBOX *pt, const char *text, int x, int y, TEXTALIGN align, unsigned int argb)
88{
89 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
90
91
92 if (textbox)
93 {
94 if (text)
95 {
96 StringSet(textbox->string, text);
97 }
98
99 textbox->pos.x = x;
100 textbox->pos.y = y;
101 textbox->pos.align = align;
102 textbox->color = to_object_color(argb);
103 }
104}
105
106void TextBoxSetColor (TEXTBOX *pt, unsigned int argb)
107{
108 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
109 if (textbox)
110 {
111 textbox->color = to_object_color(argb);
112 }
113}
114
115void TextBoxDraw (TEXTBOX *pt)
116{
117 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
118 char *text;
119
120 if (textbox)
121 {
122 text = StringGet(textbox->string);
123 if (text)
124 GuiDrawText(textbox->dfb, textbox->h, text, &textbox->color, &textbox->pos);
125 }
126}
127
128int TextBoxGetWidth (TEXTBOX *pt)
129{
130 TEXTBOX_PRIV *textbox = (TEXTBOX_PRIV *)pt;
131 int width = 0;
132
133 if (textbox)
134 {
135 width = GuiGetTextWidth(textbox->dfb, StringGet(textbox->string));
136 }
137
138 return width;
139}
140