Legacy Maemo 5 Documentation/Graphical UI Tutorial/Data selection

(Custom columns)
(wikify slightly)
 
(One intermediate revision not shown)
Line 1: Line 1:
-
= Data selection =
+
{{Legacy documentation}}
 +
 
Hildon provides a set of widgets for data selection specially designed for touchscreens that allows to build simple and easy-to-use interfaces.
Hildon provides a set of widgets for data selection specially designed for touchscreens that allows to build simple and easy-to-use interfaces.
Line 5: Line 6:
In addition, Hildon also provides a specialized dialog and a specialized button to be used in combination with a selector.
In addition, Hildon also provides a specialized dialog and a specialized button to be used in combination with a selector.
-
 
==Touch selector ==
==Touch selector ==
-
HildonTouchSelector is the mentioned selector widget. This widget can display several pannable columns. Each column is represented by a GtkTreeModel and single or multiple selection is allowed.
 
 +
<code>HildonTouchSelector</code> is the mentioned selector widget. This widget can display several pannable columns. Each column is represented by a <code>GtkTreeModel</code> and single or multiple selection is allowed.
===Text Columns Example===
===Text Columns Example===
 +
Let us see the simplest possible example. A selector that shows a single text column.
Let us see the simplest possible example. A selector that shows a single text column.
'''Example 6.1. Example of a single-column selector'''
'''Example 6.1. Example of a single-column selector'''
-
[[Image:example-single-text-column-selector.png|400px]]
+
[[Image:example-single-text-column-selector.png|frame|center|alt=Screenshot of TouchSelector|Single text column TouchSelector]]
-
  #include <hildon/hildon.h>
+
<source lang="c">
-
 
+
#include <hildon/hildon.h>
-
  void selection_changed (HildonTouchSelector * selector, gint column, gpointer user_data);
+
 
-
  static GtkWidget *create_simple_selector ();
+
void selection_changed (HildonTouchSelector * selector, gint column, gpointer user_data);
-
 
+
static GtkWidget *create_simple_selector ();
-
  void
+
 
-
  selection_changed (HildonTouchSelector * selector, gint column,
+
void
-
                    gpointer user_data)
+
selection_changed (HildonTouchSelector * selector, gint column,
-
  {
+
                  gpointer user_data)
-
    gchar *current_selection = NULL;
+
{
-
    
+
  gchar *current_selection = NULL;
-
    current_selection = hildon_touch_selector_get_current_text (selector);
+
 
-
    g_debug ("Current selection : %s", current_selection);
+
   current_selection = hildon_touch_selector_get_current_text (selector);
-
    g_debug ("User data=%s\n", (gchar*) user_data);
+
  g_debug ("Current selection : %s", current_selection);
-
  }
+
  g_debug ("User data=%s\n", (gchar*) user_data);
-
 
+
}
-
  static GtkWidget *
+
 
-
  create_simple_selector ()
+
static GtkWidget *
-
  {
+
create_simple_selector ()
-
    GtkWidget *selector = NULL;
+
{
-
    gint i;
+
  GtkWidget *selector = NULL;
-
    
+
  gint i;
-
    /* Create a HildonTouchSelector with a single text column */
+
 
-
    selector = hildon_touch_selector_new_text();
+
   /* Create a HildonTouchSelector with a single text column */
-
    
+
  selector = hildon_touch_selector_new_text();
-
    g_signal_connect (G_OBJECT (selector), "changed",
+
 
-
                      G_CALLBACK (selection_changed), (gpointer) "some data");
+
   g_signal_connect (G_OBJECT (selector), "changed",
-
 
+
                    G_CALLBACK (selection_changed), (gpointer) "some data");
-
    /* Populate selector */
+
 
-
    for (i = 1; i <= 10 ; i++) {
+
  /* Populate selector */
-
      gchar *label = g_strdup_printf ("Item %d", i);
+
  for (i = 1; i <= 10 ; i++) {
-
 
+
    gchar *label = g_strdup_printf ("Item %d", i);
-
      /* Add item to the column */
+
 
-
      hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
+
    /* Add item to the column */
-
                                        label);
+
    hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
-
 
+
                                      label);
-
      g_free (label);
+
 
-
    }
+
    g_free (label);
-
 
+
-
    /* Set selection mode */
+
-
    hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
+
-
                                                    HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
+
-
 
+
-
    return selector;
+
-
  }
+
-
 
+
-
  int
+
-
  main (int argc, char **argv)
+
-
  {
+
-
    HildonProgram *program = NULL;
+
-
    GtkWidget *window = NULL;
+
-
    GtkWidget *selector = NULL;
+
-
    GtkWidget *picker_button = NULL;
+
-
 
+
-
    hildon_gtk_init (&argc, &argv);
+
-
 
+
-
    program = hildon_program_get_instance ();
+
-
    g_set_application_name
+
-
      ("hildon-touch-selector example program");
+
-
 
+
-
    window = hildon_stackable_window_new ();
+
-
    hildon_program_add_window (program, HILDON_WINDOW (window));
+
-
 
+
-
    /* Create touch selector */
+
-
    selector = create_simple_selector ();
+
-
 
+
-
    /* Create a picker button */
+
-
    picker_button = hildon_picker_button_new (HILDON_SIZE_AUTO,
+
-
                                              HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+
-
 
+
-
    /* Set a title to the button*/
+
-
    hildon_button_set_title (HILDON_BUTTON (picker_button), "Select an item");
+
-
 
+
-
    /* Attach touch selector to the picker button*/
+
-
    hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker_button),
+
-
                                      HILDON_TOUCH_SELECTOR (selector));
+
-
 
+
-
    /* Add button to main window */
+
-
    gtk_container_add (GTK_CONTAINER (window), picker_button);
+
-
 
+
-
    g_signal_connect (G_OBJECT (window), "destroy",
+
-
                      G_CALLBACK (gtk_main_quit), NULL);
+
-
 
+
-
    gtk_widget_show_all (GTK_WIDGET (window));
+
-
 
+
-
    gtk_main ();
+
-
 
+
-
    return 0;
+
   }
   }
-
A HildonTouchSelector with a single text column is created in this program using the following convenience constructor.
+
  /* Set selection mode */
 +
  hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
 +
                                                  HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
 +
 
 +
  return selector;
 +
}
 +
 
 +
int
 +
main (int argc, char **argv)
 +
{
 +
  HildonProgram *program = NULL;
 +
  GtkWidget *window = NULL;
 +
  GtkWidget *selector = NULL;
 +
  GtkWidget *picker_button = NULL;
 +
 
 +
  hildon_gtk_init (&argc, &argv);
 +
 
 +
  program = hildon_program_get_instance ();
 +
  g_set_application_name
 +
    ("hildon-touch-selector example program");
 +
 
 +
  window = hildon_stackable_window_new ();
 +
  hildon_program_add_window (program, HILDON_WINDOW (window));
 +
 
 +
  /* Create touch selector */
 +
  selector = create_simple_selector ();
 +
 
 +
  /* Create a picker button */
 +
  picker_button = hildon_picker_button_new (HILDON_SIZE_AUTO,
 +
                                            HILDON_BUTTON_ARRANGEMENT_VERTICAL);
 +
 
 +
  /* Set a title to the button*/
 +
  hildon_button_set_title (HILDON_BUTTON (picker_button), "Select an item");
 +
 
 +
  /* Attach touch selector to the picker button*/
 +
  hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker_button),
 +
                                    HILDON_TOUCH_SELECTOR (selector));
 +
 
 +
  /* Add button to main window */
 +
  gtk_container_add (GTK_CONTAINER (window), picker_button);
 +
 
 +
  g_signal_connect (G_OBJECT (window), "destroy",
 +
                    G_CALLBACK (gtk_main_quit), NULL);
 +
 
 +
  gtk_widget_show_all (GTK_WIDGET (window));
 +
 
 +
  gtk_main ();
 +
 
 +
  return 0;
 +
}
 +
