GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

vertical and horizontal justification of text in gtktextview

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
sebo



Joined: 13 Nov 2007
Posts: 1

PostPosted: Tue Nov 13, 2007 11:54 am    Post subject: vertical and horizontal justification of text in gtktextview Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11

    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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#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
Back to top
caracal
GTK+ Geek


Joined: 21 Jun 2007
Posts: 75
Location: Wilkes Barre Pa

PostPosted: Mon Jan 07, 2008 7:05 am    Post subject: Reply with quote

Do "gtk_text_buffer_set_text" after "gtk_text_view_set_justification"
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP