[Glade-users] Re: Shrinking entry boxes?
- From: tshead k-3d com (Timothy M. Shead)
- Subject: [Glade-users] Re: Shrinking entry boxes?
- Date: Fri, 29 Sep 2000 13:58:58 -0700
James K. Wiggs wrote:
Good day, Folks;
I'm busy building input GUIs for an application I'm working on,
and I'm using a lot of GtkComboBox widgets for text and numerical
inputs. I've been building the base code using Glade and then
modifying it to use some of my internal functions to create/edit
the contents of the combolists. My question is this: how do I
force these boxes to shrink down to a reasonable size? Even if I
set the parameters in Glade for expand and fill to false, they
end up being anywhere from 2 to 5 times as large as they need to
be for the input values they contain. A combo box with an input
list whose longest value is perhaps 6-7 characters will end up
large enough to hold over 20 characters. Combo boxes that contain
only integer values ranging up to 200 or so will *still* be about
20 characters wide, even though only 3-4 are needed. Is there
some way to manually force these things to only be N characters or
perhaps N pixels wide? Or does GTK+'s internal size allocations
code preclude this, short of using a Layout widget?
James K. Wiggs wrote:
Good day, Folks;
I'm busy building input GUIs for an application I'm working on,
and I'm using a lot of GtkComboBox widgets for text and numerical
inputs. I've been building the base code using Glade and then
modifying it to use some of my internal functions to create/edit
the contents of the combolists. My question is this: how do I
force these boxes to shrink down to a reasonable size? Even if I
set the parameters in Glade for expand and fill to false, they
end up being anywhere from 2 to 5 times as large as they need to
be for the input values they contain. A combo box with an input
list whose longest value is perhaps 6-7 characters will end up
large enough to hold over 20 characters. Combo boxes that contain
only integer values ranging up to 200 or so will *still* be about
20 characters wide, even though only 3-4 are needed. Is there
some way to manually force these things to only be N characters or
perhaps N pixels wide? Or does GTK+'s internal size allocations
code preclude this, short of using a Layout widget?
The C++ SDPGTK (http://www.k-3d.com) library easily does this for any
widget, both through GTKML (XML) templates, and programmatically. The
following code allows you to set fractional character sizes, and is
easily adaptable to "C":
void sdpGtkWidget::SetCharacterSize(gdouble Width, gdouble Height)
{
// Sanity checks ...
g_return_if_fail(Attached());
const static sdpString
metrictext("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_^");
GtkWidget* widget = GTK_WIDGET(m_Object);
gint lbearing = 0;
gint rbearing = 0;
gint width = 0;
gint ascent = 0;
gint descent = 0;
gdk_string_extents(widget->style->font, metrictext, &lbearing,
&rbearing, &width, &ascent, &descent);
gdouble averagewidth = gdouble(lbearing + width + rbearing) /
gdouble(metrictext.size());
gdouble averageheight = gdouble(ascent + descent);
gdouble targetwidth = Width * averagewidth;
gdouble targetheight = Height * averageheight;
gtk_widget_set_usize(widget, gint(targetwidth) +
widget->style->klass->xthickness, gint(targetheight) +
widget->style->klass->ythickness);
}
Regards,
Timothy M. Shead
tshead k-3d com
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]