</source>
 +
 
 +
A <code>HildonTouchSelector</code> with a single text column is created in this program using the following convenience constructor.
-
<tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_touch_selector_new_text</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
+
<source lang="c">
-
</tt>
+
GtkWidget*  hildon_touch_selector_new_text  (void);
 +
</source>
To add text to a selector created by calling the constructor above, use the function.
To add text to a selector created by calling the constructor above, use the function.
-
<tt><span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_touch_selector_append_text</font></span>'''</span> <span><font color="#990000">(</font></span>HildonTouchSelector <span><font color="#990000"><nowiki>*</nowiki></font></span>selector<span><font color="#990000">,</font></span>
+
<source lang="c">
-
                                                <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>text<span><font color="#990000">);</font></span>
+
void        hildon_touch_selector_append_text (HildonTouchSelector *selector,
-
</tt>
+
                                              const gchar *text);
 +
</source>
Alternatively, you can use <code>hildon_touch_selector_prepend_text()</code> or <code>hildon_touch_selector_insert_text()</code> to add text to the selector in different positions.
Alternatively, you can use <code>hildon_touch_selector_prepend_text()</code> or <code>hildon_touch_selector_insert_text()</code> to add text to the selector in different positions.
Line 123: Line 128:
You can set the desired selection with the function. In the example, the mode was set to allow multiple selection.
You can set the desired selection with the function. In the example, the mode was set to allow multiple selection.
-
<tt><span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">hildon_touch_selector_set_column_selection_mode</font></span>'''</span> <span><font color="#990000">(</font></span>HildonTouchSelector <span><font color="#990000"><nowiki>*</nowiki></font></span>selector<span><font color="#990000">,</font></span>
+
<source lang="c">
-
                                                              HildonTouchSelectorSelectionMode mode<span><font color="#990000">);</font></span>
+
void        hildon_touch_selector_set_column_selection_mode (HildonTouchSelector *selector,
-
</tt>
+
                                                            HildonTouchSelectorSelectionMode mode);
 +
</source>
This example shows a very common use case of this widget. Next section shows how to build a more complex selector with several columns of different types.
This example shows a very common use case of this widget. Next section shows how to build a more complex selector with several columns of different types.
-
Also a simple function was set as a handler for the "changed" signal which is emitted each time the selected items change.
+
Also a simple function was set as a handler for the "<code>changed</code>" signal which is emitted each time the selected items change.
The callback retrieves a text representation of the currently selected items in the selector by calling <code>hildon_touch_selector_get_current_text()</code>. By default this function returns a concatenation of the items selected, separated by a comma.
The callback retrieves a text representation of the currently selected items in the selector by calling <code>hildon_touch_selector_get_current_text()</code>. By default this function returns a concatenation of the items selected, separated by a comma.
Line 135: Line 141:
To change how the text representation is generated, set your own function by  calling <code>hildon_touch_selector_set_print_func()</code> and using the following signature for the function:
To change how the text representation is generated, set your own function by  calling <code>hildon_touch_selector_set_print_func()</code> and using the following signature for the function:
-
<tt>gchar<span><font color="#990000"><nowiki>*</nowiki></font></span>     <span>'''<span><font color="#000000">user_function</font></span>'''</span> <span><font color="#990000">(</font></span>HildonTouchSelector <span><font color="#990000"><nowiki>*</nowiki></font></span>selector<span><font color="#990000">);</font></span>
+
<source lang="c">
-
</tt>
+
gchar*      user_function (HildonTouchSelector *selector);
 +
</source>
===Custom columns===
===Custom columns===
Line 142: Line 149:
In the previous section, a selector with a text column was created. That is probably the most common use case of touch selectors. Convenience functions to deal with text columns was used. However, you can also set other type of columns.
In the previous section, a selector with a text column was created. That is probably the most common use case of touch selectors. Convenience functions to deal with text columns was used. However, you can also set other type of columns.
-
Because each column is basically a treeview, you can use the same display to different data and in different ways as you would do with a GtkTreeview. Thus, you can use the GtkCellRenderers available in GTK+ to display the data on each cell.
+
Because each column is basically a treeview, you can use the same display to different data and in different ways as you would do with a <code>GtkTreeview</code>. Thus, you can use the <code>GtkCellRenderer</code>s available in GTK+ to display the data on each cell.
This section explains how to build a selector within a column displaying stock icons. Firstly, let us take a look on the function which used for appending new columns to a touchable selector.
This section explains how to build a selector within a column displaying stock icons. Firstly, let us take a look on the function which used for appending new columns to a touchable selector.
-
<tt>HildonTouchSelectorColumn<span><font color="#990000"><nowiki>*</nowiki></font></span><span>'''<span><font color="#000000"> hildon_touch_selector_append_column</font></span>'''</span> <span><font color="#990000">(</font></span>HildonTouchSelector <span><font color="#990000"><nowiki>*</nowiki></font></span>selector<span><font color="#990000">,</font></span>
+
<source lang="c">
-
                                                                GtkTreeModel <span><font color="#990000"><nowiki>*</nowiki></font></span>model<span><font color="#990000">,</font></span>
+
HildonTouchSelectorColumn* hildon_touch_selector_append_column (HildonTouchSelector *selector,
-
                                                                GtkCellRenderer <span><font color="#990000"><nowiki>*</nowiki></font></span>cell_renderer<span><font color="#990000">,</font></span>
+
                                                                GtkTreeModel *model,
-
                                              <span><font color="#990000">                  ...);</font></span>
+
                                                                GtkCellRenderer *cell_renderer,
-
</tt>
+
                                                                ...);
 +
