Skip to content

Instantly share code, notes, and snippets.

@rain-1 rain-1/mytv.vala
Created Apr 7, 2019

Embed
What would you like to do?
bold text in vala
using Gtk;
// valac --pkg gtk+-3.0 mytv.vala
public class MarkupTextView : TextView {
public void append_text (string s) {
TextIter end_iter;
buffer.get_end_iter (out end_iter);
buffer.insert_with_tags_by_name (ref end_iter, s, -1, null);
}
public void append_tagged_text (string s, string t) {
TextIter end_iter;
buffer.get_end_iter (out end_iter);
buffer.insert_with_tags_by_name (ref end_iter, s, -1, t, null);
}
}
public static int main (string[] args) {
Gtk.init (ref args);
var window = new Window ();
window.set_default_size (400, 600);
var text_view = new MarkupTextView ();
text_view.editable = false;
//this.text_view.cursor_visible = false;
var mybold_tag = new TextTag ("mybold");
mybold_tag.weight = Pango.Weight.BOLD; //https://valadoc.org/pango/Pango.Weight.html
text_view.buffer.tag_table.add(mybold_tag);
// text_view.buffer.create_tag ("bold", mybold_tag, null);
text_view.append_text("hello\nworld!\nand ");
text_view.append_tagged_text("**bye**", "mybold");
text_view.append_text("; btw\n!");
var scroll = new ScrolledWindow (null, null);
scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
scroll.add (text_view);
window.add (scroll);
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.