Legacy Maemo 5 Documentation/Graphical UI Tutorial/Additions to GTK+

m (Documentation/Maemo 5 Developer Guide/Graphical UI Tutorial/Additions to GTK+ moved to Legacy Maemo 5 Documentation/Graphical UI Tutorial/Additions to GTK+: Phase out from Maemo Developer Guide, superceded by Official Nokia Forum documentation)
(wikify slightly)
 
(One intermediate revision not shown)
Line 1: Line 1:
-
= Additions to GTK+=
+
{{Legacy documentation}}
-
A Hildon application can use any Gtk widget but in some cases you need to adapt the widgets to fit them perfectly.
+
-
 
+
-
Hildon provides a set of convenience functions to do that. Next sections explains these addictions
+
 +
A Hildon application can use any GTK+ widget but in some cases you need to adapt the widgets to fit them perfectly.
 +
Hildon provides a set of convenience functions to do that. The next section explains these additions
==Hildon size types==
==Hildon size types==
 +
Hildon defines the following sizes to be used as sizes for widgets such as buttons or entries in your Hildon application.
Hildon defines the following sizes to be used as sizes for widgets such as buttons or entries in your Hildon application.
-
HILDON_SIZE_AUTO_WIDTH (set to automatic width)
+
* <code>HILDON_SIZE_AUTO_WIDTH</code> (set to automatic width)
-
+
* <code>HILDON_SIZE_HALFSCREEN_WIDTH</code> (set to 50% screen width)
-
HILDON_SIZE_HALFSCREEN_WIDTH (set to 50% screen width)
+
* <code>HILDON_SIZE_FULLSCREEN_WIDTH</code> (set to 100% screen width)
-
+
* <code>HILDON_SIZE_AUTO_HEIGHT</code> (set to automatic height)
-
HILDON_SIZE_FULLSCREEN_WIDTH (set to 100% screen width)
+
* <code>HILDON_SIZE_FINGER_HEIGHT</code> (set to finger height)
-
+
* <code>HILDON_SIZE_THUMB_HEIGHT</code> (set to thumb height)
-
HILDON_SIZE_AUTO_HEIGHT (set to automatic height)
+
* <code>HILDON_SIZE_AUTO</code> (set to automatic width and automatic height)
-
+
-
HILDON_SIZE_FINGER_HEIGHT   (set to finger height)
+
-
+
-
HILDON_SIZE_THUMB_HEIGHT (set to thumb height)
+
-
+
-
HILDON_SIZE_AUTO (set to automatic width and automatic height)
+
Hildon widgets allow you to set their sizes in their construction functions, but in case you want to set the size of a GTK+ widget, Hildon also provides functions to do that:
Hildon widgets allow you to set their sizes in their construction functions, but in case you want to set the size of a GTK+ widget, Hildon also provides functions to do that:
-
GtkWidget*  hildon_gtk_button_new          (HildonSizeType size);
+
<source lang="c">
-
GtkWidget*  hildon_gtk_toggle_button_new    (HildonSizeType size);
+
GtkWidget*  hildon_gtk_button_new          (HildonSizeType size);
-
GtkWidget*  hildon_gtk_radio_button_new    (HildonSizeType size,
+
GtkWidget*  hildon_gtk_toggle_button_new    (HildonSizeType size);
-
                                              GSList *group);
+
GtkWidget*  hildon_gtk_radio_button_new    (HildonSizeType size,
-
GtkWidget*  hildon_gtk_radio_button_new_from_widget
+
                                              GSList *group);
-
                                            (HildonSizeType size,
+
GtkWidget*  hildon_gtk_radio_button_new_from_widget
-
                                              GtkRadioButton *radio_group_member);
+
                                            (HildonSizeType size,
-
 
+
                                            GtkRadioButton *radio_group_member);
 +
</source>
==UI Modes==
==UI Modes==
 +
Hildon defines two modes in the UI that change the way user interacts with certain widgets. The main purpose of these modes is to enable direct manipulation of items while still allowing the user to select single or multiple items. The following modes are supported:
Hildon defines two modes in the UI that change the way user interacts with certain widgets. The main purpose of these modes is to enable direct manipulation of items while still allowing the user to select single or multiple items. The following modes are supported:
===Normal mode===
===Normal mode===
 +
