please find as attachment, a sample with a custom Gtk TextBuffer and a
custom TextTag.

link to the TextTag vala doc: http://valadoc.org/#!api=gtk+-3.0/Gtk.TextTag
here a few documentation of text tags parameters :
http://www.bravegnu.org/gtktext/x113.html

regards.


2014/1/14 Gilzad Hamuni <[email protected]>

> Hi list,
>
> I've compiled and tested this C-tutorial that shows how to have different
> fonts, colors and and sizes in a single text box:
> http://www.gtk.org/tutorial1.2/gtk_tut-14.html
>
> GtkWidget *text;
> ...
> text = gtk_text_new (NULL, NULL);
> ...
> fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*");
> ...
> gtk_text_insert (GTK_TEXT (text), fixed_font, &text->style->black,
> NULL,"Hello\n", -1);
>
>
> Now I'd like to do the same in Vala. I've looked through valadoc and what
> valencia's completion would provide. But I couldn't find the keywords I
> expected in the Gtk namespace. Basically, I need an object that provides
> the gtk_text_insert(...) function, which allows me to add formatted text
> immediately.
>
> VteTerminal, SourceView and TextView seem to be too limited, as they
> doesn't seem to provide such a function. Or am I just to blind to find a
> substitude that is as rich?
>
> My understanding of creating GIR and VAPIs is not sufficient, but I think
> I wouldn't have to do this for gtktext.h, because the whole gtk-library is
> available to vala already?
>
> I'll be happy about any input. Thanks a bunch in advance.
>
> gilzad
> _______________________________________________
> vala-list mailing list
> [email protected]
> https://mail.gnome.org/mailman/listinfo/vala-list
>
using Gtk;

void main(string[] args)
{
	Gtk.init (ref args);
	var buffer = new MyTextBuffer (null);
	var view = new TextView.with_buffer (buffer);
	var win = new Window();
	win.realize.connect (() => {
		TextIter iter;
		buffer.get_start_iter (out iter);
		string txt = "this is a bold & red formatted text";
		buffer.insert_with_tags (iter, txt, txt.length, buffer.bold_red);
	});
	win.add (view);
	win.show_all();
	Gtk.main();
}

class MyTextBuffer : TextBuffer
{
	public MyTextBuffer (TextTagTable? table)
	{
		Object (tag_table: table);
	}
	
	construct {
		bold_red = create_tag ("bold-red", "weight", Pango.Weight.BOLD, "foreground", "#FF0000");
	}
	
	public TextTag bold_red { get; private set; }
}
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to