-
Apr 14 2012 11:59 AM #1
ScrollableControl's scrollbar behaviour
Is there a way to make the bound ScrollBar on a ScrollableControl (a ListBox in my plugin) behave like the scrollbar of the LoTRO chat window?
In the LoTRO chat window, when lines are added, if the scrollbar is at the bottom, the scrollbar adjusts to the new bottom and the lines are visible. In a ListBox, if new items are added, the scrollbar never adjusts, and new items will not be visible unless you use your mouse to scroll down.
The ListBox's scrollbar can't be adjusted with GetMaximum and SetValue, since it's bound. (Unless there's a way of making these calls through the ListBox object, but I haven't found any documentation or examples suggesting how to do that.)
As a workaround, I tried SetReverseFill() and InsertItem(1, item), but ReverseFill has nasty layout bugs.
-
Apr 14 2012 06:47 PM #2
Re: ScrollableControl's scrollbar behaviour
-
Apr 14 2012 09:51 PM #3
Re: ScrollableControl's scrollbar behaviour
There is a way to do it with a bound scrollbar but it has some limitations. First, the mechanism uses an undocumented aspect of the listbox items' properties (since it's undocumented, the devs could theoretically change the way it behaves without notice) - the Top property of an item in a listbox with a bound scrollbar will change as the scrollbar scrolls. Second, there is no way to force a bound scrollbar to scroll, so instead this method changes the listbox selection since the listbox will automatically scroll the selected item into view.
The following sample assumes you have a window with a listbox, "self.EList" (this happens to be the actual name of an object where I used this mechanism). Then where ever in the code that you add an item to the list box, you just check whether the list box is scrolled to the bottom by checking the height of the highest indexed item in the listbox against the listbox's height. If the listbox was scrolled to the bottom, then after you add the new item, just set the selection to the highest indexed item and it will automatically scroll to the bottom.
Here's the relevant code from an actual plugin:
Note that I use <= in the comparison because sometimes the GetTop() method will return 0 even though the item added has been scrolled.Code:local isMaxIndex=false; if self.EList:GetItemCount()>0 then isMaxIndex=(self.EList:GetItem(self.EList:GetItemCount()):GetTop()<=self.EList:GetHeight()); end self.EList:AddItem(tmpRow); if isMaxIndex then self.EList:SetSelectedIndex(self.EList:GetItemCount()) end
Last edited by Garan; Apr 14 2012 at 09:56 PM. Reason: typo
Gnashtooth - Rank 10 Warg - My breath's worse than my bite - but what d'ya want? I eat Hobbitsess fer cryin' out loud
Garan - Captain of little note - got parked at a Fell Scrying Pool so long it dried up and blew away
and many, many others...
"No, no, the hamsters are for the forums. The servers run on chinchillas!"-Patience 7/20/2007
-
Apr 15 2012 11:08 AM #4
Re: ScrollableControl's scrollbar behaviour
Thank you both for the help. That's a neat trick, Garan.
Why does SetSelectedIndex() cause a scroll, but SetSelectedItem() does not seem to? Oh well, as long as it works one way, I suppose it doesn't matter.
-
Apr 16 2012 11:18 PM #5
Re: ScrollableControl's scrollbar behaviour
Thanks, Garan. The bounded scrollbar trick was very helpful to me too.
-
Apr 18 2012 01:43 AM #6
Re: ScrollableControl's scrollbar behaviour
I would still strongly encourage using an unbound scroll bar for anything other than the most basic of controls. It's not that much extra effort and it affords you infinitely more control.
-
- Community Guidelines
- New Posts
- Dev Tracker
- Forum List
- Discussion Forums
- Classes
-
Worlds
- Arkenstone
- Brandywine
- Crickhollow
- Dwarrowdelf
- Eldar
- Elendilmir
- Evernight
- Firefoot
- Gilrain
- Gladden
- Imladris
- Landroval [EN-RE]
- Laurelin [EN-RP]
- Meneldor
- Nimrodel
- Riddermark
- Silverlode
- Snowbourn
- Vilya
- Windfola
- Withywindle
- Anduin [DE]
- Belegaer [DE-RP]
- Gwaihir [DE]
- Maiar [DE]
- Morthond [DE]
- Vanyar [DE]
- Estel [FR-RP]
- Sirannon [FR]
- Bullroarer (Public Test Server)
- Community
- Gameplay
- PvMP






Reply With Quote