</source>
-
This functions adds a new column to the widget whose data is obtained from the passed model. Pass also a GtkCellRenderer and a list of pairs property/value which is set as attributes of the renderer.
+
This functions adds a new column to the widget whose data is obtained from the passed model. Pass also a <code>GtkCellRenderer</code> and a list of pairs property/value which is set as attributes of the renderer.
-
This function basically adds a GtkTreeView to the widget. For more information on how GtkTreeviews work, see [http://maemo.org/api_refs/5.0/beta/gtk/ GTK+ widgets] before.
+
This function basically adds a <code>GtkTreeView</code> to the widget. For more information on how <code>GtkTreeView</code>s work, see [http://maemo.org/api_refs/5.0/beta/gtk/ GTK+ widgets] before.
The following example shows how to set a column to display images in a selector. For clarity, only the function which creates the selector is shown.
The following example shows how to set a column to display images in a selector. For clarity, only the function which creates the selector is shown.
'''Example 6.2. Example of a selector with a custom column'''
'''Example 6.2. Example of a selector with a custom column'''
-
[[Image:example-single-column-selector.png|400px]]
+
[[Image:example-single-column-selector.png|frame|center|alt=Screenshot of TouchSelector|Single column TouchSelector]]
-
<tt> <span>'''<span><font color="#0000FF">static</font></span>'''</span> GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>
+
<source lang="c">
-
<span>'''<span><font color="#000000">create_customized_selector</font></span>'''</span><span><font color="#990000">()</font></span>
+
static GtkWidget *
-
<span><font color="#FF0000">{</font></span>
+
create_customized_selector()
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>selector<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
{
-
  GSList <span><font color="#990000"><nowiki>*</nowiki></font></span>icon_list <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkWidget *selector;
-
  GtkListStore <span><font color="#990000"><nowiki>*</nowiki></font></span>store_icons <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GSList *icon_list = NULL;
-
  GSList <span><font color="#990000"><nowiki>*</nowiki></font></span>item <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkListStore *store_icons = NULL;
-
  GtkCellRenderer <span><font color="#990000"><nowiki>*</nowiki></font></span>renderer <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GSList *item = NULL;
-
  HildonTouchSelectorColumn <span><font color="#990000"><nowiki>*</nowiki></font></span>column <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkCellRenderer *renderer = NULL;
-
  <span>''<span><font color="#9A1900">/* Create a touch selector */</font></span>''</span>
+
  HildonTouchSelectorColumn *column = NULL;
-
  selector <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_touch_selector_new</font></span>'''</span><span><font color="#990000">();</font></span>
+
  /* Create a touch selector */
-
  <span>''<span><font color="#9A1900">/* Stock icons will be used for the example */</font></span>''</span>
+
  selector = hildon_touch_selector_new();
-
  icon_list <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_stock_list_ids</font></span>'''</span><span><font color="#990000">();</font></span>
+
  /* Stock icons will be used for the example */
-
  <span>''<span><font color="#9A1900">/* Create model to store selector's items */</font></span>''</span>
+
  icon_list = gtk_stock_list_ids();
-
  store_icons <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_list_store_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#993399">1</font></span><span><font color="#990000">,</font></span> G_TYPE_STRING<span><font color="#990000">);</font></span>
+
  /* Create model to store selector's items */
-
  <span>''<span><font color="#9A1900">/* Populate model */</font></span>''</span>
+
  store_icons = gtk_list_store_new (1, G_TYPE_STRING);
-
  <span>'''<span><font color="#0000FF">for</font></span>'''</span> <span><font color="#990000">(</font></span>item <span><font color="#990000"><nowiki>=</nowiki></font></span> icon_list<span><font color="#990000"><nowiki>;</nowiki></font></span> item<span><font color="#990000"><nowiki>;</nowiki></font></span> item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">g_slist_next</font></span>'''</span> <span><font color="#990000">(</font></span>item<span><font color="#990000">))</font></span> <span><font color="#FF0000">{</font></span>
+
  /* Populate model */
-
    GtkTreeIter iter<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  for (item = icon_list; item; item = g_slist_next (item)) {
-
    gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>label <span><font color="#990000"><nowiki>=</nowiki></font></span> item<span><font color="#990000">-&gt;</font></span>data<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
    GtkTreeIter iter;
-
    <span>'''<span><font color="#000000">gtk_list_store_append</font></span>'''</span> <span><font color="#990000">(</font></span>store_icons<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">);</font></span>
+
    gchar *label = item->data;
-
    <span>'''<span><font color="#000000">gtk_list_store_set</font></span>'''</span> <span><font color="#990000">(</font></span>store_icons<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> label<span><font color="#990000">,</font></span> <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
    gtk_list_store_append (store_icons, &iter);
-
    <span>'''<span><font color="#000000">g_free</font></span>'''</span> <span><font color="#990000">(</font></span>label<span><font color="#990000">);</font></span>
+
    gtk_list_store_set (store_icons, &iter, 0, label, -1);
-
  <span><font color="#FF0000">}</font></span>
+
    g_free (label);
-
  <span>'''<span><font color="#000000">g_slist_free</font></span>'''</span> <span><font color="#990000">(</font></span>icon_list<span><font color="#990000">);</font></span>
+
  }
-
  <span>''<span><font color="#9A1900">/* Create and set up a pixbuf renderer to use in the selector */</font></span>''</span>
+
  g_slist_free (icon_list);
-
  renderer <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_cell_renderer_pixbuf_new</font></span>'''</span><span><font color="#990000">();</font></span>
+
  /* Create and set up a pixbuf renderer to use in the selector */
-
  <span>'''<span><font color="#000000">gtk_cell_renderer_set_fixed_size</font></span>'''</span> <span><font color="#990000">(</font></span>renderer<span><font color="#990000">,</font></span> <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">100</font></span><span><font color="#990000">);</font></span>
+
  renderer = gtk_cell_renderer_pixbuf_new();
-
  <span>''<span><font color="#9A1900">/* Add the column to the selector */</font></span>''</span>
+
  gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
-
  column <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_touch_selector_append_column</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">),</font></span>
+
  /* Add the column to the selector */
-
                                                <span>'''<span><font color="#000000">GTK_TREE_MODEL</font></span>'''</span> <span><font color="#990000">(</font></span>store_icons<span><font color="#990000">),</font></span>
+
  column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
-
                                                renderer<span><font color="#990000">,</font></span>
+
                                                GTK_TREE_MODEL (store_icons),
-
                                                <span><font color="#FF0000">"stock-id"</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span>
+
                                                renderer,
-
                                                NULL<span><font color="#990000">);</font></span>
+
                                                "stock-id", 0,
-
  <span>''<span><font color="#9A1900">/* Set the selection mode */</font></span>''</span>
+
                                                NULL);
-
  <span>'''<span><font color="#000000">hildon_touch_selector_set_column_selection_mode</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">),</font></span>
+
  /* Set the selection mode */
-
                                    <span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE</font></span>'''</span><span><font color="#990000">);</font></span>
+
  hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
-
  <span>''<span><font color="#9A1900">/* Set the property "text-column" that indicates the column</font></span>''</span>
+
                                    HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
-
<span>''<span><font color="#9A1900">  * of the model to get the string from */</font></span>''</span>
+
  /* Set the property "text-column" that indicates the column
-
  <span>'''<span><font color="#000000">g_object_set</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>column<span><font color="#990000">),</font></span> <span><font color="#FF0000">"text-column"</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
+
  * of the model to get the string from */
-
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> selector<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  g_object_set (G_OBJECT (column), "text-column", 0, NULL);
-
<span><font color="#FF0000">}</font></span>
+
  return selector;
-
</tt>
+
}
 +
</source>
-
The first step in the example is to create and populate a GtkTreeModel. A GtkListStore is used in the example. In most use cases of the touchable selectors a GtkListStore fits well as selectors were designed to allow users to select from a list of items.
+
The first step in the example is to create and populate a <code>GtkTreeModel</code>. A <code>GtkListStore</code> is used in the example. In most use cases of the touchable selectors a <code>GtkListStore</code> fits well as selectors were designed to allow users to select from a list of items.
In this case, the model stores a list of GTK+ stock icons identifiers. The following call creates a list store with one column to store strings.
In this case, the model stores a list of GTK+ stock icons identifiers. The following call creates a list store with one column to store strings.
-
<tt>store_icons <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_list_store_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#993399">1</font></span><span><font color="#990000">,</font></span> G_TYPE_STRING<span><font color="#990000">);</font></span>
+
<source lang="c">
-
</tt>
+
store_icons = gtk_list_store_new (1, G_TYPE_STRING);
 +
</source>
The following loop appends all stock identifiers in the newly created model. The identifiers were previously retrieved using
The following loop appends all stock identifiers in the newly created model. The identifiers were previously retrieved using
-
<tt><span>'''<span><font color="#000000">gtk_stock_list_ids</font></span>'''</span><span><font color="#990000">().</font></span>
+
<source lang="c">
-
  <span>'''<span><font color="#0000FF">for</font></span>'''</span> <span><font color="#990000">(</font></span>item <span><font color="#990000"><nowiki>=</nowiki></font></span> icon_list<span><font color="#990000"><nowiki>;</nowiki></font></span> item<span><font color="#990000"><nowiki>;</nowiki></font></span> item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">g_slist_next</font></span>'''</span> <span><font color="#990000">(</font></span>item<span><font color="#990000">))</font></span> <span><font color="#FF0000">{</font></span>
+
gtk_stock_list_ids().
-
    GtkTreeIter iter<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  for (item = icon_list; item; item = g_slist_next (item)) {
-
    gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>label <span><font color="#990000"><nowiki>=</nowiki></font></span> item<span><font color="#990000">-&gt;</font></span>data<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
    GtkTreeIter iter;
-
    <span>'''<span><font color="#000000">gtk_list_store_append</font></span>'''</span> <span><font color="#990000">(</font></span>store_icons<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">);</font></span>
+
    gchar *label = item->data;
-
    <span>'''<span><font color="#000000">gtk_list_store_set</font></span>'''</span> <span><font color="#990000">(</font></span>store_icons<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>iter<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span> label<span><font color="#990000">,</font></span> <span><font color="#990000">-</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
+
    gtk_list_store_append (store_icons, &iter);
-
    <span>'''<span><font color="#000000">g_free</font></span>'''</span> <span><font color="#990000">(</font></span>label<span><font color="#990000">);</font></span>
+
    gtk_list_store_set (store_icons, &iter, 0, label, -1);
-
  <span><font color="#FF0000">}</font></span>
+
    g_free (label);
-
  <span>'''<span><font color="#000000">g_slist_free</font></span>'''</span> <span><font color="#990000">(</font></span>icon_list<span><font color="#990000">);</font></span>
+
  }
-
</tt>
+
  g_slist_free (icon_list);
 +
</source>
-
The next step is to set up the renderer which renders each row of the new column. We need a GtkCellRendererPixbuf to display the stock icons.
+
The next step is to set up the renderer which renders each row of the new column. We need a <code>GtkCellRendererPixbuf</code> to display the stock icons.
-
<tt>renderer <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_cell_renderer_pixbuf_new</font></span>'''</span><span><font color="#990000">();</font></span>
+
<source lang="c">
-
</tt>
+
renderer = gtk_cell_renderer_pixbuf_new();
 +
</source>
Finally, we create and append the new column, using the model and renderer previously created.
Finally, we create and append the new column, using the model and renderer previously created.
-
This call also sets the property "stock-id" of the GtkCellrendererPixbuf. The value is set to 0 which is the number of the column in the GtkTreeModel that stores the stock-id.
+
This call also sets the property "<code>stock-id</code>" of the <code>GtkCellrendererPixbuf</code>. The value is set to 0 which is the number of the column in the <code>GtkTreeModel</code> that stores the <code>stock-id</code>.
-
<tt>  column <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_touch_selector_append_column</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">),</font></span>
+
<source lang="c">
-
                                        <span>'''<span><font color="#000000">GTK_TREE_MODEL</font></span>'''</span> <span><font color="#990000">(</font></span>store_icons<span><font color="#990000">),</font></span>
+
column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
-
                                                renderer<span><font color="#990000">,</font></span>
+
                                        GTK_TREE_MODEL (store_icons),
-
                                                <span><font color="#FF0000">"stock-id"</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">,</font></span>
+
                                              renderer,
-
                                                NULL<span><font color="#990000">);</font></span>
+
                                              "stock-id", 0,
-
</tt>
+
                                              NULL);
 +
</source>
-
To summarize, setting a new custom column in a touchable selector is quite similar to setting a new column in a normal GtkTreeview. Create a model to store the data and a cell renderer to properly show this data in each row, and finally add the new column.
+
To summarize, setting a new custom column in a touchable selector is quite similar to setting a new column in a normal <code>GtkTreeView</code>. Create a model to store the data and a cell renderer to properly show this data in each row, and finally add the new column.
==Picker dialog and picker buttons ==
==Picker dialog and picker buttons ==
-
Normally, you use HildonTouchSelector together with a HildonPickerDialog activated from a button. For most common cases you use HildonPickerButton.
+
 
 +
Normally, you use <code>HildonTouchSelector</code> together with a <code>HildonPickerDialog</code> activated from a button. For most common cases you use <code>HildonPickerButton</code>.
This is the usual way to present a selector to the user. The picker button opens a dialog which presents the selector and properly manages user interaction.
This is the usual way to present a selector to the user. The picker button opens a dialog which presents the selector and properly manages user interaction.
Line 249: Line 263:
'''Example'''
'''Example'''
-
Previous sections showed you how to create a touchable selector. In most cases the next step is to attach the selector to a HildonPickerButton.
+
Previous sections showed you how to create a touchable selector. In most cases the next step is to attach the selector to a <code>HildonPickerButton</code>.
-
A HildonPickerButton is a special GtkButton which displays two labels, title and value, and brings up a HildonPickerDialog. The user chooses one or several items. A string representation of the chosen items is displayed in the value label of the picker button.
+
A <code>HildonPickerButton</code> is a special <code>GtkButton</code> which displays two labels, title and value, and brings up a <code>HildonPickerDialog</code>. The user chooses one or several items. A string representation of the chosen items is displayed in the value label of the picker button.
-
Below, a modified version of the previous main function is shown, in which you can check how a HildonPickerButton is created and attached to a selector. Also a callback to catch the signal "value-changed" emitted is added.
+
Below, a modified version of the previous main function is shown, in which you can check how a <code>HildonPickerButton</code> is created and attached to a selector. Also a callback to catch the signal "<code>value-changed</code>" emitted is added.
-
[[Image:example-picker-button.png|400px]]
+
[[Image:example-picker-button.png|frame|center|alt=Screenshot of picker button|PickerButton]]
'''Example 6.3. Example of a Hildon picker button'''
'''Example 6.3. Example of a Hildon picker button'''
-
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>
+
<source lang="c">
-
<span>'''<span><font color="#000000">on_picker_value_changed</font></span>'''</span> <span><font color="#990000">(</font></span>HildonPickerButton <span><font color="#990000"><nowiki>*</nowiki></font></span> button<span><font color="#990000">,</font></span> gpointer data<span><font color="#990000">)</font></span>
+
static void
-
<span><font color="#FF0000">{</font></span>
+
on_picker_value_changed (HildonPickerButton * button, gpointer data)
-
  <span>'''<span><font color="#000000">g_print</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Newly selected value: %s</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">,</font></span>
+
{
-
            <span>'''<span><font color="#000000">hildon_button_get_value</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">)));</font></span>
+
  g_print ("Newly selected value: %s\n",
-
<span><font color="#FF0000">}</font></span>
+
          hildon_button_get_value (HILDON_BUTTON (button)));
-
+
}
-
<span><font color="#009900">int</font></span>
+
 
-
<span>'''<span><font color="#000000">main</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span> <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span>
+
int
-
<span><font color="#FF0000">{</font></span>
+
main (int argc, char **argv)
-
  HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>program<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
{
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  HildonProgram *program;
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>picker_button<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkWidget *window;
-
+
  GtkWidget *picker_button;
-
  <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span>
+
 
-
+
  hildon_gtk_init (&argc, &argv);
-
  program <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_instance</font></span>'''</span> <span><font color="#990000">();</font></span>
+
 
-
  <span>'''<span><font color="#000000">g_set_application_name</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"hildon-touch-selector example program"</font></span><span><font color="#990000">);</font></span>
+
  program = hildon_program_get_instance ();
-
+
  g_set_application_name ("hildon-touch-selector example program");
-
  window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_stackable_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
+
 
-
  <span>'''<span><font color="#000000">hildon_program_add_window</font></span>'''</span> <span><font color="#990000">(</font></span>program<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
+
  window = hildon_stackable_window_new ();
-
+
  hildon_program_add_window (program, HILDON_WINDOW (window));
-
  <span>''<span><font color="#9A1900">/* Create touch selector */</font></span>''</span>
+
 
-
  selector <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">create_customized_selector</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  /* Create touch selector */
-
+
  selector = create_customized_selector ();
-
  <span>''<span><font color="#9A1900">/* Create a picker button */</font></span>''</span>
+
 
-
  picker_button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_picker_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">,</font></span>
+
  /* Create a picker button */
-
                                            HILDON_BUTTON_ARRANGEMENT_VERTICAL<span><font color="#990000">);</font></span>
+
  picker_button = hildon_picker_button_new (HILDON_SIZE_AUTO,
-
+
                                            HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-
  <span>''<span><font color="#9A1900">/* Set a title to the button */</font></span>''</span>
+
 
-
  <span>'''<span><font color="#000000">hildon_button_set_title</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>picker_button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Select an item"</font></span><span><font color="#990000">);</font></span>
+
  /* Set a title to the button */
-
+
  hildon_button_set_title (HILDON_BUTTON (picker_button), "Select an item");
-
  <span>''<span><font color="#9A1900">/* Attach the touch selector to the picker button*/</font></span>''</span>
+
 
-
  <span>'''<span><font color="#000000">hildon_picker_button_set_selector</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_PICKER_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>picker_button<span><font color="#990000">),</font></span>
+
  /* Attach the touch selector to the picker button*/
-
                                      <span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">));</font></span>
+
  hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker_button),
-
+
                                    HILDON_TOUCH_SELECTOR (selector));
-
  <span>''<span><font color="#9A1900">/* Attach callback to the "value-changed" signal*/</font></span>''</span>
+
 
-
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>picker_button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"value-changed"</font></span><span><font color="#990000">,</font></span>
+
  /* Attach callback to the "value-changed" signal*/
-
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>on_picker_value_changed<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
+
  g_signal_connect (G_OBJECT (picker_button), "value-changed",
-
+
                    G_CALLBACK (on_picker_value_changed), NULL);
-
  <span>''<span><font color="#9A1900">/* Add button to main window */</font></span>''</span>
+
 
-
  <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> picker_button<span><font color="#990000">);</font></span>
+
  /* Add button to main window */
-
+
  gtk_container_add (GTK_CONTAINER (window), picker_button);
-
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"destroy"</font></span><span><font color="#990000">,</font></span>
+
 
-
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
+
  g_signal_connect (G_OBJECT (window), "destroy",
-
+
                    G_CALLBACK (gtk_main_quit), NULL);
-
  <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
+
 
-
+
  gtk_widget_show_all (GTK_WIDGET (window));
-
  <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
+
 
-
+
  gtk_main ();
-
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
+
 
-
<span><font color="#FF0000">}</font></span>
+
  return 0;
-
+
}
-
</tt>
+
</source>
In the above example a picker button is created. The reference to the attached selector is stored in the property "touch-selector" of the picker button. To retrieve the attached selector , use function <code>hildon_picker_button_get_selector()</code>. To attach the selector, use the function <code>hildon_picker_button_set_selector()</code>.
In the above example a picker button is created. The reference to the attached selector is stored in the property "touch-selector" of the picker button. To retrieve the attached selector , use function <code>hildon_picker_button_get_selector()</code>. To attach the selector, use the function <code>hildon_picker_button_set_selector()</code>.
Line 324: Line 338:
When users finish their selection, the value label on the button automatically changes to show a textual representation of the item or items selected.
When users finish their selection, the value label on the button automatically changes to show a textual representation of the item or items selected.
-
In most cases you want to perform any action when selection is finished. To do that, add a handler to the signal "value-changed" of the picker button. In this example the handler attached to "value-changed" signal retrieves the value label of the button and prints a debug message.
+
In most cases you want to perform any action when selection is finished. To do that, add a handler to the signal "<code>value-changed</code>" of the picker button. In this example the handler attached to "<code>value-changed</code>" signal retrieves the value label of the button and prints a debug message.
-
 
+
==Touch selector entry ==
==Touch selector entry ==
-
The HildonTouchSelectorEntry is a selector widget with a text entry that allows users to select an item from a predefined list or to enter a different one in a HildonEntry. Items can also be searched and selected by typing in the entry.
 
-
An additional feature is that the HildonEntry is auto-completed with the list's items as the user types their name.
+
The <code>HildonTouchSelectorEntry</code> is a selector widget with a text entry that allows users to select an item from a predefined list or to enter a different one in a <code>HildonEntry</code>. Items can also be searched and selected by typing in the entry.
 +
 
 +
An additional feature is that the <code>HildonEntry</code> is auto-completed with the list's items as the user types their name.
Example below shows how to build a selector to pick a word in a list of words.
Example below shows how to build a selector to pick a word in a list of words.
-
[[Image:Touch_selector_entry.png|400px]]
+
[[Image:Touch_selector_entry.png|frame|center|alt=Screenshot of TouchSelectorEntry|TouchSelectorEntry]]
'''Example 6.4. Example of a Hildon picker button with a selector entry'''
'''Example 6.4. Example of a Hildon picker button with a selector entry'''
-
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;hildon/hildon.h&gt;</font></span>
+
<source lang="c">
-
                                                                                                                          <span>'''<span><font color="#0000FF">static</font></span>'''</span> <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar<span><font color="#990000"><nowiki>*</nowiki></font></span> artists <span><font color="#990000">[]</font></span> <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#FF0000">{</font></span>
+
#include <hildon/hildon.h>
-
  <span><font color="#FF0000">"AC/DC"</font></span><span><font color="#990000">,</font></span>
+
 
-
  <span><font color="#FF0000">"Aerosmith"</font></span><span><font color="#990000">,</font></span>
+
static const gchar* artists [] = {
-
  <span><font color="#FF0000">"Alice in Chains"</font></span><span><font color="#990000">,</font></span>
+
  "AC/DC",
-
  <span><font color="#FF0000">"Black Sabbath"</font></span><span><font color="#990000">,</font></span>
+
  "Aerosmith",
-
  <span><font color="#FF0000">"Carcass"</font></span><span><font color="#990000">,</font></span>
+
  "Alice in Chains",
-
  <span><font color="#FF0000">"Danzig"</font></span><span><font color="#990000">,</font></span>
+
  "Black Sabbath",
-
  <span><font color="#FF0000">"Deep Purple"</font></span><span><font color="#990000">,</font></span>
+
  "Carcass",
-
  <span><font color="#FF0000">"Dream Theater"</font></span><span><font color="#990000">,</font></span>
+
  "Danzig",
-
  <span><font color="#FF0000">"Eric Clapton"</font></span><span><font color="#990000">,</font></span>
+
  "Deep Purple",
-
  NULL
+
  "Dream Theater",
-
<span><font color="#FF0000">}</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  "Eric Clapton",
-
                                                                                                                            <span><font color="#009900">int</font></span>
+
  NULL
-
<span>'''<span><font color="#000000">main</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span> argc<span><font color="#990000">,</font></span> <span><font color="#009900">char</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span>argv<span><font color="#990000">)</font></span>
+
};
-
<span><font color="#FF0000">{</font></span>
+
 
-
  HildonProgram <span><font color="#990000"><nowiki>*</nowiki></font></span>program<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
int
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
main (int argc, char **argv)
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
{
-
  GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>selector<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  HildonProgram *program;
-
  gint i<span><font color="#990000"><nowiki>;</nowiki></font></span>
+
  GtkWidget *window;
-
  <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&amp;</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&amp;</font></span>argv<span><font color="#990000">);</font></span>
+
  GtkWidget *button;
-
  program <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_program_get_instance</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  GtkWidget *selector;
-
  g_set_application_name
+
  gint i;
-
    <span><font color="#990000">(</font></span><span><font color="#FF0000">"HildonTouchSelectorEntry example program"</font></span><span><font color="#990000">);</font></span>
+
  hildon_gtk_init (&argc, &argv);
-
  window <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_stackable_window_new</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  program = hildon_program_get_instance ();
-
  <span>'''<span><font color="#000000">hildon_program_add_window</font></span>'''</span> <span><font color="#990000">(</font></span>program<span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">HILDON_WINDOW</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
+
  g_set_application_name
-
  <span>''<span><font color="#9A1900">/* Create a picker button */</font></span>''</span>
+
    ("HildonTouchSelectorEntry example program");
-
  button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_picker_button_new</font></span>'''</span> <span><font color="#990000">(</font></span>HILDON_SIZE_AUTO<span><font color="#990000">,</font></span>
+
  window = hildon_stackable_window_new ();
-
                                      HILDON_BUTTON_ARRANGEMENT_VERTICAL<span><font color="#990000">);</font></span>
+
  hildon_program_add_window (program, HILDON_WINDOW (window));
-
  <span>'''<span><font color="#000000">hildon_button_set_title</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span> <span><font color="#FF0000">"Pick a band!"</font></span><span><font color="#990000">);</font></span>
+
  /* Create a picker button */
-
  <span>''<span><font color="#9A1900">/* Create a touch selector entry */</font></span>''</span>
+
  button = hildon_picker_button_new (HILDON_SIZE_AUTO,
-
  selector <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_touch_selector_entry_new_text</font></span>'''</span> <span><font color="#990000">();</font></span>
+
                                    HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-
  <span>''<span><font color="#9A1900">/* Populate the selector */</font></span>''</span>
+
  hildon_button_set_title (HILDON_BUTTON (button), "Pick a band!");
-
  <span>'''<span><font color="#0000FF">for</font></span>'''</span> <span><font color="#990000">(</font></span>i <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> artists <span><font color="#990000">[</font></span>i<span><font color="#990000">]</font></span> <span><font color="#990000"><nowiki>!=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span> i<span><font color="#990000">++)</font></span> <span><font color="#FF0000">{</font></span>
+
  /* Create a touch selector entry */
-
    <span>'''<span><font color="#000000">hildon_touch_selector_append_text</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">),</font></span>
+
  selector = hildon_touch_selector_entry_new_text ();
-
                                        artists <span><font color="#990000">[</font></span>i<span><font color="#990000">]);</font></span>
+
  /* Populate the selector */
-
  <span><font color="#FF0000">}</font></span>
+
  for (i = 0; artists [i] != NULL; i++) {
-
  <span>''<span><font color="#9A1900">/* Attach selector to the picker button */</font></span>''</span>
+
    hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
-
  <span>'''<span><font color="#000000">hildon_picker_button_set_selector</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">HILDON_PICKER_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>button<span><font color="#990000">),</font></span>
+
                                      artists [i]);
-
                                      <span>'''<span><font color="#000000">HILDON_TOUCH_SELECTOR</font></span>'''</span> <span><font color="#990000">(</font></span>selector<span><font color="#990000">));</font></span>
+
  }
