We have detected that cookies are not enabled on your browser. Please enable cookies to ensure the proper experience.
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2011
    Posts
    34

    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.

  2. #2
    Join Date
    Mar 2007
    Posts
    1,780

    Re: ScrollableControl's scrollbar behaviour

    Quote Originally Posted by Polymnie View Post
    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.
    You pretty much have to make an unbound scrollbar and do all the scrolling manually. A bit of a pain, but it's not too difficult.
    [B]Elendilmir - [COLOR=#3333ff]Evenwyn[/COLOR][/B] Burglar[B] - [COLOR=#3333ff]Evendale[/COLOR][/B] Guardian
    [FONT=Verdana][COLOR=#ff0000][SIZE=2][B]Combat Analysis[/B] [/SIZE][/COLOR][SIZE=2]([B]v4.2.3b[/B]) - [/SIZE][/FONT]Download "[URL="http://www.lotrointerface.com/downloads/info502-CombatAnalysis.html"]here[/URL]"

  3. #3
    Join Date
    Mar 2007
    Posts
    1,212

    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:
    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
    Note that I use <= in the comparison because sometimes the GetTop() method will return 0 even though the item added has been scrolled.
    Last edited by Garan; Apr 14 2012 at 10:56 PM. Reason: typo

  4. #4
    Join Date
    May 2011
    Posts
    34

    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.

  5. Re: ScrollableControl's scrollbar behaviour

    Thanks, Garan. The bounded scrollbar trick was very helpful to me too.
    [url="http://astleigh.mymiddleearth.com/"]Astleigh's Songbook[/url] | [url="http://www.lotrointerface.com/downloads/info455-Lyrical.html"]Lyrical[/url]

  6. #6
    Join Date
    Mar 2007
    Posts
    1,780

    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.
    [B]Elendilmir - [COLOR=#3333ff]Evenwyn[/COLOR][/B] Burglar[B] - [COLOR=#3333ff]Evendale[/COLOR][/B] Guardian
    [FONT=Verdana][COLOR=#ff0000][SIZE=2][B]Combat Analysis[/B] [/SIZE][/COLOR][SIZE=2]([B]v4.2.3b[/B]) - [/SIZE][/FONT]Download "[URL="http://www.lotrointerface.com/downloads/info502-CombatAnalysis.html"]here[/URL]"

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

This form's session has expired. You need to reload the page.

Reload