Editing Legacy Maemo 5 Documentation/Graphical UI Tutorial/Navigation
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
{{Legacy documentation}} | {{Legacy documentation}} | ||
+ | =Navigation = | ||
In previous examples only one widget was added to a window so we can simply use a <code>gtk_container_add()</code> to "pack" it into the window. To pack more than one widget into a window, use container widgets. | In previous examples only one widget was added to a window so we can simply use a <code>gtk_container_add()</code> to "pack" it into the window. To pack more than one widget into a window, use container widgets. | ||
To develop Hildon user interfaces, use any container widget provided by GTK+. For more information, see the GTK+ 2.0 Tutorial. | To develop Hildon user interfaces, use any container widget provided by GTK+. For more information, see the GTK+ 2.0 Tutorial. | ||
- | Apart from supporting those containers, the Hildon framework also provides a new container widget called | + | Apart from supporting those containers, the Hildon framework also provides a new container widget called HildonPannableArea, a scrolling widget designed for touch screens. |
- | |||
- | + | == Pannable area == | |
+ | HildonPannableArea is used to create an area with another widget inside which is accessible regardless of the size using the touchscreen to scroll it. You can insert any type of widget into a pannable area; it is always accessible by using the fingers to pan, or scroll, in the area. | ||
This widget can be "panned" (scrolled) in any direction using the touchscreen with the fingers. One remarkable characteristic is that the scrolling is "kinetic", meaning that the motion continues from the initial motion by gradually slowing down to stop. | This widget can be "panned" (scrolled) in any direction using the touchscreen with the fingers. One remarkable characteristic is that the scrolling is "kinetic", meaning that the motion continues from the initial motion by gradually slowing down to stop. | ||
Line 17: | Line 18: | ||
To create a new pannable area, choose one of the following functions: | To create a new pannable area, choose one of the following functions: | ||
- | < | + | <tt>GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_pannable_area_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span> |
- | + | GtkWidget<span><font color="#990000"><nowiki>*</nowiki></font></span> <span>'''<span><font color="#000000">hildon_pannable_area_new_full</font></span>'''</span> <span><font color="#990000">(</font></span>gint mode<span><font color="#990000">,</font></span> | |
- | GtkWidget* hildon_pannable_area_new_full (gint mode, | + | gboolean enabled<span><font color="#990000">,</font></span> |
- | + | gdouble vel_min<span><font color="#990000">,</font></span> | |
- | + | gdouble vel_max<span><font color="#990000">,</font></span> | |
- | + | gdouble decel<span><font color="#990000">,</font></span> | |
- | + | guint sps<span><font color="#990000">);</font></span> | |
- | + | </tt> | |
- | </ | + | |
The first one creates a new pannable area with the properties set to the default values. The second one allows you to set the value of the most important properties of this widget: | The first one creates a new pannable area with the properties set to the default values. The second one allows you to set the value of the most important properties of this widget: | ||
- | * | + | * mode: Used to change the behaviour of the pannable area allowing to choose whether to use the "kinetic" effect described above. |
- | * | + | * enabled: Enable or disable finger-scroll. |
- | * | + | * vel_min, vel_max: Allows developers to adjust how many pixels the child widget moves per "frame". |
- | * | + | * decel: Value for the deceleration property. |
- | * | + | * sps: Amount of scroll events to generate per second. |
The default values of these properties are right for most applications and so the simpler constructor is sufficient. For more information on the properties of the pannable area, see the Hildon reference manual. | The default values of these properties are right for most applications and so the simpler constructor is sufficient. For more information on the properties of the pannable area, see the Hildon reference manual. | ||
Line 39: | Line 39: | ||
When the area is created, place your object into the pannable window using the following function. | When the area is created, place your object into the pannable window using the following function. | ||
- | < | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_pannable_area_add_with_viewport</font></span>'''</span> <span><font color="#990000">(</font></span>HildonPannableArea <span><font color="#990000"><nowiki>*</nowiki></font></span>area<span><font color="#990000">,</font></span> |
- | void hildon_pannable_area_add_with_viewport (HildonPannableArea *area, | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>child<span><font color="#990000">);</font></span> |
- | + | </tt> | |
- | </ | + | |
- | That is a convenience function used to add a child to a | + | That is a convenience function used to add a child to a GtkViewport, and add the viewport to the pannable area. |
'''Warning''' | '''Warning''' | ||
- | Add widgets with native scrolling directly inside a pannable area. Add widgets such as | + | Add widgets with native scrolling directly inside a pannable area. Add widgets such as GtkTextView, GtkTreeView, GtkIconView and GtkLayout by calling <code>gtk_container_add()</code>. Otherwise, panning may not work properly. |
- | |||
+ | ==Pannable area example == | ||
Functions explained above are enough for a simple example. The following example packs a table with 100 toggle buttons into a pannable area. | Functions explained above are enough for a simple example. The following example packs a table with 100 toggle buttons into a pannable area. | ||
- | [[Image:example-pannable-area.png| | + | [[Image:example-pannable-area.png|400px]] |
'''Example 5.1. Example of a pannable area''' | '''Example 5.1. Example of a pannable area''' | ||
- | < | + | <tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000"><stdio.h></font></span> |
- | #include <stdio.h> | + | <span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000"><hildon/hildon.h></font></span> |
- | #include <hildon/hildon.h> | + | |
- | + | <span>'''<span><font color="#0000FF">static</font></span>'''</span> GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span><span>'''<span><font color="#000000">create_table</font></span>'''</span> <span><font color="#990000">()</font></span> | |
- | static GtkWidget *create_table () | + | <span><font color="#FF0000">{</font></span> |
- | { | + | |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>hbox<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>table<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>button<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | <span><font color="#009900">char</font></span> buffer<span><font color="#990000">[</font></span><span><font color="#993399">32</font></span><span><font color="#990000">];</font></span> | |
- | + | <span><font color="#009900">int</font></span> i<span><font color="#990000">,</font></span> j<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | ||
- | + | <span>''<span><font color="#9A1900">/* create a table of 10 by 10 squares. */</font></span>''</span> | |
- | + | table <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_table_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#993399">10</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">10</font></span><span><font color="#990000">,</font></span> FALSE<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>''<span><font color="#9A1900">/* set the spacing to 10 on x and 10 on y */</font></span>''</span> | |
- | + | <span>'''<span><font color="#000000">gtk_table_set_row_spacings</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TABLE</font></span>'''</span> <span><font color="#990000">(</font></span>table<span><font color="#990000">),</font></span> <span><font color="#993399">10</font></span><span><font color="#990000">);</font></span> | |
- | + | <span>'''<span><font color="#000000">gtk_table_set_col_spacings</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TABLE</font></span>'''</span> <span><font color="#990000">(</font></span>table<span><font color="#990000">),</font></span> <span><font color="#993399">10</font></span><span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>'''<span><font color="#000000">gtk_widget_show</font></span>'''</span> <span><font color="#990000">(</font></span>table<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>''<span><font color="#9A1900">/* this simply creates a grid of toggle buttons on the table</font></span>''</span> | |
- | + | <span>''<span><font color="#9A1900"> * to demonstrate the scrolled window. */</font></span>''</span> | |
- | + | <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">1</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> i <span><font color="#990000"><</font></span> <span><font color="#993399">10</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> i<span><font color="#990000">++)</font></span> | |
- | + | <span>'''<span><font color="#0000FF">for</font></span>'''</span> <span><font color="#990000">(</font></span>j <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">1</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> j <span><font color="#990000"><</font></span> <span><font color="#993399">10</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> j<span><font color="#990000">++)</font></span> <span><font color="#FF0000">{</font></span> | |
- | + | <span>'''<span><font color="#000000">sprintf</font></span>'''</span> <span><font color="#990000">(</font></span>buffer<span><font color="#990000">,</font></span> <span><font color="#FF0000">"button (%d,%d)</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">,</font></span> i<span><font color="#990000">,</font></span> j<span><font color="#990000">);</font></span> | |
- | + | button <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_toggle_button_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span>buffer<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>'''<span><font color="#000000">gtk_table_attach_defaults</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TABLE</font></span>'''</span> <span><font color="#990000">(</font></span>table<span><font color="#990000">),</font></span> button<span><font color="#990000">,</font></span> | |
- | + | i<span><font color="#990000">,</font></span> i<span><font color="#990000">+</font></span><span><font color="#993399">1</font></span><span><font color="#990000">,</font></span> j<span><font color="#990000">,</font></span> j<span><font color="#990000">+</font></span><span><font color="#993399">1</font></span><span><font color="#990000">);</font></span> | |
- | + | <span><font color="#FF0000">}</font></span> | |
- | + | ||
- | + | <span>'''<span><font color="#0000FF">return</font></span>'''</span> table<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | <span><font color="#FF0000">}</font></span> | |
- | } | + | |
- | + | <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> | |
- | int main( int argc, | + | <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="#990000">)</font></span> |
- | + | <span><font color="#FF0000">{</font></span> | |
- | { | + | <span>'''<span><font color="#0000FF">static</font></span>'''</span> GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>window<span><font color="#990000"><nowiki>;</nowiki></font></span> |
- | + | 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>pannable_area<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>table<span><font color="#990000"><nowiki>;</nowiki></font></span> | |
- | + | ||
- | + | <span>'''<span><font color="#000000">hildon_gtk_init</font></span>'''</span> <span><font color="#990000">(&</font></span>argc<span><font color="#990000">,</font></span> <span><font color="#990000">&</font></span>argv<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | 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">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_widget_destroy<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | pannable_area <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_pannable_area_new</font></span>'''</span> <span><font color="#990000">();</font></span> | |
- | + | ||
- | + | table <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">create_table</font></span>'''</span> <span><font color="#990000">();</font></span> | |
- | + | ||
- | + | <span>''<span><font color="#9A1900">/* pack the table into the scrolled window */</font></span>''</span> | |
- | + | <span>'''<span><font color="#000000">hildon_pannable_area_add_with_viewport</font></span>'''</span> <span><font color="#990000">(</font></span> | |
- | + | <span>'''<span><font color="#000000">HILDON_PANNABLE_AREA</font></span>'''</span> <span><font color="#990000">(</font></span>pannable_area<span><font color="#990000">),</font></span> table<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>''<span><font color="#9A1900">/* Add the box into the 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> pannable_area<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>'''<span><font color="#000000">gtk_widget_show_all</font></span>'''</span> <span><font color="#990000">(</font></span>window<span><font color="#990000">);</font></span> | |
- | + | ||
- | + | <span>'''<span><font color="#000000">gtk_main</font></span>'''</span> <span><font color="#990000">();</font></span> | |
- | + | ||
- | + | <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> | |
- | } | + | </tt> |
- | </ | + | |
In the example above, two calls are enough to use a pannable area. The rest of the code in the example is no different from the one used in a GTK+ application. | In the example above, two calls are enough to use a pannable area. The rest of the code in the example is no different from the one used in a GTK+ application. | ||
- | < | + | <tt> <span>''<span><font color="#9A1900">/* Create a new pannable area. */</font></span>''</span> |
- | /* Create a new pannable area. */ | + | pannable_area <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">hildon_pannable_area_new</font></span>'''</span> <span><font color="#990000">();</font></span> |
- | pannable_area = hildon_pannable_area_new (); | + | <span>''<span><font color="#9A1900">/* Pack the table into the pannable area */</font></span>''</span> |
- | /* Pack the table into the pannable area */ | + | <span>'''<span><font color="#000000">hildon_pannable_area_add_with_viewport</font></span>'''</span> <span><font color="#990000">(</font></span> <span>'''<span><font color="#000000">HILDON_PANNABLE_AREA</font></span>'''</span> <span><font color="#990000">(</font></span>pannable_area<span><font color="#990000">),</font></span> table<span><font color="#990000">);</font></span> |
- | hildon_pannable_area_add_with_viewport ( | + | </tt> |
- | </ | + | |
- | + | ||
- | + | ||
- | + | To see all the buttons, users can scroll with the fingers. In this example, horizontal and vertical panning are activated because that is needed to allow users to be able to interact both all the widgets. The property "mov-mode" controls if the area can scroll horizontally, vertically (default value) or both, using HILDON_MOVEMENT_MODE_HORIZ, HILDON_MOVEMENT_MODE_VERT or HILDON_MOVEMENT_MODE_BOTH, respectively. | |
+ | ==Additional features == | ||
Pannable areas provide a set of convenience functions that make it easier to move to a certain element inside the area without users interaction. | Pannable areas provide a set of convenience functions that make it easier to move to a certain element inside the area without users interaction. | ||
Line 146: | Line 142: | ||
For example, the first of the functions changes the current position on the pannable area to ensure position (x,y) is visible. The movement is a quick jump. The second function performs a smoothly scroll towards the selected position. | For example, the first of the functions changes the current position on the pannable area to ensure position (x,y) is visible. The movement is a quick jump. The second function performs a smoothly scroll towards the selected position. | ||
- | < | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_pannable_area_jump_to</font></span>'''</span> <span><font color="#990000">(</font></span>HildonPannableArea <span><font color="#990000"><nowiki>*</nowiki></font></span>area<span><font color="#990000">,</font></span> |
- | void hildon_pannable_area_jump_to (HildonPannableArea *area, | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gint x<span><font color="#990000">,</font></span> |
- | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gint y<span><font color="#990000">);</font></span> | |
- | + | <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_pannable_area_scroll_to</font></span>'''</span> <span><font color="#990000">(</font></span>HildonPannableArea <span><font color="#990000"><nowiki>*</nowiki></font></span>area<span><font color="#990000">,</font></span> | |
- | void hildon_pannable_area_scroll_to (HildonPannableArea *area, | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gint x<span><font color="#990000">,</font></span> |
- | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gint y<span><font color="#990000">);</font></span> | |
- | + | </tt> | |
- | </ | + | |
The following functions make it possible to jump or scroll to a certain descendent of the area. The argument should be a reference to a descendent widget. | The following functions make it possible to jump or scroll to a certain descendent of the area. The argument should be a reference to a descendent widget. | ||
- | < | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">hildon_pannable_area_jump_to_child</font></span>'''</span> <span><font color="#990000">(</font></span>HildonPannableArea <span><font color="#990000"><nowiki>*</nowiki></font></span>area<span><font color="#990000">,</font></span> |
- | void hildon_pannable_area_jump_to_child (HildonPannableArea *area, | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>child<span><font color="#990000">);</font></span> |
- | + | <span><font color="#009900">void</font></span> hildon_pannable_area_scroll_to_child | |
- | void hildon_pannable_area_scroll_to_child | + | <span><font color="#990000">(</font></span>HildonPannableArea <span><font color="#990000"><nowiki>*</nowiki></font></span>area<span><font color="#990000">,</font></span> |
- | + | GtkWidget <span><font color="#990000"><nowiki>*</nowiki></font></span>child<span><font color="#990000">);</font></span> | |
- | + | </tt> | |
- | </ | + | |
- | Here is a modified version of the previous example. The pannable area is packed into an | + | Here is a modified version of the previous example. The pannable area is packed into an GtkVBox and a new button is also added to navigate to the last clicked button. |
'''Example 5.2. Example of a pannable area and a "jump-to" button''' | '''Example 5.2. Example of a pannable area and a "jump-to" button''' | ||
- | + | #include <stdio.h> | |
- | #include <stdio.h> | + | #include <hildon/hildon.h> |
- | #include <hildon/hildon.h> | + | |
- | + | GtkWidget * last_clicked_button; | |
- | GtkWidget * last_clicked_button; | + | GtkWidget * pannable_area; |
- | GtkWidget * pannable_area; | + | |
- | + | ||
- | + | static void destroy( GtkWidget *widget, | |
- | static void destroy( GtkWidget *widget, | + | gpointer data ) |
- | + | { | |
- | { | + | gtk_main_quit (); |
- | + | } | |
- | } | + | |
- | + | static void clicked (GtkButton *button, | |
- | static void clicked (GtkButton *button, | + | gpointer user_data) |
- | + | { | |
- | { | + | last_clicked_button = GTK_WIDGET (button); |
- | + | } | |
- | } | + | |
- | + | static void go_to_last_clicked (GtkButton *button, | |
- | static void go_to_last_clicked (GtkButton *button, | + | gpointer user_data) |
- | + | { | |
- | { | + | hildon_pannable_area_jump_to_child (HILDON_PANNABLE_AREA (pannable_area), |
- | + | last_clicked_button); | |
- | + | } | |
- | } | + | |
- | + | static GtkWidget *create_table () | |
- | static GtkWidget *create_table () | + | { |
- | { | + | GtkWidget *table; |
- | + | GtkWidget *button; | |
- | + | char buffer[32]; | |
- | + | int i, j; | |
- | + | ||
- | + | /* create a table of 10 by 10 squares. */ | |
- | + | table = gtk_table_new (10, 10, FALSE); | |
- | + | ||
- | + | /* set the spacing to 10 on x and 10 on y */ | |
- | + | gtk_table_set_row_spacings (GTK_TABLE (table), 10); | |
- | + | gtk_table_set_col_spacings (GTK_TABLE (table), 10); | |
- | + | ||
- | + | gtk_widget_show (table); | |
- | + | ||
- | + | /* this simply creates a grid of toggle buttons on the table | |
- | + | * to demonstrate the scrolled window. */ | |
- | + | for (i = 1; i < 10; i++) | |
- | + | for (j = 1; j < 10; j++) { | |
- | + | sprintf (buffer, "button (%d,%d)\n", i, j); | |
- | + | button = gtk_toggle_button_new_with_label (buffer); | |
- | + | ||
- | + | g_signal_connect (G_OBJECT (button), | |
- | + | "clicked", | |
- | + | G_CALLBACK (clicked), | |
- | + | NULL); | |
- | + | ||
- | + | gtk_table_attach_defaults (GTK_TABLE (table), button, | |
- | + | i, i+1, j, j+1); | |
- | + | ||
- | + | gtk_widget_show (button); | |
- | + | } | |
- | + | ||
- | + | return table; | |
- | + | } | |
- | } | + | |
- | + | int main( int argc, | |
- | int main( int argc, | + | char *argv[] ) |
- | + | { | |
- | { | + | static GtkWidget *window; |
- | + | GtkWidget *button; | |
- | + | GtkWidget *table; | |
- | + | GtkWidget *hbox; | |
- | + | ||
- | + | hildon_gtk_init (&argc, &argv); | |
- | + | ||
- | + | /* Create a new hildon window for the pannable area to be | |
- | + | * packed into. */ | |
- | + | window = hildon_stackable_window_new (); | |
- | + | g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); | |
- | + | gtk_window_set_title (GTK_WINDOW (window), "HildonPannableArea example"); | |
- | + | ||
- | + | /* Create a table which will be inside the pannable area */ | |
- | + | table = create_table (); | |
- | + | ||
- | + | /* Create a box and pack the widgets into it */ | |
- | + | hbox = gtk_hbox_new (FALSE, 0); | |
- | + | ||
- | + | /* Add a button to jump */ | |
- | + | /* Button to go to last clicked */ | |
- | + | button = gtk_button_new_with_label ("Go to last clicked"); | |
- | + | ||
- | + | g_signal_connect (G_OBJECT (button), | |
- | + | "clicked", | |
- | + | G_CALLBACK (go_to_last_clicked), | |
- | + | NULL); | |
- | + | ||
- | + | gtk_box_pack_start (GTK_BOX (hbox), | |
- | + | button, | |
- | + | FALSE, | |
- | + | FALSE, | |
- | + | 0); | |
- | + | ||
- | + | /* create a new pannable area. */ | |
- | + | pannable_area = hildon_pannable_area_new (); | |
- | + | g_object_set (G_OBJECT (pannable_area), | |
- | + | "mov-mode", HILDON_MOVEMENT_MODE_BOTH, NULL); | |
- | + | ||
- | + | /* pack the table into the scrolled window */ | |
- | + | hildon_pannable_area_add_with_viewport ( | |
- | + | HILDON_PANNABLE_AREA (pannable_area), table); | |
- | + | ||
- | + | gtk_box_pack_start (GTK_BOX (hbox), | |
- | + | pannable_area, | |
- | + | TRUE, | |
- | + | TRUE, | |
- | + | 0); | |
- | + | ||
- | + | /* Add the box into the window*/ | |
- | + | gtk_container_add (GTK_CONTAINER (window), hbox); | |
- | + | ||
- | + | gtk_widget_show_all (window); | |
- | + | gtk_main(); | |
- | + | ||
- | + | return 0; | |
- | + | } | |
- | } | + | |
- | + | ||
- | The example used a global variable to store a reference to the last clicked button. This reference is used by the callback | + | The example used a global variable to store a reference to the last clicked button. This reference is used by the callback go_to_last_clicked to jump to it by calling one of the navigation functions. This function is used as a handler for the signal "clicked" of the button outside the pannable area. |
To test the different navigation functions, just change the call in the callback. | To test the different navigation functions, just change the call in the callback. | ||
- | When you use the navigation functions that allow to navigate to a certain child, the widget must already be realized. Use the | + | When you use the navigation functions that allow to navigate to a certain child, the widget must already be realized. Use the GTK_WIDGET_REALIZED macro to check it. If you want to call it during the initialization process, use the navigation function inside a callback to the "realized" signal, connecting it with <code>g_signal_connect_after()</code>. |
Learn more about Contributing to the wiki.