Blame platform-demos/gl/textview.vala.page

Packit 1470ea
Packit 1470ea
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="textview.vala" xml:lang="gl">
Packit 1470ea
  <info>
Packit 1470ea
  <title type="text">TextView (Vala)</title>
Packit 1470ea
    <link type="guide" xref="beginner.vala#multiline"/>
Packit 1470ea
    <revision version="0.1" date="2012-06-07" status="draft"/>
Packit 1470ea
Packit 1470ea
    <credit type="author copyright">
Packit 1470ea
      <name>Tiffany Antopolski</name>
Packit 1470ea
      <email its:translate="no">tiffany.antopolski@gmail.com</email>
Packit 1470ea
      <years>2012</years>
Packit 1470ea
    </credit>
Packit 1470ea
Packit 1470ea
    <desc>Widget que mostra un GtkTextBuffer</desc>
Packit 1470ea
  
Packit 1470ea
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
Packit 1470ea
      <mal:name>Fran Dieguez</mal:name>
Packit 1470ea
      <mal:email>frandieguez@gnome.org</mal:email>
Packit 1470ea
      <mal:years>2012-2013.</mal:years>
Packit 1470ea
    </mal:credit>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
  <title>Widget TextView</title>
Packit 1470ea
     <note style="sidebar">

If we press "enter", we have a new line.

Packit 1470ea
     

If we press "enter" more times then there are lines in the default sized window, then a vertical scrollbar appears.

Packit 1470ea
     

If we write a long sentence, the text will wrap breaking lines between words.

Packit 1470ea
     

If we have a loooooooooooooooooooooooooooooooooooong word, a horizontal scrollbar will appear.

</note>
Packit 1470ea
Packit 1470ea
    <media type="image" mime="image/png" src="media/textview.png"/>
Packit 1470ea
    

This is an example of Gtk.TextView

Packit 1470ea
Packit 1470ea
/* This is the application. */
Packit 1470ea
public class MyApplication : Gtk.Application {
Packit 1470ea
	/* Override the 'activate' signal of GLib.Application. */
Packit 1470ea
	protected override void activate () {
Packit 1470ea
		/* Create the window of this application. */
Packit 1470ea
		new MyWindow (this).show_all ();
Packit 1470ea
	}
Packit 1470ea
}
Packit 1470ea
Packit 1470ea
/* This is the window. */
Packit 1470ea
class MyWindow: Gtk.ApplicationWindow {
Packit 1470ea
	internal MyWindow (MyApplication app) {
Packit 1470ea
		Object (application: app, title: "TextView Example");
Packit 1470ea
		this.set_default_size (220, 200);
Packit 1470ea
Packit 1470ea
		var buffer = new Gtk.TextBuffer (null); //stores text to be displayed
Packit 1470ea
		var textview = new Gtk.TextView.with_buffer (buffer); //displays TextBuffer
Packit 1470ea
		textview.set_wrap_mode (Gtk.WrapMode.WORD); //sets line wrapping
Packit 1470ea
Packit 1470ea
		var scrolled_window = new Gtk.ScrolledWindow (null, null);
Packit 1470ea
		scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC,
Packit 1470ea
		                            Gtk.PolicyType.AUTOMATIC);
Packit 1470ea
Packit 1470ea
		scrolled_window.add (textview);
Packit 1470ea
		scrolled_window.set_border_width (5);
Packit 1470ea
Packit 1470ea
		this.add (scrolled_window);
Packit 1470ea
	}
Packit 1470ea
}
Packit 1470ea
/* main creates and runs the application. */
Packit 1470ea
public int main (string[] args) {
Packit 1470ea
	return new MyApplication ().run (args);
Packit 1470ea
}
Packit 1470ea
Packit 1470ea

Neste exemplo empregaremos o seguinte:

Packit 1470ea
<list>
Packit 1470ea
  <item>

<link href="http://www.valadoc.org/gtk+-3.0/Gtk.TextBuffer.html">Gtk.TextBuffer</link>

</item>
Packit 1470ea
  <item>

<link href="http://www.valadoc.org/gtk+-3.0/Gtk.TextView.html">Gtk.TextView</link>

</item>
Packit 1470ea
  <item>

<link href="http://www.valadoc.org/gtk+-3.0/Gtk.ScrolledWindow.html">Gtk.ScrolledWindow</link>

</item>
Packit 1470ea
  <item>

<link href="http://www.valadoc.org/gtk+-3.0/Gtk.WrapMode.html">Gtk.WrapMode</link>

</item>
Packit 1470ea
  <item>

<link href="http://www.valadoc.org/gtk+-3.0/Gtk.PolicyType.html">Gtk.PolicyType</link>

</item>
Packit 1470ea
</list>
Packit 1470ea
</page>