Gtkprogressbar
You can use gtk_progress_bar_new () to create
Gtkprogressbar. To set the progress ratio, you can use the gtk_progress_bar_set_fraction () function. The value can be set to 0.0
1.0. You can use
Gtk_progress_bar_get_fraction.
You can use gtk_progress_bar_set_text () to set the text display.
Gtk_progress_bar_get_text (). You can also use
Gtk_progress_bar_set_orientation (): sets the moving direction of the import level column. The following values can be set:
- Gtk_progress_left_to_right: left-to-right (reset)
- Gtk_progress_right_to_left: Right to left
- Gtk_progress_bottom_to_top: from bottom to top
- Gtk_progress_top_to_bottom: from top to bottom
The following program uses gtk_timeout_add ()
Set a timer for the increase in the degree of Modulo progress:
#include <gtk/gtk.h>
gboolean timeout_callback(gpointer data) {
gdouble value;
GString *text;
value = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(data));
value += 0.01;
if(value > 1.0) {
value = 0.0;
}
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(data), value);
text = g_string_new(
gtk_progress_bar_get_text(GTK_PROGRESS_BAR(data)));
g_string_sprintf(text, "%d %%", (int) (value * 100));
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(data), text->str);
return TRUE;
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *progressBar;
gint timer;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkProgressBar");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 30);
progressBar = gtk_progress_bar_new();
timer = gtk_timeout_add(100, timeout_callback, progressBar);
gtk_container_add(GTK_CONTAINER(window), progressBar);
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 the rows are as follows: