# 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 ProgressBar"""

from omni import ui
from omni.ui import color as cl
from .doc_page import DocPage

SPACING = 5


class CustomProgressValueModel(ui.AbstractValueModel):
    """An example of custom float model that can be used for progress bar"""

    def __init__(self, value: float):
        super().__init__()
        self._value = value

    def set_value(self, value):
        """Reimplemented set"""
        try:
            value = float(value)
        except ValueError:
            value = None
        if value != self._value:
            # Tell the widget that the model is changed
            self._value = value
            self._value_changed()

    def get_value_as_float(self):
        return self._value

    def get_value_as_string(self):
        return "Custom Overlay"


class ProgressBarDoc(DocPage):
    """ document for ProgressBar"""

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

        self._text("A progressbar is widget that indicates the progress of an operation.")

        self._text("In the following example, it shows how to use progress bar and override the overlay text.")

        with ui.VStack(spacing=SPACING):
            # Create progressbars
            first = ui.ProgressBar()
            # Range is [0.0, 1.0]
            first.model.set_value(0.5)

            second = ui.ProgressBar()
            second.model.set_value(1.0)

            # Overrides the overlay of progressbar
            model = CustomProgressValueModel(0.8)
            third = ui.ProgressBar(model)
            third.model.set_value(0.1)

            # Styling its color
            fourth = ui.ProgressBar(style={"color": cl("#0000DD")})
            fourth.model.set_value(0.3)

            # Styling its border width
            ui.ProgressBar(style={"border_width": 2, "color": cl("#0000DD")}).model.set_value(0.7)

            # Styling its border radius
            ui.ProgressBar(style={"border_radius": 100, "color": cl("#0000DD")}).model.set_value(0.6)

            # Styling its background color
            ui.ProgressBar(style={"border_radius": 100, "background_color": cl("#0000DD")}).model.set_value(0.6)

            # Styling the text color
            ui.ProgressBar(style={"border_radius": 100, "secondary_color": cl("#00DDDD")}).model.set_value(0.6)

            # Two progress bars in a row with padding
            with ui.HStack():
                ui.ProgressBar(style={"color": cl("#0000DD"), "padding": 100}).model.set_value(1.0)
                ui.ProgressBar().model.set_value(0.0)

        self._code(
            """
            # Create progressbars
            first = ui.ProgressBar()
            # Range is [0.0, 1.0]
            first.model.set_value(0.5)

            second = ui.ProgressBar()
            second.model.set_value(1.0)

            # Overrides the overlay of progressbar
            model = CustomProgressValueModel(0.8)
            third = ui.ProgressBar(model)
            third.model.set_value(0.1)

            # Styling its color
            fourth = ui.ProgressBar(style={"color": cl("#0000DD")})
            fourth.model.set_value(0.3)

            # Styling its border width
            ui.ProgressBar(style={"border_width": 2, "color": cl("#0000DD")}).model.set_value(0.7)

            # Styling its border radius
            ui.ProgressBar(style={"border_radius": 100, "color": cl("#0000DD")}).model.set_value(0.6)

            # Styling its background color
            ui.ProgressBar(style={"border_radius": 100, "background_color": cl("#0000DD")}).model.set_value(0.6)

            # Styling the text color
            ui.ProgressBar(style={"border_radius": 100, "secondary_color": cl("#00DDDD")}).model.set_value(0.6)

            # Two progress bars in a row with padding
            with ui.HStack():
                ui.ProgressBar(style={"color": cl("#0000DD"), "padding": 100}).model.set_value(1.0)
                ui.ProgressBar().model.set_value(0.0)
            """
        )

        ui.Spacer(height=10)
