size_request Issues in Major Widgets and One Fix (Patch)
- From: Donald Ryan Willhoit <willhoit andrew cmu edu>
- To: gtk-devel-list redhat com
- Subject: size_request Issues in Major Widgets and One Fix (Patch)
- Date: Tue, 25 Apr 2000 12:29:23 -0400 (EDT)
There seem to be weird things in the gtk_xxx_size_request functions for
several major widgets. I discovered the behaviour after fighting with
Glade to try and get it to look correct. In particular:
GtkSpinButton: Only requests some small size that means that spin buttons
with large digits/max/min look really ugly and the user can't see most
of his entry. (Unless the widget recieves a larger allocation, but that
makes small ones look bad :)
GtkTextEntry: Always chooses some really large size despite having a
maximum length of some small integer. This is primarily misleading! It
also means that some dialogs take up a lot more space than is necessary.
(Take for instance a phone number or social security entry.)
GtkLabel: If a label is put inside some container and set to fill in the
x, expand, etc. etc. and ****word wrap is turned on*** and the window
becomes quite large, the label's size code hits one hard coded and one
magic constant. The hard coded insures that no label is more than about
100 characters which means it will never fill the space allocated to it,
and the other insures that no label is ever larger than half the screen
size.
GtkText: The size size_request picks some hard coded number of rows and
columns. These should be configurable by the user (a programmer using
the library).
In all cases setting the minimum size to some number of pixels is
irresponsible since font sizes could be different and although I know very
little about themes it seems this would be a function of the theme's font.
There may be other issues with other widgets. I intend to fix the ones I
list, but since it can "break" existing user interfaces and although the
fix results in what I consider "normal" behaviour there may be cases where
the old behaviour is desirable, it seems prudent to ask. Also since I
don't have any type of access someone else would need to apply the
patches. I've attached the GtkSpinButton patch.
On a side note I uploaded this and sent mail as per instructions to
ftp.gtk.org/incoming, but it either got lost... if that technique is not
in use some docs should be updated. Anyway if this patch is acceptable
I'll make fixes for the other problems
available soon.
Ryan Willhoit
willhoit@andrew.cmu.edu
--- gtkspinbutton.c.orig Wed Apr 19 09:06:24 2000
+++ gtkspinbutton.c Wed Apr 19 12:03:55 2000
@@ -488,14 +488,43 @@
gtk_spin_button_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
+ GtkSpinButton *spin;
+ gint width;
+ gint count;
+ gfloat temp_width;
+
g_return_if_fail (widget != NULL);
g_return_if_fail (requisition != NULL);
g_return_if_fail (GTK_IS_SPIN_BUTTON (widget));
GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
-
- requisition->width = MIN_SPIN_BUTTON_WIDTH + ARROW_SIZE
+
+ spin = GTK_SPIN_BUTTON (widget);
+
+ count = MAX( abs(spin->adjustment->lower), abs(spin->adjustment->upper) );
+ count = ceil ( log10 (count + 1) );
+
+ if (spin->adjustment->lower < 0)
+ count += 1;
+ if (spin->digits > 0)
+ count += (spin->digits + 1);
+
+ /*
+ Fudge, could produce bad results in some fonts...
+ The correct answer involves finding the width of the widest single character
+ and the width of the . and rewriting the above conditional.
+ */
+ temp_width = gdk_text_width (widget->style->font, "-08", 3) / 3.0;
+ temp_width *= count;
+ width = ceil( temp_width );
+
+ /* Is MIN_SPIN_BUTTON_WIDTH reasonable? Forces single digit spins
+ to have extra whitespace
+ */
+ requisition->width = MAX( MIN_SPIN_BUTTON_WIDTH , width )
+ + ARROW_SIZE
+ 2 * widget->style->klass->xthickness;
+
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]