.. note::
    :class: sphx-glr-download-link-note

    Click :ref:`here <sphx_glr_download_auto_tutorials_02_ui_viz_ui_listbox.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_tutorials_02_ui_viz_ui_listbox.py:


=========
ListBox
=========

This example shows how to use the UI API. We will create a list
some geometric shapes from FURY UI elements.

First, a bunch of imports.


.. code-block:: default

    from fury import ui, window
    from fury.data import fetch_viz_icons







First we need to fetch some icons that are included in FURY.


.. code-block:: default


    fetch_viz_icons()





.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none

    Data size is approximately 12KB
    Dataset is already in place. If you want to fetch it again please first remove the folder /Users/koudoro/.fury/icons 



Create some text blocks that will be showm when
list elements will be selected


.. code-block:: default


    welcome_text = ui.TextBlock2D(text="Welcome", font_size=30,
                                  position=(500, 400))
    bye_text = ui.TextBlock2D(text="Bye", font_size=30, position=(500, 400))
    fury_text = ui.TextBlock2D(text="Fury", font_size=30, position=(500, 400))

    example = [welcome_text, bye_text, fury_text]







Hide these text blocks for now


.. code-block:: default



    def hide_all_examples():
        for element in example:
            element.set_visibility(False)


    hide_all_examples()







Create ListBox with the values as parameter.


.. code-block:: default


    values = ["Welcome", "Bye", "Fury"]
    listbox = ui.ListBox2D(
        values=values, position=(10, 300), size=(200, 200), multiselection=False
    )







Function to show selected element.


.. code-block:: default



    def display_element():
        hide_all_examples()
        element = example[values.index(listbox.selected[0])]
        element.set_visibility(True)


    listbox.on_change = display_element







Now that all the elements have been initialised, we add them to the show
manager.


.. code-block:: default


    current_size = (800, 800)
    show_manager = window.ShowManager(size=current_size,
                                      title="FURY UI ListBox_Example")

    show_manager.scene.add(listbox)
    show_manager.scene.add(welcome_text)
    show_manager.scene.add(bye_text)
    show_manager.scene.add(fury_text)
    interactive = False

    if interactive:
        show_manager.start()

    window.record(show_manager.scene,
                  size=current_size, out_path="viz_listbox.png")



.. image:: /auto_tutorials/02_ui/images/sphx_glr_viz_ui_listbox_001.png
    :class: sphx-glr-single-img





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.167 seconds)


.. _sphx_glr_download_auto_tutorials_02_ui_viz_ui_listbox.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download

     :download:`Download Python source code: viz_ui_listbox.py <viz_ui_listbox.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: viz_ui_listbox.ipynb <viz_ui_listbox.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_