ListView, any tutorial?

jospicjospic Posts: 3Member

Godot is an engine born for games. It 's true, but it's very powerful for building applications too. Unfortunately around I do not find any tutorial that teaches how to use the UI objects (panel, treeview, itemlist, ect.).
For example, how to make a list of scrollable and clickable buttons, like this?

Probably with VButtonArray control, but how to implement this?

Thanks in advance.


  • bitwesbitwes Posts: 64Member

    This example might be slightly more involved but it was the quickest one I could find from what I've made. It's a simple menu that loads up scenes based on what button you use. It uses an array of arrays (scenes) to populate the menu and do stuff.

    For example:
    scenes[0][0] = 'Main' # the text to be displayed on the button
    scenes[0][1] = load(res://scenes/main.tscn) # the scene to be loaded

    The List control was added via the editor and wired up to _on_sceneList_item_selected via the editor as well. There's two signals you can consume for the click event, one of them doesn't send the index of the selected item. I'm using the one that does. I think the difference is that this one doesn't fire when you re-select the same item.

    This exact code wasn't tested since I had to change some things for it to make sense out of the context of my game, but it should mostly work.

    var scenes = []
    func _ready():
    # Fill up the list control with the Menu text
    func _populate_list():
        for i in range(scenes.size()):
            if(i > _normal_end):
                scene_list.set_item_custom_bg_color(i, Color(.25, .25, 1))
    # Fill up the array with the menu text and scenes to show.
    func _add_menus():
        scenes.append(['Main', load('res://scenes/main.tscn')])
        scenes.append(['Unlockables', load('res://scenes/unlockables.tscn')])
        scenes.append(['Customize', load('res://scenes/customize.tscn')])
        scenes.append(['Achievements', load('res://scenes/achievements.tscn')])
        scenes.append(['Options', load('res://scenes/options.tscn')])
        _normal_end = scenes.size() -1
    # the show_scene method is something I created that swaps 
    # out whatever sub-scene is currently loaded with the newly
    # selected scene.
    # it basically uses the index to get the scene out of the scenes array
    # and then release the current scene and shows the new one.
    func _on_sceneList_item_selected( index ):
  • RossRoss Posts: 199Member

    If you want a scrollable list of items, use a ScrollContainer. Any children it has will be arranged inside of it as a list. So all you have to do for a scrollable list of buttons is make a ScrollContainer and give it some Button children.

    If you're making a utility program with Godot you'll probably want to use OS.set_low_processor_usage_mode(true). That's the mode the editor uses which makes it only update if something changes, which saves a lot of CPU if you have a mostly static application.

  • Shin-NiLShin-NiL Posts: 158Moderator

    If you are targeting Android, OS.set_low_processor_usage_mode(true) seems to not be a option :(

Sign In or Register to comment.