Re: Text-View width
- From: Havoc Pennington <hp redhat com>
- To: albie alfarrabio di uminho pt
- Cc: gtk-list gnome org
- Subject: Re: Text-View width
- Date: 11 Jan 2002 13:58:16 -0500
Alberto Manuel Brandao Simoes <albie alfarrabio di uminho pt> writes:
>
> How can I find the width in chars for a text-view widget? Of course, this
> is only interesting for a monosized typeface!
>
Something like this:
PangoFontMetrics *metrics;
GtkWidget *widget;
int char_width;
int width_in_chars;
widget = GTK_WIDGET (text_view);
context = gtk_widget_get_pango_context (widget);
metrics = pango_context_get_metrics (context,
widget->style->font_desc,
pango_context_get_language (context));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
width_in_chars = widget->allocation.width / char_width;
This assumes you have set the monospace font for the text view with
gtk_widget_modify_font(), resulting in a monospace font for
widget->style->font_desc; if not you need to use the font desc of
interest, not widget->style->font_desc.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]