Re: How do I resize a GtkText Widget based on line length?
- From: Vladislav Grinchenko <vgrinche integ com>
- To: "R. Bernstein" <rocky panix com>, GNOME devel list <gnome-devel-list gnome org>
- Subject: Re: How do I resize a GtkText Widget based on line length?
- Date: Tue, 17 Apr 2001 10:58:27 -0400
On Sun, Mar 25, 2001 at 11:15:24PM -0500, R. Bernstein wrote:
>
> I have command output that I accumulate in a GtkText buffer; afterwards
> I'd like to resize the lines to maybe the maximum line seen up to
> some limit.
>
> The problem is figuring out from a line of text what size it occupies,
> and then resizing the widget. How do I do?
That's what I do to calculate my text window (though mine is staticly sized):
-----------------------------------------------------------------------------
...
static const char lucida[] =
"-b&h-lucidatypewriter-medium-r-normal-sans-18-180-75-75-m-110-iso8859-1";
static const char fixed[] = "-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*";
static const char* font_names[] = { lucida, fixed };
/*--- Load a fixed font ---*/
m_fixed_font = gdk_font_load (font_names[0]);
/*--- Fall back to the standard font ---*/
if (m_fixed_font == NULL) {
m_fixed_font = gdk_font_load (font_names[1]);
}
/*---
Brain-damaged way of calculating necessary
window size (70x14) in pixels.
---*/
string s (72, 'O');
int t_width = gdk_string_width (m_fixed_font, s.c_str ());
int t_height = (m_fixed_font->ascent + m_fixed_font->descent) * 14;
/*--- Create text and set messages window size ---*/
m_widget = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT (m_widget), FALSE);
gtk_text_set_word_wrap (GTK_TEXT (m_widget), FALSE);
gtk_widget_set_usize (m_widget, t_width, t_height);
and so on ...
-----------------------------------------------------------------------------
If text line doesn't fit on the screen, you can either tell Text widget
to wrap the text or leave it unwrapped. However, the catch is if you
choose unwrapped mode, you cannot attach horizontal scroll bar to
do scrolling! I've heard it might be changed in upcoming GTK+ release.
You might also consider replacing Text widget with CList. That suppose to
give you better control of what is visible and what is not.
>
> In order to make the task precise, see gnopstree from
> http://gnopstree.sourceforge.net or download via
> http://sourceforge.net/project/showfiles.php?group_id=21133 build, and
> click on a process and look at the popup window in that.
>
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-devel-list
--
_________________________________________________________
Vladislav Grinchenko e-mail: vgrinche integ com
Integral Systems, Inc. http: www.integ.com
_________________________________________________________
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]