Merge the ClutterText actor
Merge branch 'text-actor' * text-actor: (108 commits) Re-align ClutterText header file [text] Fix cursor sizing Comments and whitespace fixes to ClutterText [docs] Add newly added :single-line-mode accessors Update the ignore file [tests] Add text field interactive test [text] Add single-line-mode to ClutterText [text] Fix the deletion actions [text] Use cached length when possible [tests] Add unit for the ClutterText:password-char property [docs] Update the Text section [text] Coalesce text visibility and password character Allow localizations to change the text direction Clean up the update_pango_context() function Pass the PangoContext, not the MainContext Revert the logic of the PangoContext check Remove the binding pool entry from the list Remove BindingPool::list_actions() Add ClutterActor::create_pango_context() Rename the PangoContext creation functions ...
This commit is contained in:
@@ -17,15 +17,15 @@ test_conformance_SOURCES = \
|
||||
test-mesh-mutability.c \
|
||||
test-path.c \
|
||||
test-pick.c \
|
||||
test-label-cache.c \
|
||||
test-clutter-entry.c \
|
||||
test-clutter-rectangle.c \
|
||||
test-clutter-fixed.c \
|
||||
test-actor-invariants.c \
|
||||
test-paint-opacity.c \
|
||||
test-backface-culling.c \
|
||||
test-binding-pool.c \
|
||||
$(NULL)
|
||||
test-clutter-text.c \
|
||||
test-text-cache.c \
|
||||
$(NULL)
|
||||
|
||||
# For convenience, this provides a way to easily run individual unit tests:
|
||||
.PHONY: wrappers clean-wrappers
|
||||
|
@@ -1,370 +0,0 @@
|
||||
#include <glib.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-conform-common.h"
|
||||
|
||||
typedef struct {
|
||||
gunichar unichar;
|
||||
const char bytes[6];
|
||||
gint nbytes;
|
||||
} TestData;
|
||||
|
||||
const TestData
|
||||
test_data[] = {
|
||||
{ 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
|
||||
{ 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */
|
||||
};
|
||||
|
||||
void
|
||||
test_entry_utf8_validation (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
gunichar unichar;
|
||||
char bytes[6];
|
||||
int nbytes;
|
||||
|
||||
g_assert (g_unichar_validate (t->unichar));
|
||||
|
||||
nbytes = g_unichar_to_utf8 (t->unichar, bytes);
|
||||
bytes[nbytes] = '\0';
|
||||
g_assert (nbytes == t->nbytes);
|
||||
g_assert (memcmp (t->bytes, bytes, nbytes) == 0);
|
||||
|
||||
unichar = g_utf8_get_char_validated (bytes, nbytes);
|
||||
g_assert (unichar == t->unichar);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
get_nbytes (ClutterEntry *entry)
|
||||
{
|
||||
const char *s = clutter_entry_get_text (entry);
|
||||
return strlen (s);
|
||||
}
|
||||
|
||||
static int
|
||||
get_nchars (ClutterEntry *entry)
|
||||
{
|
||||
const char *s = clutter_entry_get_text (entry);
|
||||
g_assert (g_utf8_validate (s, -1, NULL));
|
||||
return g_utf8_strlen (s, -1);
|
||||
}
|
||||
|
||||
#define DONT_MOVE_CURSOR (-2)
|
||||
|
||||
static void
|
||||
insert_unichar (ClutterEntry *entry, gunichar unichar, int position)
|
||||
{
|
||||
if (position > DONT_MOVE_CURSOR)
|
||||
{
|
||||
clutter_entry_set_cursor_position (entry, position);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, position);
|
||||
}
|
||||
|
||||
clutter_entry_insert_unichar (entry, unichar);
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
|
||||
g_assert (clutter_entry_get_text (entry) == NULL);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_set_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
|
||||
/* annoyingly slightly different from initially empty */
|
||||
clutter_entry_set_text (entry, "");
|
||||
g_assert_cmpint (get_nchars (entry), ==, 0);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 0);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_set_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
|
||||
clutter_entry_set_text (entry, "abcdef");
|
||||
g_assert_cmpint (get_nchars (entry), ==, 6);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 6);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 5);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 5);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_append_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 1; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (entry, t->unichar, DONT_MOVE_CURSOR);
|
||||
g_assert_cmpint (get_nchars (entry), ==, j);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
}
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_prepend_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
for (j = 2; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (entry, t->unichar, 0);
|
||||
g_assert_cmpint (get_nchars (entry), ==, j);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
}
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_insert (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
insert_unichar (entry, t->unichar, 1);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 2);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_delete_chars (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 2);
|
||||
clutter_entry_delete_chars (entry, 1);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 2);
|
||||
clutter_entry_delete_chars (entry, 1);
|
||||
g_assert_cmpint (get_nchars (entry), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 2 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_delete_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 3);
|
||||
clutter_entry_delete_text (entry, 2, 4);
|
||||
|
||||
g_assert_cmpint (get_nchars (entry), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 2 * t->nbytes);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
static void
|
||||
init_event (ClutterKeyEvent *event)
|
||||
{
|
||||
event->type = CLUTTER_KEY_PRESS;
|
||||
event->time = 0; /* not needed */
|
||||
event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC;
|
||||
event->stage = NULL; /* not needed */
|
||||
event->source = NULL; /* not needed */
|
||||
event->modifier_state = 0;
|
||||
event->hardware_keycode = 0; /* not needed */
|
||||
}
|
||||
|
||||
static void
|
||||
send_keyval (ClutterEntry *entry, int keyval)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = keyval;
|
||||
event.unicode_value = 0; /* should be ignored for cursor keys etc. */
|
||||
|
||||
clutter_entry_handle_key_event (entry, &event);
|
||||
}
|
||||
|
||||
static inline void
|
||||
send_unichar (ClutterEntry *entry, gunichar unichar)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = 0; /* should be ignored for printable characters */
|
||||
event.unicode_value = unichar;
|
||||
|
||||
clutter_entry_handle_key_event (entry, &event);
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_cursor (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; ++j)
|
||||
clutter_entry_insert_unichar (entry, t->unichar);
|
||||
|
||||
clutter_entry_set_cursor_position (entry, 2);
|
||||
|
||||
/* test cursor moves and is clamped */
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 0);
|
||||
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 0);
|
||||
|
||||
/* delete text containing the cursor */
|
||||
clutter_entry_set_cursor_position (entry, 3);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 3);
|
||||
|
||||
clutter_entry_delete_text (entry, 2, 4);
|
||||
send_keyval (entry, CLUTTER_Left);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
||||
void
|
||||
test_entry_event (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); i++)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
|
||||
send_unichar (entry, t->unichar);
|
||||
|
||||
g_assert_cmpint (get_nchars (entry), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
|
||||
clutter_entry_set_text (entry, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (entry));
|
||||
}
|
||||
|
431
tests/conform/test-clutter-text.c
Normal file
431
tests/conform/test-clutter-text.c
Normal file
@@ -0,0 +1,431 @@
|
||||
#include <glib.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test-conform-common.h"
|
||||
|
||||
typedef struct {
|
||||
gunichar unichar;
|
||||
const char bytes[6];
|
||||
gint nbytes;
|
||||
} TestData;
|
||||
|
||||
static const TestData
|
||||
test_text_data[] = {
|
||||
{ 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
|
||||
{ 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */
|
||||
};
|
||||
|
||||
void
|
||||
test_text_utf8_validation (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
gunichar unichar;
|
||||
char bytes[6];
|
||||
int nbytes;
|
||||
|
||||
g_assert (g_unichar_validate (t->unichar));
|
||||
|
||||
nbytes = g_unichar_to_utf8 (t->unichar, bytes);
|
||||
bytes[nbytes] = '\0';
|
||||
g_assert (nbytes == t->nbytes);
|
||||
g_assert (memcmp (t->bytes, bytes, nbytes) == 0);
|
||||
|
||||
unichar = g_utf8_get_char_validated (bytes, nbytes);
|
||||
g_assert (unichar == t->unichar);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
get_nbytes (ClutterText *text)
|
||||
{
|
||||
const char *s = clutter_text_get_text (text);
|
||||
return strlen (s);
|
||||
}
|
||||
|
||||
static int
|
||||
get_nchars (ClutterText *text)
|
||||
{
|
||||
const char *s = clutter_text_get_text (text);
|
||||
g_assert (g_utf8_validate (s, -1, NULL));
|
||||
return g_utf8_strlen (s, -1);
|
||||
}
|
||||
|
||||
#define DONT_MOVE_CURSOR (-2)
|
||||
|
||||
static void
|
||||
insert_unichar (ClutterText *text, gunichar unichar, int position)
|
||||
{
|
||||
if (position > DONT_MOVE_CURSOR)
|
||||
{
|
||||
clutter_text_set_cursor_position (text, position);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, position);
|
||||
}
|
||||
|
||||
clutter_text_insert_unichar (text, unichar);
|
||||
}
|
||||
|
||||
void
|
||||
test_text_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "");
|
||||
g_assert_cmpint (*clutter_text_get_text (text), ==, '\0');
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_set_empty (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
/* annoyingly slightly different from initially empty */
|
||||
clutter_text_set_text (text, "");
|
||||
g_assert_cmpint (get_nchars (text), ==, 0);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 0);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_set_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
clutter_text_set_text (text, "abcdef");
|
||||
g_assert_cmpint (get_nchars (text), ==, 6);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 6);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_text_set_cursor_position (text, 5);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 5);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
clutter_text_set_text (text, "");
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_append_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 1; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (text, t->unichar, DONT_MOVE_CURSOR);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, j);
|
||||
g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
}
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_prepend_some (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
for (j = 2; j <= 4; j++)
|
||||
{
|
||||
insert_unichar (text, t->unichar, 0);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, j);
|
||||
g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
}
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_insert (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
insert_unichar (text, t->unichar, 1);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 2);
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_delete_chars (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
clutter_text_set_cursor_position (text, 2);
|
||||
clutter_text_delete_chars (text, 1);
|
||||
g_assert_cmpint (get_nchars (text), ==, 3);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
|
||||
clutter_text_set_cursor_position (text, 2);
|
||||
clutter_text_delete_chars (text, 1);
|
||||
g_assert_cmpint (get_nchars (text), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_get_chars (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
gchar *chars;
|
||||
|
||||
clutter_text_set_text (text, "00abcdef11");
|
||||
g_assert_cmpint (get_nchars (text), ==, 10);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 10);
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "00abcdef11");
|
||||
|
||||
chars = clutter_text_get_chars (text, 2, -1);
|
||||
g_assert_cmpstr (chars, ==, "abcdef11");
|
||||
g_free (chars);
|
||||
|
||||
chars = clutter_text_get_chars (text, 0, 8);
|
||||
g_assert_cmpstr (chars, ==, "00abcdef");
|
||||
g_free (chars);
|
||||
|
||||
chars = clutter_text_get_chars (text, 2, 8);
|
||||
g_assert_cmpstr (chars, ==, "abcdef");
|
||||
g_free (chars);
|
||||
|
||||
chars = clutter_text_get_chars (text, 8, 12);
|
||||
g_assert_cmpstr (chars, ==, "11");
|
||||
g_free (chars);
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_delete_text (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
clutter_text_set_cursor_position (text, 3);
|
||||
clutter_text_delete_text (text, 2, 4);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 2);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_password_char (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
|
||||
g_assert_cmpint (clutter_text_get_password_char (text), ==, 0);
|
||||
|
||||
clutter_text_set_text (text, "hello");
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "hello");
|
||||
|
||||
clutter_text_set_password_char (text, '*');
|
||||
g_assert_cmpint (clutter_text_get_password_char (text), ==, '*');
|
||||
|
||||
g_assert_cmpstr (clutter_text_get_text (text), ==, "hello");
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
static void
|
||||
init_event (ClutterKeyEvent *event)
|
||||
{
|
||||
event->type = CLUTTER_KEY_PRESS;
|
||||
event->time = 0; /* not needed */
|
||||
event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC;
|
||||
event->stage = NULL; /* not needed */
|
||||
event->source = NULL; /* not needed */
|
||||
event->modifier_state = 0;
|
||||
event->hardware_keycode = 0; /* not needed */
|
||||
}
|
||||
|
||||
static void
|
||||
send_keyval (ClutterText *text, int keyval)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = keyval;
|
||||
event.unicode_value = 0; /* should be ignored for cursor keys etc. */
|
||||
|
||||
clutter_actor_event (CLUTTER_ACTOR (text), (ClutterEvent *) &event, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
send_unichar (ClutterText *text, gunichar unichar)
|
||||
{
|
||||
ClutterKeyEvent event;
|
||||
|
||||
init_event (&event);
|
||||
event.keyval = 0; /* should be ignored for printable characters */
|
||||
event.unicode_value = unichar;
|
||||
|
||||
clutter_actor_event (CLUTTER_ACTOR (text), (ClutterEvent *) &event, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
test_text_cursor (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
/* only editable entries listen to events */
|
||||
clutter_text_set_editable (text, TRUE);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; ++j)
|
||||
clutter_text_insert_unichar (text, t->unichar);
|
||||
|
||||
clutter_text_set_cursor_position (text, 2);
|
||||
|
||||
/* test cursor moves and is clamped */
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
||||
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0);
|
||||
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0);
|
||||
|
||||
/* delete text containing the cursor */
|
||||
clutter_text_set_cursor_position (text, 3);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 3);
|
||||
|
||||
clutter_text_delete_text (text, 2, 4);
|
||||
send_keyval (text, CLUTTER_Left);
|
||||
|
||||
/* FIXME: cursor position should be -1?
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
*/
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
||||
void
|
||||
test_text_event (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
||||
int i;
|
||||
|
||||
/* only editable entries listen to events */
|
||||
clutter_text_set_editable (text, TRUE);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
||||
{
|
||||
const TestData *t = &test_text_data[i];
|
||||
|
||||
send_unichar (text, t->unichar);
|
||||
|
||||
g_assert_cmpint (get_nchars (text), ==, 1);
|
||||
g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes);
|
||||
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
||||
|
||||
clutter_text_set_text (text, "");
|
||||
}
|
||||
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
||||
}
|
||||
|
@@ -68,22 +68,21 @@ main (int argc, char **argv)
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/picking", test_pick);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/label", test_label_cache);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_utf8_validation);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_empty);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_set_empty);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_set_text);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_append_some);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_prepend_some);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_insert);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_delete_chars);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_delete_text);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_cursor);
|
||||
TEST_CONFORM_SIMPLE ("/entry", test_entry_event);
|
||||
/* ClutterText */
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_utf8_validation);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_empty);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_set_empty);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_set_text);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_append_some);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_prepend_some);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_insert);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_delete_chars);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_delete_text);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_cursor);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_event);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_get_chars);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_cache);
|
||||
TEST_CONFORM_SIMPLE ("/text", test_text_password_char);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_size);
|
||||
TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color);
|
||||
|
@@ -14,12 +14,12 @@ test_label_opacity (TestConformSimpleFixture *fixture,
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
|
||||
label = clutter_label_new_with_text ("Sans 18px", "Label, 50% opacity");
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
|
||||
label = clutter_text_new_with_text ("Sans 18px", "Label, 50% opacity");
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_color()/1\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (stage), label, NULL);
|
||||
@@ -27,12 +27,16 @@ test_label_opacity (TestConformSimpleFixture *fixture,
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_color()/2\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (label));
|
||||
g_print ("label 50%%.get_paint_opacity()/1\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 255);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%%.get_paint_opacity()/2\n");
|
||||
clutter_actor_set_opacity (label, 128);
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 128);
|
||||
|
||||
clutter_actor_destroy (label);
|
||||
@@ -66,8 +70,7 @@ test_rectangle_opacity (TestConformSimpleFixture *fixture,
|
||||
g_assert (color_check.alpha == rect_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("rect 100%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (rect));
|
||||
g_print ("rect 100%%.get_paint_opacity()\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (rect) == 255);
|
||||
|
||||
clutter_actor_destroy (rect);
|
||||
@@ -91,25 +94,24 @@ test_paint_opacity (TestConformSimpleFixture *fixture,
|
||||
clutter_actor_set_position (group1, 10, 30);
|
||||
clutter_actor_show (group1);
|
||||
|
||||
label = clutter_label_new_with_text ("Sans 18px", "Label+Group, 25% opacity");
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
|
||||
label = clutter_text_new_with_text ("Sans 18px", "Label+Group, 25% opacity");
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%% + group 50%%.get_color()/1\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (group1), label, NULL);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%% + group 50%%.get_color()/2\n");
|
||||
clutter_label_get_color (CLUTTER_LABEL (label), &color_check);
|
||||
clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
|
||||
g_assert (color_check.alpha == label_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("label 50%% + group 50%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (label));
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 64);
|
||||
g_print ("label 50%% + group 50%%.get_paint_opacity() = 128\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (label) == 128);
|
||||
|
||||
clutter_actor_destroy (label);
|
||||
|
||||
@@ -133,9 +135,7 @@ test_paint_opacity (TestConformSimpleFixture *fixture,
|
||||
g_assert (color_check.alpha == rect_color.alpha);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("rect 100%%.get_paint_opacity() = %d\n",
|
||||
clutter_actor_get_paint_opacity (rect));
|
||||
|
||||
g_print ("rect 100%%.get_paint_opacity()\n");
|
||||
g_assert (clutter_actor_get_paint_opacity (rect) == 128);
|
||||
|
||||
clutter_actor_destroy (rect);
|
||||
|
@@ -34,7 +34,7 @@ on_paint (ClutterActor *label, CallbackData *data)
|
||||
|
||||
/* Check whether the layout used for this paint is different from
|
||||
the layout used for the last paint */
|
||||
new_layout = clutter_label_get_layout (CLUTTER_LABEL (data->label));
|
||||
new_layout = clutter_text_get_layout (CLUTTER_TEXT (data->label));
|
||||
data->layout_changed = data->old_layout != new_layout;
|
||||
|
||||
if (data->old_layout)
|
||||
@@ -71,7 +71,17 @@ check_result (CallbackData *data, const char *note,
|
||||
if (memcmp (&test_extents, &data->label_extents, sizeof (PangoRectangle)))
|
||||
{
|
||||
if (g_test_verbose ())
|
||||
g_print ("extents are different, ");
|
||||
g_print ("extents are different: expected: %d, %d, %d, %d "
|
||||
"-> text: %d, %d, %d, %d\n",
|
||||
test_extents.x / 1024,
|
||||
test_extents.y / 1024,
|
||||
test_extents.width / 1024,
|
||||
test_extents.height / 1024,
|
||||
data->label_extents.x / 1024,
|
||||
data->label_extents.y / 1024,
|
||||
data->label_extents.width / 1024,
|
||||
data->label_extents.height / 1024);
|
||||
|
||||
fail = TRUE;
|
||||
}
|
||||
else
|
||||
@@ -119,29 +129,29 @@ do_tests (CallbackData *data)
|
||||
PangoAttribute *attr;
|
||||
|
||||
/* TEST 1: change the text */
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), "Counter 0");
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 0");
|
||||
pango_layout_set_text (data->test_layout, "Counter 0", -1);
|
||||
check_result (data, "Change text", TRUE);
|
||||
g_assert (check_result (data, "Change text", TRUE) == FALSE);
|
||||
|
||||
/* TEST 2: change a single character */
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), "Counter 1");
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 1");
|
||||
pango_layout_set_text (data->test_layout, "Counter 1", -1);
|
||||
check_result (data, "Change a single character", TRUE);
|
||||
g_assert (check_result (data, "Change a single character", TRUE) == FALSE);
|
||||
|
||||
/* TEST 3: move the label */
|
||||
clutter_actor_set_position (data->label, 10, 0);
|
||||
check_result (data, "Move the label", FALSE);
|
||||
g_assert (check_result (data, "Move the label", FALSE) == FALSE);
|
||||
|
||||
/* TEST 4: change the font */
|
||||
clutter_label_set_font_name (CLUTTER_LABEL (data->label), "Serif 15");
|
||||
clutter_text_set_font_name (CLUTTER_TEXT (data->label), "Serif 15");
|
||||
fd = pango_font_description_from_string ("Serif 15");
|
||||
pango_layout_set_font_description (data->test_layout, fd);
|
||||
pango_font_description_free (fd);
|
||||
check_result (data, "Change the font", TRUE);
|
||||
g_assert (check_result (data, "Change the font", TRUE) == FALSE);
|
||||
|
||||
/* TEST 5: change the color */
|
||||
clutter_label_set_color (CLUTTER_LABEL (data->label), &red);
|
||||
check_result (data, "Change the color", FALSE);
|
||||
clutter_text_set_color (CLUTTER_TEXT (data->label), &red);
|
||||
g_assert (check_result (data, "Change the color", FALSE) == FALSE);
|
||||
|
||||
/* TEST 6: change the attributes */
|
||||
attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
|
||||
@@ -150,23 +160,23 @@ do_tests (CallbackData *data)
|
||||
attr_list = pango_attr_list_new ();
|
||||
pango_attr_list_insert (attr_list, attr);
|
||||
attr_list_copy = pango_attr_list_copy (attr_list);
|
||||
clutter_label_set_attributes (CLUTTER_LABEL (data->label), attr_list);
|
||||
clutter_text_set_attributes (CLUTTER_TEXT (data->label), attr_list);
|
||||
pango_layout_set_attributes (data->test_layout, attr_list_copy);
|
||||
pango_attr_list_unref (attr_list_copy);
|
||||
pango_attr_list_unref (attr_list);
|
||||
check_result (data, "Change the attributes", TRUE);
|
||||
g_assert (check_result (data, "Change the attributes", TRUE) == FALSE);
|
||||
|
||||
/* TEST 7: change the text again */
|
||||
clutter_label_set_attributes (CLUTTER_LABEL (data->label), NULL);
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), long_text);
|
||||
clutter_text_set_attributes (CLUTTER_TEXT (data->label), NULL);
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), long_text);
|
||||
pango_layout_set_attributes (data->test_layout, NULL);
|
||||
pango_layout_set_text (data->test_layout, long_text, -1);
|
||||
check_result (data, "Change the text again", TRUE);
|
||||
g_assert (check_result (data, "Change the text again", TRUE) == FALSE);
|
||||
|
||||
/* TEST 8: enable markup */
|
||||
clutter_label_set_use_markup (CLUTTER_LABEL (data->label), TRUE);
|
||||
clutter_text_set_use_markup (CLUTTER_TEXT (data->label), TRUE);
|
||||
pango_layout_set_markup (data->test_layout, long_text, -1);
|
||||
check_result (data, "Enable markup", TRUE);
|
||||
g_assert (check_result (data, "Enable markup", TRUE) == FALSE);
|
||||
|
||||
/* This part can't be a test because Clutter won't restrict the
|
||||
width if wrapping and ellipsizing is disabled so the extents will
|
||||
@@ -178,39 +188,39 @@ do_tests (CallbackData *data)
|
||||
force_redraw (data);
|
||||
|
||||
/* TEST 9: enable ellipsize */
|
||||
clutter_label_set_ellipsize (CLUTTER_LABEL (data->label),
|
||||
clutter_text_set_ellipsize (CLUTTER_TEXT (data->label),
|
||||
PANGO_ELLIPSIZE_END);
|
||||
pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_END);
|
||||
check_result (data, "Enable ellipsize", TRUE);
|
||||
clutter_label_set_ellipsize (CLUTTER_LABEL (data->label),
|
||||
g_assert (check_result (data, "Enable ellipsize", TRUE) == FALSE);
|
||||
clutter_text_set_ellipsize (CLUTTER_TEXT (data->label),
|
||||
PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_NONE);
|
||||
force_redraw (data);
|
||||
|
||||
/* TEST 10: enable line wrap */
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (data->label), TRUE);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (data->label), TRUE);
|
||||
pango_layout_set_wrap (data->test_layout, PANGO_WRAP_WORD);
|
||||
check_result (data, "Enable line wrap", TRUE);
|
||||
g_assert (check_result (data, "Enable line wrap", TRUE) == FALSE);
|
||||
|
||||
/* TEST 11: change wrap mode */
|
||||
clutter_label_set_line_wrap_mode (CLUTTER_LABEL (data->label),
|
||||
clutter_text_set_line_wrap_mode (CLUTTER_TEXT (data->label),
|
||||
PANGO_WRAP_CHAR);
|
||||
pango_layout_set_wrap (data->test_layout, PANGO_WRAP_CHAR);
|
||||
check_result (data, "Change wrap mode", TRUE);
|
||||
g_assert (check_result (data, "Change wrap mode", TRUE) == FALSE);
|
||||
|
||||
/* TEST 12: enable justify */
|
||||
clutter_label_set_justify (CLUTTER_LABEL (data->label), TRUE);
|
||||
clutter_text_set_justify (CLUTTER_TEXT (data->label), TRUE);
|
||||
pango_layout_set_justify (data->test_layout, TRUE);
|
||||
/* Pango appears to have a bug which means that you can't change the
|
||||
justification after setting the text but this fixes it.
|
||||
See http://bugzilla.gnome.org/show_bug.cgi?id=551865 */
|
||||
pango_layout_context_changed (data->test_layout);
|
||||
check_result (data, "Enable justify", TRUE);
|
||||
g_assert (check_result (data, "Enable justify", TRUE) == FALSE);
|
||||
|
||||
/* TEST 13: change alignment */
|
||||
clutter_label_set_alignment (CLUTTER_LABEL (data->label), PANGO_ALIGN_RIGHT);
|
||||
clutter_text_set_alignment (CLUTTER_TEXT (data->label), PANGO_ALIGN_RIGHT);
|
||||
pango_layout_set_alignment (data->test_layout, PANGO_ALIGN_RIGHT);
|
||||
check_result (data, "Change alignment", TRUE);
|
||||
g_assert (check_result (data, "Change alignment", TRUE) == FALSE);
|
||||
|
||||
clutter_main_quit ();
|
||||
|
||||
@@ -218,7 +228,7 @@ do_tests (CallbackData *data)
|
||||
}
|
||||
|
||||
static PangoLayout *
|
||||
make_layout_like_label (ClutterLabel *label)
|
||||
make_layout_like_label (ClutterText *label)
|
||||
{
|
||||
PangoLayout *label_layout, *new_layout;
|
||||
PangoContext *context;
|
||||
@@ -226,7 +236,7 @@ make_layout_like_label (ClutterLabel *label)
|
||||
|
||||
/* Make another layout using the same context as the layout from the
|
||||
label */
|
||||
label_layout = clutter_label_get_layout (label);
|
||||
label_layout = clutter_text_get_layout (label);
|
||||
context = pango_layout_get_context (label_layout);
|
||||
new_layout = pango_layout_new (context);
|
||||
fd = pango_font_description_from_string (TEST_FONT);
|
||||
@@ -237,8 +247,8 @@ make_layout_like_label (ClutterLabel *label)
|
||||
}
|
||||
|
||||
void
|
||||
test_label_cache (TestConformSimpleFixture *fixture,
|
||||
gconstpointer _data)
|
||||
test_text_cache (TestConformSimpleFixture *fixture,
|
||||
gconstpointer _data)
|
||||
{
|
||||
CallbackData data;
|
||||
|
||||
@@ -246,9 +256,9 @@ test_label_cache (TestConformSimpleFixture *fixture,
|
||||
|
||||
data.stage = clutter_stage_get_default ();
|
||||
|
||||
data.label = clutter_label_new_with_text (TEST_FONT, "");
|
||||
data.label = clutter_text_new_with_text (TEST_FONT, "");
|
||||
|
||||
data.test_layout = make_layout_like_label (CLUTTER_LABEL (data.label));
|
||||
data.test_layout = make_layout_like_label (CLUTTER_TEXT (data.label));
|
||||
|
||||
g_signal_connect (data.label, "paint", G_CALLBACK (on_paint), &data);
|
||||
|
@@ -6,7 +6,6 @@ UNIT_TESTS = \
|
||||
test-scale.c \
|
||||
test-actors.c \
|
||||
test-behave.c \
|
||||
test-entry.c \
|
||||
test-project.c \
|
||||
test-perspective.c \
|
||||
test-rotate.c \
|
||||
@@ -39,7 +38,9 @@ UNIT_TESTS = \
|
||||
test-layout.c \
|
||||
test-animation.c \
|
||||
test-easing.c \
|
||||
test-binding-pool.c
|
||||
test-binding-pool.c \
|
||||
test-text.c \
|
||||
test-text-field.c
|
||||
|
||||
if X11_TESTS
|
||||
UNIT_TESTS += test-pixmap.c
|
||||
|
@@ -305,8 +305,8 @@ test_clip_main (int argc, char **argv)
|
||||
data.hand = cogl_texture_new_from_file ("redhand.png", 64, FALSE,
|
||||
COGL_PIXEL_FORMAT_ANY, NULL);
|
||||
|
||||
label = clutter_label_new_with_text ("Sans 12px", instructions);
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (label), TRUE);
|
||||
label = clutter_text_new_with_text ("Sans 12px", instructions);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (label), TRUE);
|
||||
clutter_actor_set_width (label, clutter_actor_get_width (data.stage) - 310);
|
||||
clutter_actor_set_y (label,
|
||||
clutter_actor_get_height (data.stage)
|
||||
|
@@ -297,16 +297,16 @@ frame_cb (ClutterTimeline *timeline,
|
||||
}
|
||||
|
||||
static void
|
||||
update_toggle_text (ClutterLabel *button, gboolean val)
|
||||
update_toggle_text (ClutterText *button, gboolean val)
|
||||
{
|
||||
clutter_label_set_text (button, val ? "Enabled" : "Disabled");
|
||||
clutter_text_set_text (button, val ? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_toggle_click (ClutterActor *button, ClutterEvent *event,
|
||||
gboolean *toggle_val)
|
||||
{
|
||||
update_toggle_text (CLUTTER_LABEL (button), *toggle_val = !*toggle_val);
|
||||
update_toggle_text (CLUTTER_TEXT (button), *toggle_val = !*toggle_val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -315,12 +315,12 @@ static ClutterActor *
|
||||
make_toggle (const char *label_text, gboolean *toggle_val)
|
||||
{
|
||||
ClutterActor *group = clutter_group_new ();
|
||||
ClutterActor *label = clutter_label_new_with_text ("Sans 14", label_text);
|
||||
ClutterActor *button = clutter_label_new_with_text ("Sans 14", "");
|
||||
ClutterActor *label = clutter_text_new_with_text ("Sans 14", label_text);
|
||||
ClutterActor *button = clutter_text_new_with_text ("Sans 14", "");
|
||||
|
||||
clutter_actor_set_reactive (button, TRUE);
|
||||
|
||||
update_toggle_text (CLUTTER_LABEL (button), *toggle_val);
|
||||
update_toggle_text (CLUTTER_TEXT (button), *toggle_val);
|
||||
|
||||
clutter_actor_set_position (button, clutter_actor_get_width (label) + 10, 0);
|
||||
clutter_container_add (CLUTTER_CONTAINER (group), label, button, NULL);
|
||||
@@ -373,7 +373,7 @@ test_cogl_tex_polygon_main (int argc, char *argv[])
|
||||
clutter_actor_set_position (filtering_toggle, 0,
|
||||
clutter_actor_get_y (slicing_toggle)
|
||||
- clutter_actor_get_height (filtering_toggle));
|
||||
note = clutter_label_new_with_text ("Sans 10", "<- Click to change");
|
||||
note = clutter_text_new_with_text ("Sans 10", "<- Click to change");
|
||||
clutter_actor_set_position (note,
|
||||
clutter_actor_get_width (filtering_toggle) + 10,
|
||||
(clutter_actor_get_height (stage)
|
||||
|
@@ -83,10 +83,10 @@ janus_group (const gchar *front_text,
|
||||
|
||||
group = clutter_group_new ();
|
||||
rectangle = clutter_rectangle_new_with_color (&slide_color);
|
||||
front = clutter_label_new_with_text ("Sans 50px", front_text);
|
||||
back = clutter_label_new_with_text ("Sans 50px", back_text);
|
||||
clutter_label_set_color (CLUTTER_LABEL (front), &red);
|
||||
clutter_label_set_color (CLUTTER_LABEL (back), &green);
|
||||
front = clutter_text_new_with_text ("Sans 50px", front_text);
|
||||
back = clutter_text_new_with_text ("Sans 50px", back_text);
|
||||
clutter_text_set_color (CLUTTER_TEXT (front), &red);
|
||||
clutter_text_set_color (CLUTTER_TEXT (back), &green);
|
||||
|
||||
clutter_actor_get_size (front, &width, &height);
|
||||
clutter_actor_get_size (back, &width2, &height2);
|
||||
@@ -134,7 +134,7 @@ test_depth_main (int argc, char *argv[])
|
||||
clutter_stage_add (stage, group);
|
||||
clutter_actor_show (group);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 26", "Clutter");
|
||||
label = clutter_text_new_with_text ("Mono 26", "Clutter");
|
||||
clutter_actor_set_position (label, 120, 200);
|
||||
clutter_actor_show (label);
|
||||
|
||||
|
@@ -41,7 +41,7 @@ on_button_press (ClutterActor *actor,
|
||||
current_mode + 1,
|
||||
n_easing_modes);
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (easing_mode_label), text);
|
||||
clutter_text_set_text (CLUTTER_TEXT (easing_mode_label), text);
|
||||
g_free (text);
|
||||
|
||||
clutter_actor_get_size (main_stage, &stage_width, &stage_height);
|
||||
@@ -97,10 +97,10 @@ test_easing_main (int argc, char *argv[])
|
||||
current_mode + 1,
|
||||
n_easing_modes);
|
||||
|
||||
label = clutter_label_new ();
|
||||
label = clutter_text_new ();
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
|
||||
clutter_label_set_font_name (CLUTTER_LABEL (label), "Sans 18px");
|
||||
clutter_label_set_text (CLUTTER_LABEL (label), text);
|
||||
clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 18px");
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), text);
|
||||
clutter_actor_get_size (label, &label_width, &label_height);
|
||||
clutter_actor_set_position (label,
|
||||
stage_width - label_width - 10,
|
||||
|
@@ -43,9 +43,9 @@ make_source(void)
|
||||
|
||||
clutter_group_add (source, actor);
|
||||
|
||||
actor = clutter_label_new_with_text ("Sans Bold 50px", "Clutter");
|
||||
actor = clutter_text_new_with_text ("Sans Bold 50px", "Clutter");
|
||||
|
||||
clutter_label_set_color (CLUTTER_LABEL (actor), &yellow);
|
||||
clutter_text_set_color (CLUTTER_TEXT (actor), &yellow);
|
||||
clutter_actor_set_y (actor, clutter_actor_get_height(source) + 5);
|
||||
clutter_group_add (source, actor);
|
||||
|
||||
|
@@ -787,7 +787,7 @@ test_layout_main (int argc, char *argv[])
|
||||
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||
|
||||
instructions = clutter_label_new_with_text ("Sans 14",
|
||||
instructions = clutter_text_new_with_text ("Sans 14",
|
||||
"<b>Instructions:</b>\n"
|
||||
"a - add a new item\n"
|
||||
"d - remove last item\n"
|
||||
@@ -799,7 +799,7 @@ test_layout_main (int argc, char *argv[])
|
||||
"s - use transformed box\n"
|
||||
"q - quit");
|
||||
|
||||
clutter_label_set_use_markup (CLUTTER_LABEL (instructions), TRUE);
|
||||
clutter_text_set_use_markup (CLUTTER_TEXT (instructions), TRUE);
|
||||
clutter_actor_set_position (instructions, 450, 10);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), instructions);
|
||||
|
||||
|
@@ -50,10 +50,10 @@ on_button_press (ClutterActor *actor,
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (new_stage), tex);
|
||||
|
||||
stage_label = g_strdup_printf ("<b>Stage: %d</b>", ++n_stages);
|
||||
label = clutter_label_new_with_text ("Mono 12", stage_label);
|
||||
label = clutter_text_new_with_text ("Mono 12", stage_label);
|
||||
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &white);
|
||||
clutter_label_set_use_markup (CLUTTER_LABEL (label), TRUE);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &white);
|
||||
clutter_text_set_use_markup (CLUTTER_TEXT (label), TRUE);
|
||||
width = (clutter_actor_get_width (new_stage)
|
||||
- clutter_actor_get_width (label)) / 2;
|
||||
height = (clutter_actor_get_height (new_stage)
|
||||
@@ -110,7 +110,7 @@ test_multistage_main (int argc, char *argv[])
|
||||
G_CALLBACK (on_button_press),
|
||||
NULL);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 16", "Default stage");
|
||||
label = clutter_text_new_with_text ("Mono 16", "Default stage");
|
||||
width = (clutter_actor_get_width (stage_default)
|
||||
- clutter_actor_get_width (label))
|
||||
/ 2;
|
||||
|
@@ -224,8 +224,8 @@ test_project_main (int argc, char *argv[])
|
||||
clutter_actor_set_rotation (rect, CLUTTER_Y_AXIS, 60, 0, 0, 0);
|
||||
clutter_group_add (CLUTTER_GROUP (main_stage), rect);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 8pt", "Drag the blue rectangles");
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &white);
|
||||
label = clutter_text_new_with_text ("Mono 8pt", "Drag the blue rectangles");
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &white);
|
||||
|
||||
clutter_actor_set_position (label, 10, 10);
|
||||
clutter_group_add (CLUTTER_GROUP (main_stage), label);
|
||||
|
@@ -45,7 +45,7 @@ on_idle (gpointer data)
|
||||
font_names[rand () % FONT_NAME_COUNT],
|
||||
rand () % (MAX_FONT_SIZE - MIN_FONT_SIZE) + MIN_FONT_SIZE);
|
||||
|
||||
label = clutter_label_new_with_text (font_name, text);
|
||||
label = clutter_text_new_with_text (font_name, text);
|
||||
|
||||
if (clutter_actor_get_height (label) > line_height)
|
||||
line_height = clutter_actor_get_height (label);
|
||||
|
@@ -33,8 +33,8 @@ test_rotate_main (int argc, char *argv[])
|
||||
clutter_actor_show (hand);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);
|
||||
|
||||
label = clutter_label_new_with_text ("Mono 16", "The Wonder of the Spinning Hand");
|
||||
clutter_label_set_alignment (CLUTTER_LABEL (label), PANGO_ALIGN_CENTER);
|
||||
label = clutter_text_new_with_text ("Mono 16", "The Wonder of the Spinning Hand");
|
||||
clutter_text_set_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_CENTER);
|
||||
clutter_actor_set_position (label, 150, 150);
|
||||
clutter_actor_set_size (label, 500, 100);
|
||||
clutter_actor_show (label);
|
||||
|
@@ -354,7 +354,7 @@ test_shader_main (gint argc, gchar *argv[])
|
||||
if (!child2)
|
||||
g_error("pixbuf load failed: %s", error ? error->message : "Unknown");
|
||||
child3 = clutter_rectangle_new ();
|
||||
child4 = clutter_label_new_with_text ("Sans 20px", "Shady stuff");
|
||||
child4 = clutter_text_new_with_text ("Sans 20px", "Shady stuff");
|
||||
|
||||
clutter_rectangle_set_color (child3, &color);
|
||||
clutter_actor_set_size (child3, 50, 50);
|
||||
|
@@ -23,14 +23,14 @@ make_label (void)
|
||||
gchar *text;
|
||||
gchar *argv[] = { "ls", "--help", NULL };
|
||||
|
||||
label = clutter_label_new ();
|
||||
clutter_label_set_font_name (CLUTTER_LABEL (label), "Sans 10");
|
||||
label = clutter_text_new ();
|
||||
clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 10");
|
||||
|
||||
if (g_spawn_sync (NULL, argv, NULL,
|
||||
G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, &text, NULL, NULL, NULL))
|
||||
{
|
||||
clutter_label_set_text (CLUTTER_LABEL (label), text);
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), text);
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
|
117
tests/interactive/test-text-field.c
Normal file
117
tests/interactive/test-text-field.c
Normal file
@@ -0,0 +1,117 @@
|
||||
#include <stdlib.h>
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define FONT "Mono Bold 14px"
|
||||
|
||||
static void
|
||||
on_entry_paint (ClutterActor *actor,
|
||||
gpointer data)
|
||||
{
|
||||
ClutterActorBox allocation = { 0, };
|
||||
ClutterUnit width, height;
|
||||
|
||||
clutter_actor_get_allocation_box (actor, &allocation);
|
||||
width = allocation.x2 - allocation.x1;
|
||||
height = allocation.y2 - allocation.y1;
|
||||
|
||||
cogl_set_source_color4ub (255, 255, 255, 255);
|
||||
cogl_path_round_rectangle (0, 0,
|
||||
CLUTTER_UNITS_TO_FIXED (width),
|
||||
CLUTTER_UNITS_TO_FIXED (height),
|
||||
COGL_FIXED_FROM_INT (4),
|
||||
COGL_ANGLE_FROM_DEG (1.0));
|
||||
cogl_path_stroke ();
|
||||
}
|
||||
|
||||
static void
|
||||
on_entry_activate (ClutterText *text,
|
||||
gpointer data)
|
||||
{
|
||||
g_print ("Text activated: %s\n", clutter_text_get_text (text));
|
||||
}
|
||||
|
||||
static ClutterActor *
|
||||
create_label (const ClutterColor *color,
|
||||
const gchar *text)
|
||||
{
|
||||
ClutterActor *retval = clutter_text_new_full (FONT, text, color);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (retval), FALSE);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static ClutterActor *
|
||||
create_entry (const ClutterColor *color,
|
||||
const gchar *text,
|
||||
gunichar password_char,
|
||||
gint max_length)
|
||||
{
|
||||
ClutterActor *retval = clutter_text_new_full (FONT, text, color);
|
||||
ClutterColor selection = { 0, };
|
||||
|
||||
clutter_actor_set_width (retval, 200);
|
||||
clutter_actor_set_reactive (retval, TRUE);
|
||||
|
||||
clutter_color_darken (color, &selection);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_activatable (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE);
|
||||
clutter_text_set_password_char (CLUTTER_TEXT (retval), password_char);
|
||||
clutter_text_set_cursor_color (CLUTTER_TEXT (retval), &selection);
|
||||
clutter_text_set_max_length (CLUTTER_TEXT (retval), max_length);
|
||||
|
||||
g_signal_connect (retval, "activate",
|
||||
G_CALLBACK (on_entry_activate),
|
||||
NULL);
|
||||
g_signal_connect (retval, "paint",
|
||||
G_CALLBACK (on_entry_paint),
|
||||
NULL);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gint
|
||||
test_text_field_main (gint argc,
|
||||
gchar **argv)
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterActor *text;
|
||||
ClutterColor entry_color = {0x33, 0xff, 0x33, 0xff};
|
||||
ClutterColor label_color = {0xff, 0xff, 0xff, 0xff};
|
||||
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
|
||||
gint height;
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
||||
|
||||
text = create_label (&label_color, "Input field: ");
|
||||
clutter_actor_set_position (text, 10, 10);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
height = clutter_actor_get_height (text);
|
||||
|
||||
text = create_entry (&entry_color, "some text", 0, 0);
|
||||
clutter_actor_set_position (text, 200, 10);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
text = create_label (&label_color, "Password field: ");
|
||||
clutter_actor_set_position (text, 10, height + 12);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
text = create_entry (&entry_color, "password", '*', 8);
|
||||
clutter_actor_set_position (text, 200, height + 12);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
179
tests/interactive/test-text.c
Normal file
179
tests/interactive/test-text.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/* Try this text editor, it has issues but does work,
|
||||
* try ctrl+A, ctrl+C, ctrl+V, ctrl+X as well as selecting text with
|
||||
* mouse and keyboard, /Øyvind K
|
||||
*/
|
||||
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define FONT "Mono Bold 22px"
|
||||
|
||||
static gchar *clipboard = NULL;
|
||||
|
||||
static gchar *runes =
|
||||
"ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ\n"
|
||||
"ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ\n"
|
||||
"ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬\n";
|
||||
|
||||
|
||||
static gboolean
|
||||
select_all (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint len;
|
||||
len = g_utf8_strlen (clutter_text_get_text (ttext), -1);
|
||||
|
||||
clutter_text_set_cursor_position (ttext, 0);
|
||||
clutter_text_set_selection_bound (ttext, len);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
copy (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
if (clipboard)
|
||||
g_free (clipboard);
|
||||
clipboard = clutter_text_get_selection (ttext);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
paste (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
const gchar *p;
|
||||
if (!clipboard)
|
||||
return TRUE;
|
||||
|
||||
for (p=clipboard; *p!='\0'; p=g_utf8_next_char (p))
|
||||
{
|
||||
clutter_text_insert_unichar (ttext, g_utf8_get_char_validated (p, 3));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cut (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
clutter_text_action (ttext, "copy", NULL);
|
||||
clutter_text_action (ttext, "truncate-selection", NULL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pageup (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint i;
|
||||
for (i=0;i<10;i++)
|
||||
clutter_text_action (ttext, "move-up", event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pagedown (ClutterText *ttext,
|
||||
const gchar *commandline,
|
||||
ClutterEvent *event)
|
||||
{
|
||||
gint i;
|
||||
for (i=0;i<10;i++)
|
||||
clutter_text_action (ttext, "move-down", event);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
cursor_event (ClutterText *text,
|
||||
ClutterGeometry *geometry)
|
||||
{
|
||||
gint y;
|
||||
|
||||
y = clutter_actor_get_y (CLUTTER_ACTOR (text));
|
||||
|
||||
if (y + geometry->y < 50)
|
||||
{
|
||||
clutter_actor_set_y (CLUTTER_ACTOR (text), y + 100);
|
||||
}
|
||||
else if (y + geometry->y > 720)
|
||||
{
|
||||
clutter_actor_set_y (CLUTTER_ACTOR (text), y - 100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT gint
|
||||
test_text_main (gint argc,
|
||||
gchar **argv)
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterActor *text;
|
||||
ClutterColor text_color = {0x33, 0xff, 0x33, 0xff};
|
||||
ClutterColor cursor_color = {0xff, 0x33, 0x33, 0xff};
|
||||
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
||||
|
||||
text = clutter_text_new_full (FONT, "·", &text_color);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL);
|
||||
clutter_actor_set_position (text, 40, 30);
|
||||
clutter_actor_set_width (text, 1024);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (text), TRUE);
|
||||
|
||||
clutter_actor_set_reactive (text, TRUE);
|
||||
clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text);
|
||||
|
||||
clutter_text_set_editable (CLUTTER_TEXT (text), TRUE);
|
||||
clutter_text_set_selectable (CLUTTER_TEXT (text), TRUE);
|
||||
clutter_text_set_cursor_color (CLUTTER_TEXT (text), &cursor_color);
|
||||
|
||||
#if 0
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "select-all", select_all);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "copy", copy);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "paste", paste);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "cut", cut);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "pageup", pageup);
|
||||
clutter_text_add_action (CLUTTER_TEXT (text), "pagedown", pagedown);
|
||||
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_a, CLUTTER_CONTROL_MASK, "select-all");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_c, CLUTTER_CONTROL_MASK, "copy");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_v, CLUTTER_CONTROL_MASK, "paste");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_x, CLUTTER_CONTROL_MASK, "cut");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_Page_Up, 0, "pageup");
|
||||
clutter_text_add_mapping (CLUTTER_TEXT (text),
|
||||
CLUTTER_Page_Down, 0, "pagedown");
|
||||
#endif
|
||||
|
||||
if (argv[1])
|
||||
{
|
||||
gchar *utf8;
|
||||
g_file_get_contents (argv[1], &utf8, NULL, NULL);
|
||||
clutter_text_set_text (CLUTTER_TEXT (text), utf8);
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_text_set_text (CLUTTER_TEXT (text), runes);
|
||||
}
|
||||
|
||||
g_signal_connect (text, "cursor-event", G_CALLBACK (cursor_event), NULL);
|
||||
|
||||
clutter_actor_set_size (stage, 1024, 768);
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
return 0;
|
||||
}
|
@@ -42,7 +42,7 @@ test_thread_done_idle (gpointer user_data)
|
||||
|
||||
g_print ("Thread completed\n");
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (data->label), "Completed");
|
||||
clutter_text_set_text (CLUTTER_TEXT (data->label), "Completed");
|
||||
clutter_timeline_stop (data->timeline);
|
||||
|
||||
test_thread_data_free (data);
|
||||
@@ -67,7 +67,7 @@ update_label_idle (gpointer data)
|
||||
|
||||
text = g_strdup_printf ("Count to %d", update->count);
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (update->thread_data->label), text);
|
||||
clutter_text_set_text (CLUTTER_TEXT (update->thread_data->label), text);
|
||||
clutter_actor_set_width (update->thread_data->label, -1);
|
||||
|
||||
if (update->count == 0)
|
||||
@@ -151,7 +151,7 @@ on_key_press_event (ClutterStage *stage,
|
||||
switch (clutter_key_event_symbol (event))
|
||||
{
|
||||
case CLUTTER_s:
|
||||
clutter_label_set_text (CLUTTER_LABEL (help_label), "Press 'q' to quit");
|
||||
clutter_text_set_text (CLUTTER_TEXT (help_label), "Press 'q' to quit");
|
||||
|
||||
clutter_timeline_start (timeline);
|
||||
|
||||
@@ -191,10 +191,10 @@ test_threads_main (int argc, char *argv[])
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
||||
clutter_actor_set_size (stage, 600, 300);
|
||||
|
||||
count_label = clutter_label_new_with_text ("Mono 12", "Counter");
|
||||
count_label = clutter_text_new_with_text ("Mono 12", "Counter");
|
||||
clutter_actor_set_position (count_label, 350, 50);
|
||||
|
||||
help_label = clutter_label_new_with_text ("Mono 12", "Press 's' to start");
|
||||
help_label = clutter_text_new_with_text ("Mono 12", "Press 's' to start");
|
||||
clutter_actor_set_position (help_label, 50, 50);
|
||||
|
||||
rect = clutter_rectangle_new_with_color (&rect_color);
|
||||
|
@@ -53,12 +53,11 @@ on_event (ClutterStage *stage,
|
||||
CLUTTER_UNITS_TO_DEVICE (xu2),
|
||||
CLUTTER_UNITS_TO_DEVICE (yu2));
|
||||
|
||||
clutter_label_set_text (CLUTTER_LABEL (label), txt);
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), txt);
|
||||
g_free (txt);
|
||||
}
|
||||
else
|
||||
clutter_label_set_text (CLUTTER_LABEL (label),
|
||||
"Unprojection failed.");
|
||||
clutter_text_set_text (CLUTTER_TEXT (label), "Unprojection failed.");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -76,9 +75,9 @@ test_unproject_main (int argc, char *argv[])
|
||||
gchar *txt;
|
||||
ClutterActor *rect, *stage, *label0;
|
||||
int i, rotate_x = 0, rotate_y = 60, rotate_z = 0;
|
||||
ClutterColor stage_clr = { 0x0, 0x0, 0x0, 0xff },
|
||||
ClutterColor stage_clr = { 0x0, 0x0, 0x0, 0xff },
|
||||
white = { 0xff, 0xff, 0xff, 0xff },
|
||||
blue = { 0, 0xff, 0xff, 0xff };
|
||||
blue = { 0x0, 0xff, 0xff, 0xff };
|
||||
|
||||
for (i = 0; i < argc; ++i)
|
||||
{
|
||||
@@ -96,11 +95,12 @@ test_unproject_main (int argc, char *argv[])
|
||||
}
|
||||
else if (!strncmp (argv[i], "--help", 6))
|
||||
{
|
||||
printf ("%s [--rotage-x=degrees] [--rotage-y=degrees] "
|
||||
"[--rotage-z=degrees]\n",
|
||||
argv[0]);
|
||||
g_print ("%s [--rotage-x=degrees] "
|
||||
"[--rotage-y=degrees] "
|
||||
"[--rotage-z=degrees]\n",
|
||||
argv[0]);
|
||||
|
||||
exit (0);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ test_unproject_main (int argc, char *argv[])
|
||||
RECT_T, RECT_T + RECT_H,
|
||||
rotate_x, rotate_y, rotate_z);
|
||||
|
||||
label0 = clutter_label_new_with_text ("Mono 8pt", txt);
|
||||
clutter_label_set_color (CLUTTER_LABEL (label0), &white);
|
||||
label0 = clutter_text_new_with_text ("Mono 8pt", txt);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label0), &white);
|
||||
|
||||
clutter_actor_set_position (label0, 10, 10);
|
||||
clutter_group_add (CLUTTER_GROUP (stage), label0);
|
||||
@@ -135,9 +135,9 @@ test_unproject_main (int argc, char *argv[])
|
||||
g_free (txt);
|
||||
|
||||
label =
|
||||
clutter_label_new_with_text ("Mono 8pt", "Click around!");
|
||||
clutter_text_new_with_text ("Mono 8pt", "Click around!");
|
||||
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &blue);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &blue);
|
||||
|
||||
clutter_actor_set_position (label, 10, 50);
|
||||
clutter_group_add (CLUTTER_GROUP (stage), label);
|
||||
|
@@ -80,14 +80,14 @@ main (int argc, char *argv[])
|
||||
scale = 1.0;
|
||||
}
|
||||
|
||||
label = clutter_label_new_with_text (font_name, text);
|
||||
clutter_label_set_color (CLUTTER_LABEL (label), &label_color);
|
||||
label = clutter_text_new_with_text (font_name, text);
|
||||
clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
|
||||
clutter_actor_set_position (label, (1.0*STAGE_WIDTH/COLS)*col,
|
||||
(1.0*STAGE_HEIGHT/ROWS)*row);
|
||||
/*clutter_actor_set_clip (label, 0,0, (1.0*STAGE_WIDTH/COLS),
|
||||
(1.0*STAGE_HEIGHT/ROWS));*/
|
||||
clutter_actor_set_scale (label, scale, scale);
|
||||
clutter_label_set_line_wrap (CLUTTER_LABEL (label), FALSE);
|
||||
clutter_text_set_line_wrap (CLUTTER_TEXT (label), FALSE);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user