GtkWidget::set_style proposal (was: [bug, v0.99.3] frame->label_width)



On Thu, 19 Feb 1998 Kevin Turner wrote:

> (apologies if this message was re-sent, just subscribed to the list and
> wasn't sure if it went through...)

hm, seems i'm unsubscribed and can't manage to get subscribed
again (maybe this list is private and only meant for people who are more
familiar with gtk than me? ;)
so please Cc: for replies (at the moment).

> Playing with changing the font size in (gimp's) gtkrc, I noticed frame
> labels no longer fit in the space provided for them...  The blank space
> in the frame was always that of the default font size
> ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*").  The full text
> would still display, but it would run over on top of the frame line...
> Smaller fonts simply don't take up the whole space.
> http://www.aracnet.com/~kevint/gimp/gtkbug.png illustrates.  I checked
> gtkframe.c and found
> 
> frame->label_width = gdk_string_measure (GTK_WIDGET (frame)->style->font, 
>                                          frame->label) + 7;

the label size measuring will be done before the frame is added to a
parent. therefore style->font is taken from the default style, which
uses the default font that has another size than the one you used.

> To see what was up, I added this line to my program after it created
> the frame:
> 
>   g_print("label_width: %d, %d\n",
>           GTK_FRAME(msg_frame)->label_width,
>           gdk_string_measure (GTK_WIDGET(msg_frame)->style->font,
>                               GTK_FRAME(msg_frame)->label) + 7);
> 
> When the font size in gtkrc was default, it gave: 
> label_width: 66, 66
> 
> But changing gtkrc and restarting with point size of 100 instead of 120: 
> label_width: 66, 55
> 
> Point size 180: label_width: 66, 93

unaware of the style change (introduced by gtkrc parsing), the frame still
operates with the old precomputed value that is incorrect for your new font.

> Unaware of gtk internals, I became rather mystified at this point and
> decided to turn it over to you.

now, there would be an easy solution, that is to move the size computation
of the frames label out of gtk_frame_set_label into gtk_frame_paint.
but this will introduce a performance impact on every expose event (of which
there are quite a lot coming from the x server during normal program
operation), and it would only be a fix around the real problem, that is:
widgets don't get informed when their style changes.

so i'm herewith proposing the need of yet another widget signal,
run_type==GTK_RUN_FIRST as follows:

void	(*GtkWidget::set_style)	(GtkWidget *widget,
				 GtkStyle  *previous_style);

the new style will be already set if this signal is emitted.

objections?
				 

> 
> Have fun,
>  - Kevin Turner
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]