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 Oct 31, 2014 4:54 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: vertical and horizontal justification of text in gtktextview
PostPosted: Tue Nov 13, 2007 11:54 am 
Offline

Joined: Tue Nov 13, 2007 10:58 am
Posts: 1
hello all,
I need centered text (horizontal and vertical) in gtktextview, i wrote some code, but I think it's too complicated and it work only with one line of text, (becouse next lines have too much big distance, becouse I use gtk_text_view_set_pixels_above_lines to make text vertical centered).
here is main part of code :

Code:
    GtkTextBuffer *buff=gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));

        GtkTextIter iter;
        gtk_text_buffer_get_start_iter(buff,&iter);
        gtk_text_buffer_insert(buff,&iter,"text",-1);     
        gtk_text_view_set_justification(GTK_TEXT_VIEW(view),GTK_JUSTIFY_CENTER);/*horizontal justification is simple*/
        GdkRectangle visible_rect;
        gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(view),&visible_rect);/*get size of gtk_text_view, we need height*/     
        gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(view),visible_rect.height/2);/*set distance between lines, which provide vertical justification, but only for one line*/


And here is full source code :
Code:
#include <gtk/gtk.h>

static void ondestroy( GtkWidget *widget, gpointer data )
{
        gtk_main_quit();
}

int main( int argc, char *argv[] )
{
        GtkWidget *view;
        GtkWidget *window;

        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(ondestroy), NULL);
        gtk_container_set_border_width(GTK_CONTAINER(window), 16);

        view = gtk_text_view_new();
        gtk_container_add(GTK_CONTAINER(window),view);

        gtk_widget_show(view);
        gtk_widget_show(window);

        GtkTextBuffer *buff=gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));

        GtkTextIter iter;
        gtk_text_buffer_get_start_iter(buff,&iter);
        gtk_text_buffer_insert(buff,&iter,"text",-1);
        gtk_text_view_set_justification(GTK_TEXT_VIEW(view),GTK_JUSTIFY_CENTER);

        GdkRectangle visible_rect;
        gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(view),&visible_rect);
        gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(view),visible_rect.height/2);

        gtk_main();

        return 0;
}


Thanks for any solutions


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 7:05 am 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
Do "gtk_text_buffer_set_text" after "gtk_text_view_set_justification"


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: Yahoo [Bot] and 4 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