# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
"""The documentation for Scrolling Frame"""

from omni import ui
from .doc_page import DocPage

SPACING = 5


class ScrollingFrameDoc(DocPage):
    """ document for Menu"""

    def create_doc(self, navigate_to=None):
        self._section_title("ScrollingFrame")

        self._text(
            "The ScrollingFrame class provides the ability to scroll onto another widget. ScrollingFrame is used to "
            "display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the "
            "frame can provide scroll bars so that the entire area of the child widget can be viewed."
        )

        with ui.HStack(style=self._style_system):
            left_frame = ui.ScrollingFrame(
                height=250,
                horizontal_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_OFF,
                vertical_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_ON,
            )
            with left_frame:
                with ui.VStack(height=0):
                    for i in range(20):
                        ui.Button(f"Button Left {i}")

            right_frame = ui.ScrollingFrame(
                height=250,
                horizontal_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_OFF,
                vertical_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_ON,
            )
            with right_frame:
                with ui.VStack(height=0):
                    for i in range(20):
                        ui.Button(f"Button Right {i}")

        # Synchronize the scroll position of two frames
        def set_scroll_y(frame, y):
            frame.scroll_y = y

        left_frame.set_scroll_y_changed_fn(lambda y, frame=right_frame: set_scroll_y(frame, y))
        right_frame.set_scroll_y_changed_fn(lambda y, frame=left_frame: set_scroll_y(frame, y))

        self._code(
            """
        with ui.HStack(style=style_system):
            left_frame = ui.ScrollingFrame(
                height=250,
                horizontal_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_OFF,
                vertical_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_ON,
            )
            with left_frame:
                with ui.VStack(height=0):
                    for i in range(20):
                        ui.Button(f"Button Left {i}")

            right_frame = ui.ScrollingFrame(
                height=250,
                horizontal_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_OFF,
                vertical_scrollbar_policy=ui.ScrollBarPolicy.SCROLLBAR_ALWAYS_ON,
            )
            with right_frame:
                with ui.VStack(height=0):
                    for i in range(20):
                        ui.Button(f"Button Right {i}")

        # Synchronize the scroll position of two frames
        def set_scroll_y(frame, y):
            frame.scroll_y = y

        left_frame.set_scroll_y_changed_fn(
            lambda y, frame=right_frame: set_scroll_y(frame, y))
        right_frame.set_scroll_y_changed_fn(
            lambda y, frame=left_frame: set_scroll_y(frame, y)
            """
        )

        ui.Spacer(height=10)
