Page 1 of 1

TextView.Text changed - scroll to bottom?

Posted: Sun Jul 10, 2016 3:57 pm
by midwan
I'm wondering if this is the default behavior or I'm missing something...

I have an application using RapaGUI. It utilizes the Textview class to show a simple log, which has its contents updated whenever something important happens.
The text is updated normally, but the Textview does not scroll to the end when it happens. So if you keep adding text to it, you don't see it unless you manually scroll down...

Here's an extract of the XML definition for the TextView:

Code: Select all

<hgroup><label>Server Log:</label><rectangle/></hgroup>
<textview id="textviewLog">Server Log started</textview>
And here's the piece of code which writes new content to the TextView:

Code: Select all

Function p_WriteToLog(message)
	Local currentLog = moai.Get("textviewLog", "Text")
	currentLog = currentLog .. "\r\n" .. message
	moai.Set("textviewLog", "Text", currentLog)
Am I missing something here? Shouldn't it automatically scroll to the end when new text is added?

Re: TextView.Text changed - scroll to bottom?

Posted: Sun Jul 10, 2016 4:58 pm
by airsoftsoftwair
No, it doesn't automatically scroll to the bottom and I don't think that such a behaviour would be natural because it isn't always desirable. I'd have to implement a new method which allows you to scroll the TextView to make something like this possible.

However, why don't you use a Listview or Listbox for your log window? This seems more appropriate for the job. Take a look at the "Demo" example that comes with RapaGUI. It also contains a log widget which is based on a Listview widget.

Re: TextView.Text changed - scroll to bottom?

Posted: Sun Jul 10, 2016 9:25 pm
by midwan
Thanks, I will use the Listview for the Log as per you example.

However, I still think this behavior is a bit weird. If for example one would like to use the TextView as a place to paste in (possibly formatted/styled) text, wouldn't they expect that after doing so they'd end up at the last character entered?

Let's say I'm using it for an IRC client's chat window, where incoming messages are always appended... Wouldn't you expect that it always scrolls to show the last text entered? I would expect that to be the default behavior at least.

Which scenarios would make this undesirable as you say?

Re: TextView.Text changed - scroll to bottom?

Posted: Thu Jul 14, 2016 6:07 pm
by airsoftsoftwair
Well, generally speaking, TextView class is not really efficient for constantly appending new information because it doesn't have any method for just appending text. There's only a method to update the *complete* contents of the widget and this is of course highly inefficient when dealing with larger amounts of information in the widget... that's why ListView is a much better choice here.

That being said, I agree that there are cases when scrolling to the bottom is desirable but there are also cases where it isn't desirable so the best idea is probably to implement a new scroll method which can be used if needed.

Re: TextView.Text changed - scroll to bottom?

Posted: Thu Jul 14, 2016 6:12 pm
by midwan
Unless we can have another implementation which is more efficient in appending text of course (in the future). :)

Or is there another way you can think of to implement such a functionality? I'm currently getting the existing Text, appending the new text to it and then re-setting the Text property with the new value - as you said, not very efficient.

Would you use another control type for this? I'm looking for something that can be used in say, messenger windows, where the chat log is shown and you can type in new text (or receive from the other peer) with the control scrolling at the bottom when that happens.

Re: TextView.Text changed - scroll to bottom?

Posted: Sat Jul 16, 2016 1:10 pm
by airsoftsoftwair
The problem is actually in MUI. On MUI, TextView is mapped to Floattext.mui which doesn't support appending or insertion of text. Floattext only supports setting the whole text of the widget. That's why RapaGUI doesn't support anything else here either. If Floattext.mui supported text appending, then I could support it as well but currently it doesn't.