Normal mode is the default mode. In lists and grids, tapping on an item causes a direct action. In views, this direct action could open a new subview to perform a certain action with the item.
Normal mode is the default mode. In lists and grids, tapping on an item causes a direct action. In views, this direct action could open a new subview to perform a certain action with the item.
===Edit mode===
===Edit mode===
 +
Edit mode is used in Edit Mode views and in some dialogs. The purpose of this mode is providing single or multiple selection functionality in list or grid and providing standard UI for editing single content item.
Edit mode is used in Edit Mode views and in some dialogs. The purpose of this mode is providing single or multiple selection functionality in list or grid and providing standard UI for editing single content item.
Hildon provides the following functions to set mode for a treeview or icon view.
Hildon provides the following functions to set mode for a treeview or icon view.
-
GtkWidget*  hildon_gtk_tree_view_new            (HildonUIMode mode);
+
<source lang="c">
-
GtkWidget*  hildon_gtk_tree_view_new_with_model (HildonUIMode mode,
+
GtkWidget*  hildon_gtk_tree_view_new            (HildonUIMode mode);
-
                                                  GtkTreeModel *model);
+
GtkWidget*  hildon_gtk_tree_view_new_with_model (HildonUIMode mode,
-
void        hildon_gtk_tree_view_set_ui_mode    (GtkTreeView *treeview,
+
                                                GtkTreeModel *model);
-
                                                  HildonUIMode mode);
+
void        hildon_gtk_tree_view_set_ui_mode    (GtkTreeView *treeview,
-
GtkWidget*  hildon_gtk_icon_view_new            (HildonUIMode mode);
+
-
GtkWidget*  hildon_gtk_icon_view_new_with_model (HildonUIMode mode,
+
-
                                                  GtkTreeModel *model);
+
-
void        hildon_gtk_icon_view_set_ui_mode    (GtkIconView *iconview,
+
                                                 HildonUIMode mode);
                                                 HildonUIMode mode);
 +
GtkWidget*  hildon_gtk_icon_view_new            (HildonUIMode mode);
 +
GtkWidget*  hildon_gtk_icon_view_new_with_model (HildonUIMode mode,
 +
                                                GtkTreeModel *model);
 +
void        hildon_gtk_icon_view_set_ui_mode    (GtkIconView *iconview,
 +
                                                HildonUIMode mode);
 +
</source>
-
The enum HildonUIMode defines the following flags:
+
The enum <code>HildonUIMode</code> defines the following flags:
-
HILDON_UI_MODE_NORMAL
+
* <code>HILDON_UI_MODE_NORMAL</code>
-
HILDON_UI_MODE_EDIT
+
* <code>HILDON_UI_MODE_EDIT</code>
-
When you use a list or grid in the edit mode inside a window you should use a HildonEditToolbar to control the edition and set the window to fullscreen, building an Edit subview. For more information about edit views, see the Toolbars chapter. In that chapter you can check an example of HildonToolbar, which uses the concepts explained above.
+
When you use a list or grid in the edit mode inside a window you should use a <code>HildonEditToolbar</code> to control the edition and set the window to fullscreen, building an Edit subview. For more information about edit views, see the [[Legacy Maemo 5 Documentation/Graphical UI Tutorial/Toolbars|Toolbars chapter]]. In that chapter you can check an example of <code>HildonToolbar</code>, which uses the concepts explained above.
==Seek Bars==
==Seek Bars==
-
The seek bars are a useful way to select a value from a range of predetermined values by adjusting the slider with a finger. These seek bars can be horizontal or vertical and are implemented using GtkVScale and GtkHScale. Thus, you can use this GTK+ widget in your Hildon application as seek bar, but use the following creation function instead of the GTK ones:
 
-
GtkWidget*  hildon_gtk_hscale_new          (void);
+
The seek bars are a useful way to select a value from a range of predetermined values by adjusting the slider with a finger. These seek bars can be horizontal or vertical and are implemented using <code>GtkVScale</code> and <code>GtkHScale</code>. Thus, you can use this GTK+ widget in your Hildon application as seek bar, but use the following creation function instead of the GTK+ ones:
-
GtkWidget*  hildon_gtk_vscale_new          (void);
+
 +
<source lang="c">
 +
GtkWidget*  hildon_gtk_hscale_new          (void);
 +
