Where is a working DirectScrolledList example

Hi folks,

I’ve been experimenting with DirectScrolledLists heavily but besides two scroll buttons and one shown button I haven’t been able to produce anything useful.

Unfortunatly the manual does not provide a working example - to be true, I haven’t even found out how a direct scrolled list should look like properly. Arg… I imagine/hope that I’ll get a vertical or horizontal list of buttons/labels/… (whatever) with the option to scroll left/right (up/down) if there are more entries than space to show the GUI elements…

What I’m able to produce is: a working directscrolledlist which has e.g. 3 buttons or labels - but only one is shown.

I paste my last confused tryout - maybe someone can give me a pointer… You can see I tried out a lot of things (e.g. forcedHeight) to get the idea…

Andrew

        b1 = DirectButton(
        text = ("Button1", "click!", "roll", "disabled"),
        scale=0.1,
        relief=2)

        b2 = DirectButton(
        text = ("Button2", "click!", "roll", "disabled"),
        scale=0.1,
        relief=2)

        l1 = DirectLabel(text = "Test1", scale=0.1)
        l2 = DirectLabel(text = "Test2", scale=0.1)
        l3 = DirectLabel(text = "Test3", scale=0.1)

        myScrolledList = DirectScrolledList(incButton_pos= (0.25,0,0.52), 
                incButton_text = "Inc", 
                incButton_scale = 0.08,
                decButton_pos= (0.25,0,-0.04), 
                decButton_text = "Dec", 
                decButton_scale = 0.08,
                forceHeight=3, items = [b1,b2],
                numItemsVisible=1 )

        
        #l1 = myScrolledList.itemMakeFunction("label1")
        myScrolledList.addItem(l1)
        myScrolledList.addItem(l2)
        myScrolledList.addItem(l3)
        l1.setPos(0,0,0.1)
        l2.setPos(0,0,0.3)
        l3.setPos(0,0,0.5)
        myScrolledList.refresh()
        #l1.hide()
        #l2.hide()
        #l3.hide()
        #myScrolledList['text'] = "MyScrolledList"
        #myScrolledList['text_scale'] = 0.2
        
        myScrolledList['frameSize'] = (-0.1, 0.6, -0.1, 0.6)
        myScrolledList['frameColor'] = (1,0,0,0.5)

        myScrolledList.itemFrame['frameSize'] = (0, 0.5, 0, 0.5)
        
        #myScrolledList.incButton['frameSize'] = (0, 0.1, 0, 0.1)
        #myScrolledList.decButton['frameSize'] = (0, 0.1, 0, 0.1)
        myScrolledList.incButton['text_scale'] = .5
        myScrolledList.decButton['text_scale'] = .5
        myScrolledList.setPos(-1,0,0)
        pdir(myScrolledList.itemFrame)
        myScrolledList.itemFrame.resetFrameSize()
        myScrolledList.resetFrameSize()

Seems like you had the right idea. There does appear to be a minor bug in DirectScrolledList, however, which was probably tripping you up: it tries to determine the height of each of the items you add, but it gets it wrong if the items have a scale on their top node.

To avoid this bug, either use text_scale, geom_scale, etc. on your individual items (instead of scale), or use the forceHeight parameter to DirectScrolledList, which tells it an explicit height for your items.

Other than that, the rest is just fussing with placement. Here’s a modified version of your example:

from direct.directbase.DirectStart import *
from direct.gui.DirectGui import *
from pandac.PandaModules import *

b1 = DirectButton(text = ("Button1", "click!", "roll", "disabled"),
                  text_scale=0.1, borderWidth = (0.01, 0.01),
                  relief=2)

b2 = DirectButton(text = ("Button2", "click!", "roll", "disabled"),
                  text_scale=0.1, borderWidth = (0.01, 0.01),
                  relief=2)

l1 = DirectLabel(text = "Test1", text_scale=0.1)
l2 = DirectLabel(text = "Test2", text_scale=0.1)
l3 = DirectLabel(text = "Test3", text_scale=0.1)

numItemsVisible = 4
itemHeight = 0.11

myScrolledList = DirectScrolledList(
    decButton_pos= (0.35, 0, 0.53),
    decButton_text = "Dec",
    decButton_text_scale = 0.04,
    decButton_borderWidth = (0.005, 0.005),

    incButton_pos= (0.35, 0, -0.02),
    incButton_text = "Inc",
    incButton_text_scale = 0.04,
    incButton_borderWidth = (0.005, 0.005),

    frameSize = (0.0, 0.7, -0.05, 0.59),
    frameColor = (1,0,0,0.5),
    pos = (-1, 0, 0),
    items = [b1, b2],
    numItemsVisible = numItemsVisible,
    forceHeight = itemHeight,
    itemFrame_frameSize = (-0.2, 0.2, -0.37, 0.11),
    itemFrame_pos = (0.35, 0, 0.4),
    )

myScrolledList.addItem(l1)
myScrolledList.addItem(l2)
myScrolledList.addItem(l3)

for fruit in ['apple', 'pear', 'banana', 'orange']:
    l = DirectLabel(text = fruit, text_scale=0.1)
    myScrolledList.addItem(l)

David

Hi David,

thanks a lot! Works! Coool…

I’m currently working on a generic “menu” class system which will build a consistent menu system, comparable to a windows style menu system (in a way).

I’ll post the whole class system in some weeks as a “thanks” for your support.

Andrew