Gtk# TextView and Scrolling Text

View: New views
6 Messages — Rating Filter:   Alert me  

Gtk# TextView and Scrolling Text

by Emfor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,
I'm fighting with TextView widget. Everything is fine except that when I load text to it and move cursor in it - the coursor can go out of view (TextView doesn't scroll). I tried many examples with using TextIter and TextMark and ScrollToMark function, bu it simply doesn't work.
Can anyone please tell me what am I doing wrong?

--
Best regards,
Emfor

Re: Gtk# TextView and Scrolling Text

by countcb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Emfor wrote:
Hi there,
I'm fighting with TextView widget. Everything is fine except that when I load text to it and move cursor in it - the coursor can go out of view (TextView doesn't scroll). I tried many examples with using TextIter and TextMark and ScrollToMark function, bu it simply doesn't work.
Can anyone please tell me what am I doing wrong?

--
Best regards,
Emfor

Hi.
You have to add your TextView to a ScrolledWindow widget and then add this ScrolledWindow to the window/dialog you want the TextView to be displayed in.

Below is a small test program which demostrates a srolling TextView.
Christopher.

------

using Gtk;
using Gdk;

namespace GtkTest
{
        class Program
        {
                public static void Main (string[] args)
                {
                        Application.Init ();
                        Gtk.Window win = new TestWindow();
                        win.ShowAll();
                        Application.Run ();
                }
        }
}

namespace GtkTest
{
        class TestWindow : Gtk.Window
        {
                public TestWindow() : base(Gtk.WindowType.Toplevel)
                {
                        this.DeleteEvent += this.OnDeleteEvent;
                        this.SetSizeRequest(800, 600);

                        ScrolledWindow scrolledWindow = new ScrolledWindow();
                        TextView yourTextView = new TextView();
                       
                        scrolledWindow.Add(yourTextView);
                        this.Add(scrolledWindow);
                }
               
                private void OnDeleteEvent(object sender, DeleteEventArgs a)
                {
                        System.Console.WriteLine("onDelete");
                        Application.Quit();
                        a.RetVal = true;
                }
                       
        }
}

Re: Gtk# TextView and Scrolling Text

by Emfor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


countcb wrote:
Hi.
You have to add your TextView to a ScrolledWindow widget and then add this ScrolledWindow to the window/dialog you want the TextView to be displayed in.
Hi,
I did that. When I load text, the scroll bar is shown, but when I move cursor around the text and it goes away the visible part of the TextView, it doesn't scroll to show the cursor. I experiment here with OnCursorMove event and Iter/Mark, but none of the solutions I've found (mostly for C/C++) doesn't work with Gtk#.

--
Best regards,
Mateusz

Re: Gtk# TextView and Scrolling Text

by countcb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Emfor wrote:
Hi,
I did that. When I load text, the scroll bar is shown, but when I move cursor around the text and it goes away the visible part of the TextView, it doesn't scroll to show the cursor. I experiment here with OnCursorMove event and Iter/Mark, but none of the solutions I've found (mostly for C/C++) doesn't work with Gtk#.
Does this also happen with my code snippet? When you add text to it?
Adding the TextView to a ScrolledWindow should be everything you need to do.

What version of mono and gtk# are you using?

I think i can't say more, wihout seeing some code.

Re: Gtk# TextView and Scrolling Text

by Nelis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Emfor wrote:
Hi there,
I'm fighting with TextView widget. Everything is fine except that when I load text to it and move cursor in it - the coursor can go out of view (TextView doesn't scroll). I tried many examples with using TextIter and TextMark and ScrollToMark function, bu it simply doesn't work.
Can anyone please tell me what am I doing wrong?

--
Best regards,
Emfor
Hi,

Searched for the same, found a solution:

TextIter ti = textview1.Buffer.GetIterAtLine(textview1.Buffer.LineCount-1);
TextMark tm = textview1.Buffer.CreateMark("eot", ti,false);
textview1.ScrollToMark(tm, 0, false, 0, 0);

Nelis

Re: Gtk# TextView and Scrolling Text

by Jiří Zárevúcky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Emfor wrote:
Hi,
I did that. When I load text, the scroll bar is shown, but when I move cursor around the text and it goes away the visible part of the TextView, it doesn't scroll to show the cursor. I experiment here with OnCursorMove event and Iter/Mark, but none of the solutions I've found (mostly for C/C++) doesn't work with Gtk#.
You have probably used the AddWithViewport method. TextView has it's own viewport, which is handling the scrolling. You need to use the Add method.