GtkWidget*  hildon_gtk_vscale_new          (void);
 +
</source>
      
      
Scales created by using these constructors has a hildonized behavior, meaning that when the user taps or clicks a point of the bar, it immediately jumps to the desired position.
Scales created by using these constructors has a hildonized behavior, meaning that when the user taps or clicks a point of the bar, it immediately jumps to the desired position.
==Progress indicators==
==Progress indicators==
 +
A convenient way to inform the user that a long-term task is being performed is to show a progress indicator icon in the window or dialog title.
A convenient way to inform the user that a long-term task is being performed is to show a progress indicator icon in the window or dialog title.
-
Hildon provides the following function to show a progress icon. This function applies to HildonWindow and GtkDialog.
+
Hildon provides the following function to show a progress icon. This function applies to <code>HildonWindow</code> and <code>GtkDialog</code>.
-
void        hildon_gtk_window_set_progress_indicator (GtkWindow *window,
+
<source lang="c">
-
                                                      guint state);
+
void        hildon_gtk_window_set_progress_indicator (GtkWindow *window,
-
 
+
                                                      guint state);
-
   
+
</source>
The argument state must be 1 to show the indicator and 0 to hide it.
The argument state must be 1 to show the indicator and 0 to hide it.
-
Here, a little example that sets a progress indicator in a GtkDialog.
+
Here, a little example that sets a progress indicator in a <code>GtkDialog</code>.
Example 8.1. Adding a progress indicator to a dialog
Example 8.1. Adding a progress indicator to a dialog
-
  #include <hildon/hildon.h>
+
<source lang="c">
-
 
+
#include <hildon/hildon.h>
-
  int main( int  argc, char *argv[] )
+
 
-
  {
+
int main( int  argc, char *argv[] )
-
    GtkWidget *dialog;
+
{
 +
  GtkWidget *dialog;
 +
 
 +
  hildon_gtk_init (&argc, &argv);
 +
 
 +
  dialog = gtk_dialog_new ();
 +
 
 +
  gtk_window_set_title (GTK_WINDOW (dialog),
 +
                        "Performing a long task");
 +
 
 +
  gtk_widget_show  (dialog);
 +
 
 +
  hildon_gtk_window_set_progress_indicator (GTK_WINDOW (dialog),
 +
                                            1);
    
    
-
    hildon_gtk_init (&argc, &argv);
+
   gtk_dialog_run (GTK_DIALOG (dialog));
-
    
+
 
-
    dialog = gtk_dialog_new ();
+
   return 0;
-
 
+
}
-
    gtk_window_set_title (GTK_WINDOW (dialog),
+
</source>
-
                          "Performing a long task");
+
-
 
+
-
    gtk_widget_show  (dialog);
+
-
 
+
-
    hildon_gtk_window_set_progress_indicator (GTK_WINDOW (dialog),
+
-
                                              1);
+
-
 
+
-
    gtk_dialog_run (GTK_DIALOG (dialog));
+
-
    
+
-
    return 0;
+
-
  }
