From 487fe8784cee913b177dffcee83fe6df5c9b2ca6 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 19 Mar 2013 14:09:28 -0700 Subject: Make slider labels consistent in print dialog To make this easier I created a new helper function create_label that takes printf style arguments. I assumed this would be usable in many places but ended up finding just one other obvious use for it. Signed-off-by: Dirk Hohndel --- display-gtk.h | 2 ++ gtk-gui.c | 4 +--- print.c | 27 +++++++++++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/display-gtk.h b/display-gtk.h index 498fceda5..5a8bd29eb 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -73,6 +73,8 @@ extern const char *get_active_text(GtkComboBox *); extern void set_active_text(GtkComboBox *, const char *); extern GtkWidget *combo_box_with_model_and_entry(GtkListStore *); +extern GtkWidget *create_label(const char *fmt, ...); + extern gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data); unsigned int amount_selected; diff --git a/gtk-gui.c b/gtk-gui.c index 33777ed93..c5b9a8071 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -1981,11 +1981,9 @@ int confirm_dialog(int when, char *action_text, char *event_text) { GtkWidget *dialog, *vbox, *label; int confirmed; - char buffer[256]; char title[80]; snprintf(title, sizeof(title), "%s %s", action_text, event_text); - snprintf(buffer, sizeof(buffer), _("%s event at %d:%02u"), title, FRACTION(when, 60)); dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -1994,7 +1992,7 @@ int confirm_dialog(int when, char *action_text, char *event_text) NULL); vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - label = gtk_label_new(buffer); + label = create_label(_("%s event at %d:%02u"), title, FRACTION(when, 60)); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show_all(dialog); confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT; diff --git a/print.c b/print.c index e5028e94b..deeec0e9b 100644 --- a/print.c +++ b/print.c @@ -907,14 +907,26 @@ OPTIONSELECTEDCALLBACK(color_selection_toggle, print_options.color_selected) #define SCALECALLBACK(name, scale1, scale2)\ static void name(GtkWidget *hscale, gpointer *data)\ { \ - print_options.scale1 = gtk_range_get_value(GTK_RANGE(hscale)); \ - print_options.notes_height = 93 - print_options.scale1 - print_options.scale2;\ - gtk_range_set_value (GTK_RANGE(data), print_options.notes_height);\ + print_options.scale1 = gtk_range_get_value(GTK_RANGE(hscale)); \ + print_options.notes_height = 93 - print_options.scale1 - print_options.scale2; \ + gtk_range_set_value (GTK_RANGE(data), print_options.notes_height); \ } SCALECALLBACK (prof_hscale, profile_height, tanks_height) SCALECALLBACK (tanks_hscale, tanks_height, profile_height) + +GtkWidget *create_label(const char *fmt, ...) +{ + char buf[256]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + return gtk_label_new(buf); +} + static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data) { GtkWidget *vbox, *radio1, *radio2, *radio3, *radio4, *radio5, @@ -1004,9 +1016,9 @@ static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data) box4 = gtk_vbox_new (FALSE, 5); gtk_box_pack_start(GTK_BOX(box2), box4, TRUE, TRUE, 5); - label1 = gtk_label_new(_("Profile height (37% - 77%)")); - label2 = gtk_label_new(_("Other data height (7% - 16%)")); - label3 = gtk_label_new(_("Notes height (7% - 77%)")); + label1 = create_label(_("Profile height (%d%% - %d%%)"), profile_height_min, profile_height_max); + label2 = create_label(_("Other data height (%d%% - %d%%)"), tanks_height_min, tanks_height_max); + label3 = create_label(_("Notes height (%d%% - %d%%)"), notes_height_min, notes_height_max); gtk_box_pack_start (GTK_BOX(box3), label1, TRUE, TRUE, 10); gtk_box_pack_start (GTK_BOX(box3), label2, TRUE, TRUE, 10); gtk_box_pack_start (GTK_BOX(box3), label3, TRUE, TRUE, 10); @@ -1020,6 +1032,9 @@ static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data) gtk_range_set_value (GTK_RANGE(scale_tanks_hscale), print_options.tanks_height); gtk_range_set_increments (GTK_RANGE(scale_tanks_hscale),1,1); gtk_scale_set_value_pos (GTK_SCALE(scale_tanks_hscale), GTK_POS_LEFT); + + /* this third scale just shows how much is left for the notes; + * it can't be directly changed by the user */ scale_notes_hscale = gtk_hscale_new_with_range (notes_height_min, notes_height_max, 1); gtk_range_set_value (GTK_RANGE(scale_notes_hscale), print_options.notes_height); gtk_range_set_increments (GTK_RANGE(scale_notes_hscale),1,1); -- cgit v1.2.3-70-g09d2