2009-01-07 00:27:50 +00:00
|
|
|
#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, };
|
2009-06-02 17:44:30 +00:00
|
|
|
gfloat width, height;
|
2009-01-07 00:27:50 +00:00
|
|
|
|
|
|
|
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);
|
2009-06-02 17:44:30 +00:00
|
|
|
cogl_path_round_rectangle (0, 0, width, height, 4.0, 1.0);
|
2009-01-07 00:27:50 +00:00
|
|
|
cogl_path_stroke ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_entry_activate (ClutterText *text,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2009-05-14 11:05:57 +00:00
|
|
|
g_print ("Text activated: %s (cursor: %d, selection at: %d)\n",
|
|
|
|
clutter_text_get_text (text),
|
|
|
|
clutter_text_get_cursor_position (text),
|
|
|
|
clutter_text_get_selection_bound (text));
|
2009-01-07 00:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ClutterActor *
|
|
|
|
create_label (const ClutterColor *color,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
2009-01-29 13:29:43 +00:00
|
|
|
ClutterActor *retval = clutter_text_new ();
|
2009-01-07 00:27:50 +00:00
|
|
|
|
2009-04-21 11:03:41 +00:00
|
|
|
clutter_actor_set_width (retval, 200);
|
|
|
|
|
2009-01-29 13:29:43 +00:00
|
|
|
clutter_text_set_font_name (CLUTTER_TEXT (retval), FONT);
|
|
|
|
clutter_text_set_color (CLUTTER_TEXT (retval), color);
|
|
|
|
clutter_text_set_markup (CLUTTER_TEXT (retval), text);
|
2009-01-07 00:27:50 +00:00
|
|
|
clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE);
|
|
|
|
clutter_text_set_selectable (CLUTTER_TEXT (retval), FALSE);
|
2009-04-21 11:03:41 +00:00
|
|
|
clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE);
|
|
|
|
clutter_text_set_ellipsize (CLUTTER_TEXT (retval), PANGO_ELLIPSIZE_END);
|
2009-01-07 00:27:50 +00:00
|
|
|
|
|
|
|
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};
|
2009-06-03 10:12:09 +00:00
|
|
|
ClutterUnits h_padding, v_padding;
|
2009-05-07 18:16:20 +00:00
|
|
|
gfloat width, height;
|
2009-01-07 00:27:50 +00:00
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
|
|
|
|
2009-06-03 10:12:09 +00:00
|
|
|
clutter_units_em_for_font (&h_padding, FONT, 2.0); /* 2em */
|
|
|
|
clutter_units_em_for_font (&v_padding, FONT, 3.0); /* 3em */
|
2009-05-07 18:16:20 +00:00
|
|
|
|
2009-06-03 10:12:09 +00:00
|
|
|
g_print ("padding: h:%.2f px, v:%.2f px\n",
|
|
|
|
clutter_units_to_pixels (&h_padding),
|
|
|
|
clutter_units_to_pixels (&v_padding));
|
2009-05-07 18:16:20 +00:00
|
|
|
|
2009-01-29 13:29:43 +00:00
|
|
|
text = create_label (&label_color, "<b>Input field:</b> ");
|
2009-01-07 00:27:50 +00:00
|
|
|
clutter_actor_set_position (text, 10, 10);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
|
2009-04-21 11:03:41 +00:00
|
|
|
width = clutter_actor_get_width (text);
|
2009-01-07 00:27:50 +00:00
|
|
|
height = clutter_actor_get_height (text);
|
|
|
|
|
2009-01-29 13:29:43 +00:00
|
|
|
text = create_entry (&entry_color, "<i>some</i> text", 0, 0);
|
2009-06-03 10:12:09 +00:00
|
|
|
clutter_actor_set_position (text,
|
|
|
|
width + 10 + clutter_units_to_pixels (&h_padding),
|
|
|
|
10);
|
2009-01-07 00:27:50 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
|
2009-04-21 11:03:41 +00:00
|
|
|
text = create_label (&label_color, "<i>A very long password field</i>: ");
|
2009-06-03 10:12:09 +00:00
|
|
|
clutter_actor_set_position (text,
|
|
|
|
10,
|
|
|
|
height + 10 + clutter_units_to_pixels (&v_padding));
|
2009-01-07 00:27:50 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
|
|
|
|
text = create_entry (&entry_color, "password", '*', 8);
|
2009-05-07 18:16:20 +00:00
|
|
|
clutter_actor_set_position (text,
|
2009-06-03 10:12:09 +00:00
|
|
|
width + 10 + clutter_units_to_pixels (&h_padding),
|
|
|
|
height + 10 + clutter_units_to_pixels (&v_padding));
|
2009-01-07 00:27:50 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|