GTK gossip: gtkspinbutton

Source: Internet
Author: User
Tags gtk

Gtkspinbutton is a component that allows the user to adjust the value. It has an up or down arrow and is pressed, you can set the upper and lower limits of the input values, the number of small numbers, and the value of increment by pressing the arrow, however, the actually token of the gtkspinbutton is derived from the gtkentry:

Gtkwidget


+ ---- Gtkentry


+ ---- Gtkspinbutton


You can use the gtk_spin_button_new () function to add a gtkspinbutton:

Gtkwidget * gtk_spin_button_new (

Gtkadjustment * adjustment, gdouble climb_rate, guint digits );


Climb_rate is the acceleration of changes in the numeric value when the value is set to press the hour, for a 0.0 to 1.0 setting, digits is a small number that sets the metric value. This function also requires a gtkadjustment, this object is used to control the threshold, upper and lower limit, and increment value of a number:

Gtkobject * gtk_adjustment_new (gdouble value, // Initial Value


Gdouble lower, // lower bound value



Gdouble upper, // upper bound value



Gdouble step_increment, // increment Value



Gdouble page_increment, // does not define the gtkspinbutton identifier



Gdouble page_size );

// Does not define the gtkspinbutton callback

Gtkadjustment can also be used in other Widgets. page_increment is the number of terminal increments when Pagedown and Pageup are pressed,
Page_size is the size that the component can display, but for gtkspinbutton, the parameter step_increment is intentionally defined.

You can also use
Gtk_spin_button_new_with_range (). You can directly specify the minimum value, maximum value, and increment value. This function automatically produces gtkadjustment:

Gtkwidget * gtk_spin_button_new_with_range (gdouble min,



Gdouble Max,



Gdouble step );

In
Gtkhbox
And gtkvbox



You have used gtkspinbutton.

The gtk_spin_button_new_with_range () function is used to create a gtkspinbutton. In this example, modify the example of the parameter to create a gtkadjustment and use it.
Create a gtk_spin_button_new () function:

  • Gtk_spin_button_demo.c
#include <gtk/gtk.h>

void value_changed_callback(GtkSpinButton *spinButton, gpointer data) {
gdouble value = gtk_spin_button_get_value(spinButton);
GString *text = g_string_new("");
g_string_sprintf(text, "%.2f", value);
gtk_label_set_text(GTK_LABEL(data), text->str);
}

int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *spinButton;
GtkObject *adjustment;
GtkWidget *label;
GtkWidget *hbox;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkSpinButton");
gtk_window_set_default_size(GTK_WINDOW(window), 250, 50);

adjustment = gtk_adjustment_new(0.0, 0.0, 100.0, 0.05, 0.0, 0.0);
spinButton = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 0.01, 2);
label = gtk_label_new("0.00");
hbox = gtk_hbox_new(TRUE, 5);

gtk_box_pack_start(GTK_BOX(hbox), spinButton, TRUE, TRUE, 5);
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 5);
gtk_container_add(GTK_CONTAINER(window), hbox);

g_signal_connect(GTK_OBJECT(spinButton), "value_changed",
G_CALLBACK(value_changed_callback), label);
g_signal_connect(GTK_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);

gtk_main();

return 0;
}


The results of a line are as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.