gtk_label_set_text and gtk_widget_queue_resize



OK, so to answer my own question: set_text causes a size_request event
because the code is written that way :)

But the question is: why ? the code comments:

  /*
   * There are a number of conditions which will necessitate re-filling
   * our text:
   *
   *     1. text changed.
   *     2. justification changed either from to to GTK_JUSTIFY_FILL.
   *     3. font changed.
   *
   * These have been detected elsewhere, and label->words will be zero,
   * if one of the above has occured.
   *
   * Additionally, though, if GTK_JUSTIFY_FILL, we need to re-fill if:
   *
   *     4. gtk_widget_set_usize has changed the requested width.
   *     5. gtk_misc_set_padding has changed xpad.
   *     6.  maybe others?...
   *
   * Too much of a pain to detect all these case, so always re-fill.  I
   * don't think it's really that slow.
   */

I agree with these comments, but not their context: this is in
gtk_label_size_request! It appears to me that this function has been
used to handle all text refilling, when in fact, it should have been
broken out into a separate function, say gtk_label_refill().

The problem with the current architecture is that every change to a
label's text causes a recomputation of its container's size. This is a
silly overhead. No, it doesn't cause serious problems in a
well-designed app, because doing label updates with a frequency faster
than the screen refresh rate (say 70Hz) is silly. However, given that
very few containers will resize themselves because a windowless widget
contained within them "resized" itself after display, it seems to me
that using the size_request event handler as the only place where the
text is redrawn is a suboptimal choice.

the reason i noticed this, BTW, is that I was trying to find a place
that i could use a widget's style->font to set its minimum width. It
appeared to me that the size_request was the first time i could be
sure that the style was setup, and the right place to get my foot in
the door of the sizing process. It is definitely not set after a call
to gtk_widget_set_name(), which is disappointing.

i also found out that the size_request handler got called multiple
time before mapping, and that if set_usize() is called on only the first
call, it appears to have no effect. Instead, I have some totally gross
code to make sure that i call it on the first 5 calls, but never
again. there must be a better way ...

comments ?

--p



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