Here's my answers (and sorry for messing up the reply of the last 2 mails, I blame gmail)
I've also attached the sources for the program I used to generate the GTK2/3 answers I posted above. Please look at it if there's any questions remaining after looking at that long table. When I put "5/10" in there, I'm referring to not knowing exactly how a "natural size" algorithm would be implemented that tries to find the ideal width when it's allowed to wrap a text any way it wants. So both values are fine with me. wrap ellipsize width_chars max_width_chars minimum natural false false -1 -1 10 10 true false -1 -1 5 5/10 false true -1 -1 3 5/10 true true -1 -1 3 5/10 false false 4 -1 10 10 true false 4 -1 5 5/10 false true 4 -1 4 5/10 true true 4 -1 4 5/10 false false 8 -1 10 10 true false 8 -1 8 5/10 false true 8 -1 8 5/10 true true 8 -1 8 5/10 false false 12 -1 12 12 true false 12 -1 12 12 false true 12 -1 12 12 true true 12 -1 12 12 false false -1 4 10 10 true false -1 4 5 5/10 false true -1 4 3 5/10 true true -1 4 3 5/10 false false 4 4 10 10 true false 4 4 5 5/10 false true 4 4 4 5/10 true true 4 4 4 5/10 false false 8 4 10 10 true false 8 4 5 5/10 false true 8 4 8 5/10 true true 8 4 8 5/10 false false 12 4 12 12 true false 12 4 12 12 false true 12 4 12 12 true true 12 4 12 12 false false -1 8 10 10 true false -1 8 5 8/10 false true -1 8 3 8/10 true true -1 8 3 8/10 false false 4 8 10 10 true false 4 8 5 8/10 false true 4 8 4 8/10 true true 4 8 4 8/10 false false 8 8 10 10 true false 8 8 5 8/10 false true 8 8 8 8/10 true true 8 8 8 8/10 false false 12 8 12 12 true false 12 8 12 12 false true 12 8 12 12 true true 12 8 12 12 false false -1 12 10 12 true false -1 12 5 12 false true -1 12 3 12 true true -1 12 3 12 false false 4 12 10 12 true false 4 12 5 12 false true 4 12 4 12 true true 4 12 4 12 false false 8 12 10 12 true false 8 12 8 12 false true 8 12 8 12 true true 8 12 8 12 false false 12 12 12 12 true false 12 12 12 12 false true 12 12 12 12 true true 12 12 12 12 The algorithm I tried to use above follows: First, compute the minimum size: 1) Set the minimum size to the width of the text. If wrapped, use the size of the text wrapped as often as possible. 2) If the label is ellipsized, reduce the minimum size to at most 3 characters. 3) If the label has width-chars set, make sure the minimum size fits at least this many characters. Second, compute the natural size: 1) Compute an ideally wrapped text (see disclaimer above: I have no idea what that means exactly.) Take its width. 2) If a max-width-chars is set, reduce the natural size to this many characters. 3) Ensure the natural size is at least as big as the minimum size. This is the algorithm I'll try to implement if nothing better comes up. Benjamin
#include <gtk/gtk.h> static void check_width (GtkWidget *label, gboolean wrap, gboolean ellipsize, gint width_chars, gint max_width_chars) { #if GTK_CHECK_VERSION (3, 0, 0) int min, natural; #else GtkRequisition req; #endif gtk_label_set_line_wrap (GTK_LABEL (label), wrap); gtk_label_set_ellipsize (GTK_LABEL (label), ellipsize); gtk_label_set_width_chars (GTK_LABEL (label), width_chars); gtk_label_set_max_width_chars (GTK_LABEL (label), max_width_chars); #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_get_preferred_width (label, &min, &natural); #else gtk_widget_size_request (label, &req); #endif g_print ("%s %s %2d %2d %2d %2d\n", wrap ? "true " : "false", ellipsize ? "true " : "false", width_chars, max_width_chars, #if GTK_CHECK_VERSION (3, 0, 0) min / 10, natural / 10); #else req.width / 10, req.width / 10); #endif } static void check (GtkWidget *label) { int sizes[] = { -1, 4, 8, 12 }; guint width, max_width; g_print ("properties characters requested\n"); g_print ("wrap ellipsize width_chars max_width_chars minimum natural\n"); for (max_width = 0; max_width < G_N_ELEMENTS (sizes); max_width++) { for (width = 0; width < G_N_ELEMENTS (sizes); width++) { check_width (label, FALSE, FALSE, sizes[width], sizes[max_width]); check_width (label, TRUE, FALSE, sizes[width], sizes[max_width]); check_width (label, FALSE, TRUE, sizes[width], sizes[max_width]); check_width (label, TRUE, TRUE, sizes[width], sizes[max_width]); } } } int main (int argc, char **argv) { GtkWidget *window, *label; PangoFontDescription *font; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); label = gtk_label_new ("12345 1234"); gtk_container_add (GTK_CONTAINER (window), label); font = pango_font_description_from_string ("Monospace 10"); #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_override_font (label, font); #else gtk_widget_modify_font (label, font); #endif pango_font_description_free (font); gtk_widget_realize (window); check (label); return 0; }
_______________________________________________ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list