.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/07_ui/viz_ui_listbox.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_auto_examples_07_ui_viz_ui_listbox.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_07_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.

.. GENERATED FROM PYTHON SOURCE LINES 12-15

.. code-block:: Python


    import fury








.. GENERATED FROM PYTHON SOURCE LINES 16-17

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

.. GENERATED FROM PYTHON SOURCE LINES 17-20

.. code-block:: Python


    fury.data.fetch_viz_icons()





.. rst-class:: sphx-glr-script-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/skoudoro/.fury/icons 

    ({'icomoon.tar.gz': ('https://digital.lib.washington.edu/researchworks/bitstream/handle/1773/38478/icomoon.tar.gz', 'BC1FEEA6F58BA3601D6A0B029EB8DFC5F352E21F2A16BA41099A96AA3F5A4735')}, '/Users/skoudoro/.fury/icons')



.. GENERATED FROM PYTHON SOURCE LINES 21-23

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

.. GENERATED FROM PYTHON SOURCE LINES 23-30

.. code-block:: Python


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

    example = [welcome_text, bye_text, fury_text]








.. GENERATED FROM PYTHON SOURCE LINES 31-32

Hide these text blocks for now

.. GENERATED FROM PYTHON SOURCE LINES 32-41

.. code-block:: Python



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


    hide_all_examples()








.. GENERATED FROM PYTHON SOURCE LINES 42-43

Create ListBox with the values as parameter.

.. GENERATED FROM PYTHON SOURCE LINES 43-49

.. code-block:: Python


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








.. GENERATED FROM PYTHON SOURCE LINES 50-51

Function to show selected element.

.. GENERATED FROM PYTHON SOURCE LINES 51-61

.. code-block:: Python



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


    listbox.on_change = display_element








.. GENERATED FROM PYTHON SOURCE LINES 62-64

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

.. GENERATED FROM PYTHON SOURCE LINES 64-82

.. code-block:: Python


    current_size = (800, 800)
    show_manager = fury.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()

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



.. image-sg:: /auto_examples/07_ui/images/sphx_glr_viz_ui_listbox_001.png
   :alt: viz ui listbox
   :srcset: /auto_examples/07_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.082 seconds)


.. _sphx_glr_download_auto_examples_07_ui_viz_ui_listbox.py:

.. only:: html

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

    .. container:: sphx-glr-download sphx-glr-download-jupyter

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

    .. container:: sphx-glr-download sphx-glr-download-python

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


.. only:: html

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

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