+
Additionally, if you consider that additional text information should be given to the user, use an informational banner.
Additionally, if you consider that additional text information should be given to the user, use an informational banner.
Another convenient way to indicate to the user that a long operation is being performed is using the [http://maemo.org/api_refs/5.0/beta/gtk/GtkProgressBar.html GtkProgressBar] widget.
Another convenient way to indicate to the user that a long operation is being performed is using the [http://maemo.org/api_refs/5.0/beta/gtk/GtkProgressBar.html GtkProgressBar] widget.

Latest revision as of 12:44, 14 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

A Hildon application can use any GTK+ widget but in some cases you need to adapt the widgets to fit them perfectly.

Hildon provides a set of convenience functions to do that. The next section explains these additions

Contents

[edit] Hildon size types

Hildon defines the following sizes to be used as sizes for widgets such as buttons or entries in your Hildon application.

  • HILDON_SIZE_AUTO_WIDTH (set to automatic width)
  • HILDON_SIZE_HALFSCREEN_WIDTH (set to 50% screen width)
  • HILDON_SIZE_FULLSCREEN_WIDTH (set to 100% screen width)
  • HILDON_SIZE_AUTO_HEIGHT (set to automatic height)
  • HILDON_SIZE_FINGER_HEIGHT (set to finger height)
  • HILDON_SIZE_THUMB_HEIGHT (set to thumb height)
  • HILDON_SIZE_AUTO (set to automatic width and automatic height)

Hildon widgets allow you to set their sizes in their construction functions, but in case you want to set the size of a GTK+ widget, Hildon also provides functions to do that:

GtkWidget*  hildon_gtk_button_new           (HildonSizeType size);
GtkWidget*  hildon_gtk_toggle_button_new    (HildonSizeType size);
GtkWidget*  hildon_gtk_radio_button_new     (HildonSizeType size,
                                              GSList *group);
GtkWidget*  hildon_gtk_radio_button_new_from_widget
                                            (HildonSizeType size,
                                             GtkRadioButton *radio_group_member);

[edit] UI Modes

Hildon defines two modes in the UI that change the way user interacts with certain widgets. The main purpose of these modes is to enable direct manipulation of items while still allowing the user to select single or multiple items. The following modes are supported:

[edit] Normal mode

Normal mode is the default mode. In lists and grids, tapping on an item causes a direct action. In views, this direct action could open a new subview to perform a certain action with the item.

[edit] Edit mode

Edit mode is used in Edit Mode views and in some dialogs. The purpose of this mode is providing single or multiple selection functionality in list or grid and providing standard UI for editing single content item.

Hildon provides the following functions to set mode for a treeview or icon view.

GtkWidget*  hildon_gtk_tree_view_new            (HildonUIMode mode);
GtkWidget*  hildon_gtk_tree_view_new_with_model (HildonUIMode mode,
                                                 GtkTreeModel *model);
void        hildon_gtk_tree_view_set_ui_mode    (GtkTreeView *treeview,
                                                 HildonUIMode mode);
GtkWidget*  hildon_gtk_icon_view_new            (HildonUIMode mode);
GtkWidget*  hildon_gtk_icon_view_new_with_model (HildonUIMode mode,
                                                 GtkTreeModel *model);
void        hildon_gtk_icon_view_set_ui_mode    (GtkIconView *iconview,
                                                HildonUIMode mode);

The enum HildonUIMode defines the following flags:

  • HILDON_UI_MODE_NORMAL
  • HILDON_UI_MODE_EDIT

When you use a list or grid in the edit mode inside a window you should use a HildonEditToolbar to control the edition and set the window to fullscreen, building an Edit subview. For more information about edit views, see the Toolbars chapter. In that chapter you can check an example of HildonToolbar, which uses the concepts explained above.

[edit] Seek Bars

The seek bars are a useful way to select a value from a range of predetermined values by adjusting the slider with a finger. These seek bars can be horizontal or vertical and are implemented using GtkVScale and GtkHScale. Thus, you can use this GTK+ widget in your Hildon application as seek bar, but use the following creation function instead of the GTK+ ones:

GtkWidget*  hildon_gtk_hscale_new           (void);
GtkWidget*  hildon_gtk_vscale_new           (void);

Scales created by using these constructors has a hildonized behavior, meaning that when the user taps or clicks a point of the bar, it immediately jumps to the desired position.

[edit] Progress indicators

A convenient way to inform the user that a long-term task is being performed is to show a progress indicator icon in the window or dialog title.

Hildon provides the following function to show a progress icon. This function applies to HildonWindow and GtkDialog.

void        hildon_gtk_window_set_progress_indicator (GtkWindow *window,
                                                      guint state);

The argument state must be 1 to show the indicator and 0 to hide it.

Here, a little example that sets a progress indicator in a GtkDialog.

Example 8.1. Adding a progress indicator to a dialog

#include <hildon/hildon.h>
 
int main( int   argc, char *argv[] )
{
  GtkWidget *dialog;
 
  hildon_gtk_init (&argc, &argv);
 
  dialog = gtk_dialog_new ();
 
  gtk_window_set_title (GTK_WINDOW (dialog),
                        "Performing a long task");
 
  gtk_widget_show  (dialog);
 
  hildon_gtk_window_set_progress_indicator (GTK_WINDOW (dialog),
                                            1);
 
  gtk_dialog_run (GTK_DIALOG (dialog));
 
  return 0;
}

Additionally, if you consider that additional text information should be given to the user, use an informational banner.

Another convenient way to indicate to the user that a long operation is being performed is using the GtkProgressBar widget.