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




Tim Janik <timj@gimp.org> writes:

> 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?

From my TODO list:

 * Need to be able to make small alterations in the widgets style.
   1) gtk_style_copy
   2) A function to force the style to be set, _without_ realizing
      the widget. (And/or a way of telling widgets that the style has
      been changed so they can change their window's bg color)

So, yes, it is a good idea. Further thoughts:

- I would call it "style_set" though, because it is notification,
  not a command. 

- I don't see much point to having the previous_style argument -
  it may be harmless, but it also IMO useless.

- Are you planning to emit it when the style is initially set
  or only later? I would tend to say that it it only needs to
  be emitted after the widget has been size_requested for the
  first time, though that isn't really flagged now.

- Implementing it fully will require quite a bit of work - since
  almost every widget that isn't NO_WINDOW should in theory have
  a handler. 

- It probably is a good idea to do the style initialization that
  is now done at the time of "realize" before the initial
  "size_request", because a lot of widgets will change their size
  depending on the style.

- There _should_ be a command that says "set the style now", 
  other than gtk_widget_realize(). Maybe we should add another
  widget flag as well...

  So people can do:

    if (!GTK_WIDGET_STYLE_SET (widget))
      gtk_widget_set_default_style (widget); 
    new_style = gtk_style_copy (widget->style);
    new_style->fg_color[GTK_STATE_NORMAL] = my_color;
    gtk_widget_set_style (new_style)

  Adding the flag means that we can solve the problem mentioned
  above - the "style_set" would only be emitted _after_ the
  first time the style is set. Since that would be guaranteed
  to be before the first size_request, everything would work
  out fine. Until we run out of flags...

  Note that people will still get into trouble if they do:

    if (!GTK_STYLE_SET (widget))
      gtk_widget_set_default_style (widget); 
    my_color = widget->style_color;

  Because the style isn't _attached_ yet. For that usage, you
  will still have to realize the widget.

Regards,
                                        Owen



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