GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 9:40 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Fit window size to text size?
PostPosted: Thu Sep 06, 2012 1:02 pm 
Offline
Familiar Face

Joined: Thu Sep 06, 2012 8:45 am
Posts: 6
I want a window size to be just the right size to show the text in a text_view, unless the text size is greater then some limit size.
The window is built like this using C code.
Code:
     
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      scrolled_window=gtk_scrolled_window_new(NULL,NULL);
      gtk_window_set_title(GTK_WINDOW(window), notification_file_name());
     
      gtk_container_add(GTK_CONTAINER (window), scrolled_window);

      text_view = text_view_new_from_file(notification_file_path());
      gtk_container_add(GTK_CONTAINER (scrolled_window), text_view);

Is there a way to do that?
Or can I get the size of the text_view in pixels?


Top
 Profile  
 
 Post subject: Re: Fit window size to text size?
PostPosted: Fri Sep 07, 2012 1:14 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
You may have problems in doing this. The TextView has default settings that can be obtained using gtk_text_view_get_default_attributes (), but at any point these can be overridden by tags in which case locally you can use gtk_text_iter_get_attributes () to find the attributes. In each case the GtkTextAttributes struct has a PangoFontDescription member from which the text size can then be determined. Pango has some good methods for determining text size from that point.
Personally I'm not a fan of setting window sizes. Bad things can happen for small screen devices if its not properly designed and tested.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group