import omni.ui as ui

class LabelMenuDelegate(ui.MenuDelegate):
    """
    The menu delegate that show menu item text as a label.

    kwargs:
        enable (bool): Label enabled or not. Default True.
        width (ui.Length): Label width. Default ui.Fraction(1).
        height (ui.Length): Label height. Default 26 pixels.
        alignment (ui.Alignment): Label alignment. Default ui.Alignment.CENTER.
    """

    def __init__(
        self,
        enabled: bool = True,
        width: ui.Length = ui.Fraction(1),
        height: ui.Length = 26,
        alignment: ui.Alignment = ui.Alignment.LEFT
    ):
        super().__init__(propagate=False)
        self.__enabled = enabled
        self.__height = height
        self.__width = width
        self.__alignment = alignment
        
    def build_item(self, item: ui.MenuItem):
        self.__frame = ui.Frame(width=self.__width, height=self.__height, style_type_name_override="Menu.Item", enabled=self.__enabled)
        with self.__frame:
            ui.Label(item.text, style_type_name_override="Menu.Item.Label", alignment=self.__alignment)