Exemple #1
0
func CreateText(buffer **gtk3.TextBuffer, isSource bool) gtk3.WidgetLike {
	scrolledW := gtk3.NewScrolledWindow(nil, nil)
	scrolledW.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)
	scrolledW.SetShadowType(gtk3.GtkShadow.IN)

	*buffer = gtk3.NewTextBuffer(nil)
	textView := gtk3.NewTextView()
	textView.SetBuffer(*buffer)
	textView.SetEditable(false)
	textView.SetCursorVisible(false)

	scrolledW.Add(textView)

	if isSource {
		fontDesc := pango.NewFontDescriptionFromString("monospace")
		textView.OverrideFont(fontDesc)
		textView.SetWrapMode(gtk3.GtkWrapMode.NONE)
	} else {
		// Make it a bit nicer for text
		textView.SetWrapMode(gtk3.GtkWrapMode.WORD)
		textView.SetPixelsAboveLines(2)
		textView.SetPixelsBelowLines(2)
	}

	return scrolledW
}
Exemple #2
0
func DoTextView(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetDefaultSize(450, 450)
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetTitle("TextView")
		window.SetBorderWidth(0)

		vpaned := gtk3.NewVPaned()
		vpaned.SetBorderWidth(5)
		window.Add(vpaned)

		view1 := gtk3.NewTextView()
		buffer := view1.GetBuffer()
		view2 := gtk3.NewTextViewWithBuffer(buffer)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)

		vpaned.Add1(sw)
		sw.Add(view1)

		sw = gtk3.NewScrolledWindow(nil, nil)
		sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)

		vpaned.Add2(sw)
		sw.Add(view2)

		createTags(buffer)
		insertText(buffer)

		attachWidgets(view1)
		attachWidgets(view2)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}
	return window
}