Re: [gtk-list] Specifying size of Entry and Text widgets
- From: Paul Barton-Davis <pbd op net>
- To: gtk-list redhat com
- Cc: rknop lilys lbl gov
- Subject: Re: [gtk-list] Specifying size of Entry and Text widgets
- Date: Fri, 11 Feb 2000 15:28:22 -0500
>Is there a way to specify the on-screen size of Entry and Text widget, in
>units of character widths (or "nominal" character widths for a
>proportional font) and lines? The "set_usize" function for the Widget
>class appears to operate in pixels, which isn't the most natural unit for
>Entry and Text widgets, and is indeed a bad unit to use if you want a
>modicum of font sensitivity.
its not a stupid question. its also tricky to do right. Below is
one of my utility functions to do this. note that it does not work
correctly if the style for the widget is not set when called. i am
still unsure when the style is "put into effect", but i generally try
to call this from the size_requisition callback, when i figure the
style must be set up (since the sizes would be wrong anyway).
--p
/*
Copyright (C) 1998-99 Paul Barton-Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: gtkutils.c,v 1.1 1999/11/29 18:38:11 pbd Exp $
*/
#include <gtk/gtk.h>
#include <gtkmmext/gtkutils.h>
void
gtk_widget_set_usize_to_display_given_text (GtkWidget *w,
const gchar *text,
gint hpadding,
gint vpadding)
{
guint width;
guint lbearing;
guint rbearing;
guint ascent;
guint descent;
gdk_string_extents (w->style->font,
text,
&lbearing,
&rbearing,
&width,
&ascent,
&descent);
gtk_widget_set_usize (w, width+hpadding, ascent+descent+vpadding);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]