Number Widgets

Number Widgets — How to migrate Number Widgets

Migrating Number Widgets

To achieve the same functionlity of HildonNumberEditor you can use a HildonPickerButton with a HildonTouchSelectorEntry assigned to it. With these widgets you can also easily have the functionality of a HildonRangeEditor (not covered in this example). Both the HildonNumberEditor and the HildonRangeEditor are deprecated since Hildon 2.2.

The following example shows a typical NumberEditor.

Example 42. A Typical Number Editor


GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ());
GtkWidget *editor = hildon_number_editor_new (0, 30);
GtkWidget *label = gtk_label_new ("Number:");
GtkWidget *hbox = gtk_hbox_new (FALSE, 12);

gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), editor, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (dialog->vbox), hbox, TRUE, TRUE, 0);

gtk_widget_show_all (GTK_WIDGET (dialog));
gtk_dialog_run (dialog);

        

The functionality of the example above is shown on the example bellow using by validating the HildonPickerButton's value every time it's changed. The choices given in the HildonTouchSelectorShould be the most common choices.

Example 43. A Replacement for the Number Editor


void
changed_value_cb (HildonPickerButton *picker, gpointer data)
{
    gdouble number = 0;
    const gchar *choice = hildon_button_get_value(HILDON_BUTTON (picker));
    number = CLAMP(g_ascii_strtod (choice, NULL), 0, 30);
    hildon_button_set_value(HILDON_BUTTON (picker), g_strdup_printf ("%d", (int) number));
}

GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ());
GtkWidget *picker = hildon_picker_button_new (HILDON_SIZE_THUMB_HEIGHT,
                                HILDON_BUTTON_ARRANGEMENT_VERTICAL);
hildon_button_set_title (HILDON_BUTTON (picker), "Number:");
HildonTouchSelector *selector = HILDON_TOUCH_SELECTOR (
                                hildon_touch_selector_entry_new_text ());
hildon_touch_selector_append_text (selector, "0");
hildon_touch_selector_append_text (selector, "5");
hildon_touch_selector_append_text (selector, "10");
hildon_touch_selector_append_text (selector, "15");
hildon_touch_selector_append_text (selector, "20");
hildon_touch_selector_append_text (selector, "25");
hildon_touch_selector_append_text (selector, "30");
hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (picker), selector);
hildon_picker_button_set_active (HILDON_PICKER_BUTTON (picker), 0);
g_signal_connect (G_OBJECT (picker), "value-changed",
                                G_CALLBACK (changed_value_cb), NULL);
gtk_box_pack_start (GTK_BOX (dialog->vbox), picker, TRUE, TRUE, 0);
gtk_widget_show_all (GTK_WIDGET (dialog));
gtk_dialog_run (dialog);