-
  <span>'''<span><font color="#000000">gtk_container_add</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CONTAINER</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> button<span><font color="#990000">);</font></span>
+
  /* Attach selector to the picker button */
-
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">),</font></span> <span><font color="#FF0000">"destroy"</font></span><span><font color="#990000">,</font></span>
+
  hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
-
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>gtk_main_quit<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
+
                                    HILDON_TOUCH_SELECTOR (selector));
-
  <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_WIDGET</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">));</font></span>
+
  gtk_container_add (GTK_CONTAINER (window), button);
-
  <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span>
+
  g_signal_connect (G_OBJECT (window), "destroy",
-
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> <span><font color="#993399">0</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
+
                    G_CALLBACK (gtk_main_quit), NULL);
-
<span><font color="#FF0000">}</font></span>
+
  gtk_widget_show_all (GTK_WIDGET (window));
-
</tt>
+
  gtk_main ();
 +
  return 0;
 +
}
 +
</source>
As you can see in the example above, the use of this widget is similar to using a normal touchable selector.
As you can see in the example above, the use of this widget is similar to using a normal touchable selector.
-
You can also use custom columns in a HildonTouchableEntry but at least one column must be a text column. The text column is indicated by the property "text_column" which you set with <code>hildon_touch_selector_entry_set_text_column()</code>.
+
You can also use custom columns in a <code>HildonTouchableEntry</code> but at least one column must be a text column. The text column is indicated by the property "<code>text_column</code>" which you set with <code>hildon_touch_selector_entry_set_text_column()</code>.
==Pre-built selectors ==
==Pre-built selectors ==
-
The widgets HildonDateButton and HildonTimeButton are buttons displaying and allowing the selection of date and time, respectively. Developers can use them directly instead of building their own date or time selectors.
+
 
 +
The widgets <code>HildonDateButton</code> and <code>HildonTimeButton</code> are buttons displaying and allowing the selection of date and time, respectively. Developers can use them directly instead of building their own date or time selectors.
Both widgets are specialized picker buttons with a convenient touchable selector attached that you can use directly in your application.
Both widgets are specialized picker buttons with a convenient touchable selector attached that you can use directly in your application.
-
Here a simple application using a HildonDateButton.
+
Here a simple application using a <code>HildonDateButton</code>.
'''Example 6.5. Example of a Hildon date button'''
'''Example 6.5. Example of a Hildon date button'''
-
  #include <hildon/hildon.h>
+
<source lang="c">
-
 
+
#include <hildon/hildon.h>
-
  int
+
 
-
  main (int argc, char **argv)
+
int
-
  {
+
main (int argc, char **argv)
-
    HildonProgram *program = NULL;
+
{
-
    GtkWidget *window = NULL;
+
  HildonProgram *program = NULL;
-
    GtkWidget *picker_button = NULL;
+
  GtkWidget *window = NULL;
-
    
+
  GtkWidget *picker_button = NULL;
-
    hildon_gtk_init (&argc, &argv);
+
 
-
 
+
   hildon_gtk_init (&argc, &argv);
-
    program = hildon_program_get_instance ();
+
 
-
    g_set_application_name
+
  program = hildon_program_get_instance ();
-
      ("hildon-date-button example program");
+
  g_set_application_name
-
    
+
    ("hildon-date-button example program");
-
    window = hildon_stackable_window_new ();
+
 
-
    hildon_program_add_window (program, HILDON_WINDOW (window));
+
   window = hildon_stackable_window_new ();
-
    
+
  hildon_program_add_window (program, HILDON_WINDOW (window));
-
    /* Create a picker button */
+
 
-
    picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
+
   /* Create a picker button */
-
                                            HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+
  picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
-
 
+
                                          HILDON_BUTTON_ARRANGEMENT_VERTICAL);
-
    /* Set a title to the button*/
+
 
-
    hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
+
  /* Set a title to the button*/
-
    
+
  hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
-
    /* Add button to main window */
+
 
-
    gtk_container_add (GTK_CONTAINER (window), picker_button);
+
   /* Add button to main window */
-
    
+
  gtk_container_add (GTK_CONTAINER (window), picker_button);
-
    g_signal_connect (G_OBJECT (window), "destroy",
+
 
-
                      G_CALLBACK (gtk_main_quit), NULL);
+
   g_signal_connect (G_OBJECT (window), "destroy",
-
    
+
                    G_CALLBACK (gtk_main_quit), NULL);
-
    gtk_widget_show_all (GTK_WIDGET (window));
+
 
-
 
+
   gtk_widget_show_all (GTK_WIDGET (window));
-
    gtk_main ();
+
 
-
 
+
  gtk_main ();
-
    return 0;
+
 
-
  }
+
  return 0;
 +
}
 +
</source>

Latest revision as of 14:34, 15 October 2010

Image:Ambox_content.png
This article is legacy documentation, and is superseded by Forum Nokia documentation.
The Forum Nokia documentation is available as the Hildon 2.2 UI style guide, Fremantle master layout guide and the Hildon 2.2 widget UI specification

Hildon provides a set of widgets for data selection specially designed for touchscreens that allows to build simple and easy-to-use interfaces.

The key widget is a selector widget that allows users to select items from one to many predefined lists. It is similar to a combo box but allows several individual pannable columns.

In addition, Hildon also provides a specialized dialog and a specialized button to be used in combination with a selector.

Contents

[edit] Touch selector

HildonTouchSelector is the mentioned selector widget. This widget can display several pannable columns. Each column is represented by a GtkTreeModel and single or multiple selection is allowed.

[edit] Text Columns Example

Let us see the simplest possible example. A selector that shows a single text column.

Example 6.1. Example of a single-column selector

Screenshot of TouchSelector
Single text column TouchSelector
#include <hildon/hildon.h>
 
void selection_changed (HildonTouchSelector * selector, gint column, gpointer user_data);
static GtkWidget *create_simple_selector ();
 
void
selection_changed (HildonTouchSelector * selector, gint column,
                   gpointer user_data)
{
  gchar *current_selection = NULL;
 
  current_selection = hildon_touch_selector_get_current_text (selector);
  g_debug ("Current selection : %s", current_selection);
  g_debug ("User data=%s\n", (gchar*) user_data);
}
 
static GtkWidget *
create_simple_selector ()
{
  GtkWidget *selector = NULL;
  gint i;
 
  /* Create a HildonTouchSelector with a single text column */
  selector = hildon_touch_selector_new_text();
 
  g_signal_connect (G_OBJECT (selector), "changed",
                    G_CALLBACK (selection_changed), (gpointer) "some data");
 
  /* Populate selector */
  for (i = 1; i <= 10 ; i++) {
    gchar *label = g_strdup_printf ("Item %d", i);
 
    /* Add item to the column */
    hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
                                       label);
 
    g_free (label);
  }
 
  /* Set selection mode */
  hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
                                                   HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
 
  return selector;
}
 
int
main (int argc, char **argv)
{
  HildonProgram *program = NULL;
  GtkWidget *window = NULL;
  GtkWidget *selector = NULL;
  GtkWidget *picker_button = NULL;
 
  hildon_gtk_init (&argc, &argv);
 
  program = hildon_program_get_instance ();
  g_set_application_name
    ("hildon-touch-selector example program");
 
  window = hildon_stackable_window_new ();
  hildon_program_add_window (program, HILDON_WINDOW (window));
 
  /* Create touch selector */
  selector = create_simple_selector ();
 
  /* Create a picker button */
  picker_button = hildon_picker_button_new (HILDON_SIZE_AUTO,
                                            HILDON_BUTTON_ARRANGEMENT_VERTICAL);
 
  /* Set a title to the button*/
  hildon_button_set_title (HILDON_BUTTON (picker_button), "Select an item");
 
  /* Attach touch selector to the picker button*/
  hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker_button),
                                     HILDON_TOUCH_SELECTOR (selector));
 
  /* Add button to main window */
  gtk_container_add (GTK_CONTAINER (window), picker_button);
 
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
 
  gtk_widget_show_all (GTK_WIDGET (window));
 
  gtk_main ();
 
  return 0;
}

A HildonTouchSelector with a single text column is created in this program using the following convenience constructor.

GtkWidget*  hildon_touch_selector_new_text  (void);

To add text to a selector created by calling the constructor above, use the function.

void        hildon_touch_selector_append_text (HildonTouchSelector *selector,
                                               const gchar *text);

Alternatively, you can use hildon_touch_selector_prepend_text() or hildon_touch_selector_insert_text() to add text to the selector in different positions.

You can set the desired selection with the function. In the example, the mode was set to allow multiple selection.

void        hildon_touch_selector_set_column_selection_mode (HildonTouchSelector *selector,
                                                             HildonTouchSelectorSelectionMode mode);

This example shows a very common use case of this widget. Next section shows how to build a more complex selector with several columns of different types.

Also a simple function was set as a handler for the "changed" signal which is emitted each time the selected items change.

The callback retrieves a text representation of the currently selected items in the selector by calling hildon_touch_selector_get_current_text(). By default this function returns a concatenation of the items selected, separated by a comma.

To change how the text representation is generated, set your own function by calling hildon_touch_selector_set_print_func() and using the following signature for the function:

gchar*      user_function (HildonTouchSelector *selector);

[edit] Custom columns

In the previous section, a selector with a text column was created. That is probably the most common use case of touch selectors. Convenience functions to deal with text columns was used. However, you can also set other type of columns.

Because each column is basically a treeview, you can use the same display to different data and in different ways as you would do with a GtkTreeview. Thus, you can use the GtkCellRenderers available in GTK+ to display the data on each cell.

This section explains how to build a selector within a column displaying stock icons. Firstly, let us take a look on the function which used for appending new columns to a touchable selector.

HildonTouchSelectorColumn* hildon_touch_selector_append_column (HildonTouchSelector *selector,
                                                                GtkTreeModel *model,
                                                                GtkCellRenderer *cell_renderer,
                                                                ...);

This functions adds a new column to the widget whose data is obtained from the passed model. Pass also a GtkCellRenderer and a list of pairs property/value which is set as attributes of the renderer.

This function basically adds a GtkTreeView to the widget. For more information on how GtkTreeViews work, see GTK+ widgets before. The following example shows how to set a column to display images in a selector. For clarity, only the function which creates the selector is shown.

Example 6.2. Example of a selector with a custom column

Screenshot of TouchSelector
Single column TouchSelector
static GtkWidget *
create_customized_selector()
{
  GtkWidget *selector;
  GSList *icon_list = NULL;
  GtkListStore *store_icons = NULL;
  GSList *item = NULL;
  GtkCellRenderer *renderer = NULL;
  HildonTouchSelectorColumn *column = NULL;
  /* Create a touch selector */
  selector = hildon_touch_selector_new();
  /* Stock icons will be used for the example */
  icon_list = gtk_stock_list_ids();
  /* Create model to store selector's items */
  store_icons = gtk_list_store_new (1, G_TYPE_STRING);
  /* Populate model */
  for (item = icon_list; item; item = g_slist_next (item)) {
    GtkTreeIter iter;
    gchar *label = item->data;
    gtk_list_store_append (store_icons, &iter);
    gtk_list_store_set (store_icons, &iter, 0, label, -1);
    g_free (label);
  }
  g_slist_free (icon_list);
  /* Create and set up a pixbuf renderer to use in the selector */
  renderer = gtk_cell_renderer_pixbuf_new();
  gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
  /* Add the column to the selector */
  column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
                                                GTK_TREE_MODEL (store_icons),
                                                renderer,
                                                "stock-id", 0,
                                                NULL);
  /* Set the selection mode */
  hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
                                    HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
  /* Set the property "text-column" that indicates the column
   * of the model to get the string from */
  g_object_set (G_OBJECT (column), "text-column", 0, NULL);
  return selector;
}

The first step in the example is to create and populate a GtkTreeModel. A GtkListStore is used in the example. In most use cases of the touchable selectors a GtkListStore fits well as selectors were designed to allow users to select from a list of items.

In this case, the model stores a list of GTK+ stock icons identifiers. The following call creates a list store with one column to store strings.

store_icons = gtk_list_store_new (1, G_TYPE_STRING);

The following loop appends all stock identifiers in the newly created model. The identifiers were previously retrieved using

gtk_stock_list_ids().
  for (item = icon_list; item; item = g_slist_next (item)) {
    GtkTreeIter iter;
    gchar *label = item->data;
    gtk_list_store_append (store_icons, &iter);
    gtk_list_store_set (store_icons, &iter, 0, label, -1);
    g_free (label);
  }
  g_slist_free (icon_list);

The next step is to set up the renderer which renders each row of the new column. We need a GtkCellRendererPixbuf to display the stock icons.

renderer = gtk_cell_renderer_pixbuf_new();

Finally, we create and append the new column, using the model and renderer previously created.

This call also sets the property "stock-id" of the GtkCellrendererPixbuf. The value is set to 0 which is the number of the column in the GtkTreeModel that stores the stock-id.

column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
                                        GTK_TREE_MODEL (store_icons),
                                              renderer,
                                              "stock-id", 0,
                                              NULL);

To summarize, setting a new custom column in a touchable selector is quite similar to setting a new column in a normal GtkTreeView. Create a model to store the data and a cell renderer to properly show this data in each row, and finally add the new column.

[edit] Picker dialog and picker buttons

Normally, you use HildonTouchSelector together with a HildonPickerDialog activated from a button. For most common cases you use HildonPickerButton.

This is the usual way to present a selector to the user. The picker button opens a dialog which presents the selector and properly manages user interaction.

Example

Previous sections showed you how to create a touchable selector. In most cases the next step is to attach the selector to a HildonPickerButton.

A HildonPickerButton is a special GtkButton which displays two labels, title and value, and brings up a HildonPickerDialog. The user chooses one or several items. A string representation of the chosen items is displayed in the value label of the picker button.

Below, a modified version of the previous main function is shown, in which you can check how a HildonPickerButton is created and attached to a selector. Also a callback to catch the signal "value-changed" emitted is added.

Screenshot of picker button
PickerButton

Example 6.3. Example of a Hildon picker button

static void
on_picker_value_changed (HildonPickerButton * button, gpointer data)
{
  g_print ("Newly selected value: %s\n",
           hildon_button_get_value (HILDON_BUTTON (button)));
}
 
int
main (int argc, char **argv)
{
  HildonProgram *program;
  GtkWidget *window;
  GtkWidget *picker_button;
 
  hildon_gtk_init (&argc, &argv);
 
  program = hildon_program_get_instance ();
  g_set_application_name ("hildon-touch-selector example program");
 
  window = hildon_stackable_window_new ();
  hildon_program_add_window (program, HILDON_WINDOW (window));
 
  /* Create touch selector */
  selector = create_customized_selector ();
 
  /* Create a picker button */
  picker_button = hildon_picker_button_new (HILDON_SIZE_AUTO,
                                            HILDON_BUTTON_ARRANGEMENT_VERTICAL);
 
  /* Set a title to the button */
  hildon_button_set_title (HILDON_BUTTON (picker_button), "Select an item");
 
  /* Attach the touch selector to the picker button*/
  hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker_button),
                                     HILDON_TOUCH_SELECTOR (selector));
 
  /* Attach callback to the "value-changed" signal*/
  g_signal_connect (G_OBJECT (picker_button), "value-changed",
                    G_CALLBACK (on_picker_value_changed), NULL);
 
  /* Add button to main window */
  gtk_container_add (GTK_CONTAINER (window), picker_button);
 
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
 
  gtk_widget_show_all (GTK_WIDGET (window));
 
  gtk_main ();
 
  return 0;
}

In the above example a picker button is created. The reference to the attached selector is stored in the property "touch-selector" of the picker button. To retrieve the attached selector , use function hildon_picker_button_get_selector(). To attach the selector, use the function hildon_picker_button_set_selector().

Note that you do not need to take care of the HildonPickerDialog. The dialog is automatically brought up when users click the picker button and closed when the selection is done.

The dialog shows a button "Done" to allow users finish the selection when the touchable selector allows multiple selection. When the selector allows only single selection, the dialog does not show any button and closes when the user taps on one item.

The label of the button "Done" can be set by using hildon_picker_button_set_done_button_text() and retrieved by using hildon_picker_button_get_done_button_text().

When users finish their selection, the value label on the button automatically changes to show a textual representation of the item or items selected.

In most cases you want to perform any action when selection is finished. To do that, add a handler to the signal "value-changed" of the picker button. In this example the handler attached to "value-changed" signal retrieves the value label of the button and prints a debug message.

[edit] Touch selector entry

The HildonTouchSelectorEntry is a selector widget with a text entry that allows users to select an item from a predefined list or to enter a different one in a HildonEntry. Items can also be searched and selected by typing in the entry.

An additional feature is that the HildonEntry is auto-completed with the list's items as the user types their name.

Example below shows how to build a selector to pick a word in a list of words.

Screenshot of TouchSelectorEntry
TouchSelectorEntry

Example 6.4. Example of a Hildon picker button with a selector entry

#include <hildon/hildon.h>
 
static const gchar* artists [] = {
  "AC/DC",
  "Aerosmith",
  "Alice in Chains",
  "Black Sabbath",
  "Carcass",
  "Danzig",
  "Deep Purple",
  "Dream Theater",
  "Eric Clapton",
  NULL
};
 
int
main (int argc, char **argv)
{
  HildonProgram *program;
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *selector;
  gint i;
  hildon_gtk_init (&argc, &argv);
  program = hildon_program_get_instance ();
  g_set_application_name
    ("HildonTouchSelectorEntry example program");
  window = hildon_stackable_window_new ();
  hildon_program_add_window (program, HILDON_WINDOW (window));
  /* Create a picker button */
  button = hildon_picker_button_new (HILDON_SIZE_AUTO,
                                     HILDON_BUTTON_ARRANGEMENT_VERTICAL);
  hildon_button_set_title (HILDON_BUTTON (button), "Pick a band!");
  /* Create a touch selector entry */
  selector = hildon_touch_selector_entry_new_text ();
  /* Populate the selector */
  for (i = 0; artists [i] != NULL; i++) {
    hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector),
                                       artists [i]);
  }
  /* Attach selector to the picker button */
  hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
                                     HILDON_TOUCH_SELECTOR (selector));
  gtk_container_add (GTK_CONTAINER (window), button);
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
  gtk_widget_show_all (GTK_WIDGET (window));
  gtk_main ();
  return 0;
}

As you can see in the example above, the use of this widget is similar to using a normal touchable selector.

You can also use custom columns in a HildonTouchableEntry but at least one column must be a text column. The text column is indicated by the property "text_column" which you set with hildon_touch_selector_entry_set_text_column().

[edit] Pre-built selectors

The widgets HildonDateButton and HildonTimeButton are buttons displaying and allowing the selection of date and time, respectively. Developers can use them directly instead of building their own date or time selectors.

Both widgets are specialized picker buttons with a convenient touchable selector attached that you can use directly in your application.

Here a simple application using a HildonDateButton.

Example 6.5. Example of a Hildon date button

#include <hildon/hildon.h>
 
int
main (int argc, char **argv)
{
  HildonProgram *program = NULL;
  GtkWidget *window = NULL;
  GtkWidget *picker_button = NULL;
 
  hildon_gtk_init (&argc, &argv);
 
  program = hildon_program_get_instance ();
  g_set_application_name
    ("hildon-date-button example program");
 
  window = hildon_stackable_window_new ();
  hildon_program_add_window (program, HILDON_WINDOW (window));
 
  /* Create a picker button */
  picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
                                          HILDON_BUTTON_ARRANGEMENT_VERTICAL);
 
  /* Set a title to the button*/
  hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
 
  /* Add button to main window */
  gtk_container_add (GTK_CONTAINER (window), picker_button);
 
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
 
  gtk_widget_show_all (GTK_WIDGET (window));
 
  gtk_main ();
 
  return 0;
}