summaryrefslogtreecommitdiff
path: root/src/bin/elementary/test_efl_ui_text.c
blob: 40b88bf9da0c7332856b4d695f2289785eaf0650 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#define EO_BETA_API
#include <Efl_Ui.h>
#include <Elementary.h>
#include "elm_priv.h" //FIXME remove this once efl.ui.text doesn't need elm_general.h

static void
_apply_style(Eo *obj, size_t start_pos, size_t end_pos, const char *style)
{
   Efl_Text_Cursor *start, *end;

   start = efl_ui_textbox_cursor_create(obj);
   end = efl_ui_textbox_cursor_create(obj);

   efl_text_cursor_position_set(start, start_pos);
   efl_text_cursor_position_set(end, end_pos);

   efl_text_attribute_factory_attribute_insert(start, end, style);

   efl_del(start);
   efl_del(end);
}

static Eo *
_create_label(Eo *win, Eo *bx)
{
   Eo *en;
   en = efl_add(EFL_UI_TEXTBOX_CLASS, win);
   printf("Added Efl.Ui.Textbox object\n");
   efl_text_interactive_editable_set(en, EINA_FALSE);
   efl_pack(bx, en);
   return en;
}


void
test_efl_ui_text_label(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win, *bx;
   Eo *en;
   char *markup;

   win = efl_add_ref(EFL_UI_WIN_CLASS, NULL,
                  efl_text_set(efl_added, "Efl Canvas_Layout"),
         efl_ui_win_autodel_set(efl_added, EINA_TRUE));

   bx = efl_add(EFL_UI_BOX_CLASS, win);
   efl_content_set(win, bx);

   en = _create_label(win, bx);
   efl_text_set(en, "This is a\t small label");
   //                012345678901234567890
   _apply_style(en, 0, 21, "font_size=12 font_weight=bold");
   efl_text_font_weight_set(en, EFL_TEXT_FONT_WEIGHT_BOLD);

   en = _create_label(win, bx);
   efl_text_set(en, "This is a text. It is longer but its size is taken as the"
         " min size so that it shows in whole");
   _apply_style(en, 40, 45, "font_weight=bold color=#ff0");
   _apply_style(en, 52, 58, "font_weight=italic color=#f00");

   en = _create_label(win, bx);
   efl_text_set(en, "By default 'multiline' is disabled.\n"
         "So, \\n would only work if you enable it.");

   en = _create_label(win, bx);
   efl_text_markup_set(en, "You can also <b>ENTER</b> markup!");
   efl_text_font_family_set(en, "Sans");
   efl_text_font_size_set(en, 14);
   efl_text_wrap_set(en, EFL_TEXT_FORMAT_WRAP_WORD);
   efl_text_multiline_set(en, EINA_TRUE);

   en = _create_label(win, bx);
   markup = efl_text_markup_util_text_to_markup(
         "You can use the text -> markup helper\nto make coding easier.");
   efl_text_markup_set(en, markup);
   free(markup);
   efl_text_font_family_set(en, "Sans");
   efl_text_font_size_set(en, 14);
   efl_text_wrap_set(en, EFL_TEXT_FORMAT_WRAP_WORD);
   efl_text_multiline_set(en, EINA_TRUE);

   en = _create_label(win, bx);
   markup = efl_text_markup_util_markup_to_text(
         "You can use markup -&gt; text helpers<ps>to make coding easier.");
   efl_text_set(en, markup);
   free(markup);
   efl_text_font_family_set(en, "Sans");
   efl_text_font_size_set(en, 14);
   efl_text_wrap_set(en, EFL_TEXT_FORMAT_WRAP_WORD);
   efl_text_multiline_set(en, EINA_TRUE);
}

typedef struct
{
   const char *wrap_mode[4];
   size_t cur_wrap;
} Test_Data;

static void
_on_bt3_clicked(void *data, const Efl_Event *event EINA_UNUSED)
{
   Efl_Text_Cursor *sel_start, *sel_end;
   Eo *en = data;

   efl_text_interactive_selection_cursors_get(en, &sel_start, &sel_end);
   const char *s = efl_text_cursor_range_text_get(sel_start, sel_end);

   printf("SELECTION REGION: %d - %d\n",
         efl_text_cursor_position_get( sel_start),
         efl_text_cursor_position_get(sel_end));
   printf("SELECTION:\n");
   if (s) printf("%s\n", s);
}

static void
_on_bt6_clicked(void *data, const Efl_Event *event EINA_UNUSED)
{
   Eo *text_obj = data;

   Efl_Text_Format_Wrap wrap = efl_text_wrap_get(text_obj);

   switch(wrap)
     {
      case EFL_TEXT_FORMAT_WRAP_NONE:
         wrap = EFL_TEXT_FORMAT_WRAP_CHAR;
         break;
      case EFL_TEXT_FORMAT_WRAP_CHAR:
         wrap = EFL_TEXT_FORMAT_WRAP_WORD;
         break;
      case EFL_TEXT_FORMAT_WRAP_WORD:
         wrap = EFL_TEXT_FORMAT_WRAP_MIXED;
         break;
      case EFL_TEXT_FORMAT_WRAP_MIXED:
         wrap = EFL_TEXT_FORMAT_WRAP_NONE;
         break;
      default:
         break;
     }
   efl_text_wrap_set(text_obj, wrap);
}

void
test_efl_ui_text(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eo *win, *bx, *bx2, *en;
   Eo *bt;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                  efl_text_set(efl_added, "Efl Ui Text"),
         efl_ui_win_autodel_set(efl_added, EINA_TRUE));

   bx = efl_add(EFL_UI_BOX_CLASS, win);
   efl_gfx_hint_weight_set(bx, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
   efl_content_set(win, bx);

   en = efl_add(EFL_UI_TEXTBOX_CLASS, bx,
         efl_text_multiline_set(efl_added, EINA_TRUE));

   printf("Added Efl.Ui.Textbox object\n");

   efl_text_interactive_editable_set(en, EINA_TRUE);
   efl_ui_textbox_scrollable_set(en, EINA_TRUE);

   efl_text_font_family_set(en, "Sans");
   efl_text_font_size_set(en, 12);
   efl_text_font_width_set(en, EFL_TEXT_FONT_WIDTH_ULTRACONDENSED);
   efl_text_normal_color_set(en, 255, 255, 255, 255);

   efl_text_set(en,
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\n"
      "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim\n"
      "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea\n"
      "commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate\n"
      "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\n"
      "occaecat cupidatat non proident, sunt in culpa qui officia deserunt\n"
      "mollit anim id est laborum");

   efl_gfx_hint_size_min_set(en, EINA_SIZE2D(300, 100));
   efl_pack(bx, en);

   bx2 = efl_add(EFL_UI_BOX_CLASS, bx);
   efl_gfx_hint_weight_set(bx2, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
   efl_ui_layout_orientation_set(bx2, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL);

   bt = efl_add(EFL_UI_BUTTON_CLASS, bx2);
   efl_text_set(bt, "Sel");
   efl_event_callback_add(bt, EFL_INPUT_EVENT_CLICKED, _on_bt3_clicked, en);
   efl_gfx_hint_weight_set(bt, EFL_GFX_HINT_EXPAND, 0.0);
   efl_pack(bx2, bt);
   elm_object_focus_allow_set(bt, EINA_FALSE);

   bt = efl_add(EFL_UI_BUTTON_CLASS, bx2);
   efl_text_set(bt, "Wr");
   efl_event_callback_add(bt, EFL_INPUT_EVENT_CLICKED, _on_bt6_clicked, en);
   efl_gfx_hint_weight_set(bt, EFL_GFX_HINT_EXPAND, 0.0);
   efl_pack(bx2, bt);
   elm_object_focus_allow_set(bt, EINA_FALSE);

   efl_pack(bx, bx2);
}

void
test_efl_ui_text_inputfield(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eo *win, *bx, *en;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                  efl_text_set(efl_added, "Efl Ui Text Input Field"),
         efl_ui_win_autodel_set(efl_added, EINA_TRUE));

   bx = efl_add(EFL_UI_BOX_CLASS, win);
   efl_gfx_hint_weight_set(bx, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
   efl_content_set(win, bx);

   en = efl_add(EFL_UI_TEXTBOX_CLASS, bx,
         efl_text_multiline_set(efl_added, EINA_FALSE));

   efl_text_interactive_editable_set(en, EINA_TRUE);
   efl_ui_textbox_scrollable_set(en, EINA_TRUE);

   printf("Added Efl.Ui.Textbox object\n");
   efl_text_font_width_set(en, EFL_TEXT_FONT_WIDTH_ULTRACONDENSED);
   efl_text_set(efl_part(en, "efl.text_guide"), "Enter you name here");

   efl_pack(bx, en);

   en = _create_label(win, bx);
   efl_text_set(en, "This is a multiline input.\n"
         "Enter multiline here");
   efl_text_interactive_editable_set(en, EINA_TRUE);
   efl_text_wrap_set(en, EFL_TEXT_FORMAT_WRAP_WORD);
   efl_text_multiline_set(en, EINA_TRUE);
   efl_ui_textbox_scrollable_set(en, EINA_TRUE);
   evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0.5);
   efl_pack(bx, en);

   efl_gfx_entity_size_set(win, EINA_SIZE2D(300, 200));

}