// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 export component MenuBarItemBase { in property entry; in property default-foreground; in property hover-foreground; in property pressed-foreground; in property default-background; in property hover-background; in property pressed-background; in property font-size <=> label.font-size; in property font-weight <=> label.font-weight; in property border-radius <=> background-layer.border-radius; callback clicked; callback hovered; background-layer := Rectangle { background: root.default-background; touch-area := TouchArea { layout := HorizontalLayout { padding-top: root.padding-top; padding-bottom: root.padding-bottom; padding-left: root.padding-left; padding-right: root.padding-right; label := Text { text: entry.title; color: root.default-foreground; } } pointer-event(event) => { if event.kind == PointerEventKind.down { root.clicked(); } } changed has-hover => { if self.has-hover { root.hovered(); } } } } states [ pressed when touch-area.pressed : { background-layer.background: root.pressed-background; label.color: root.pressed-foreground; } has-hover when touch-area.has-hover : { background-layer.background: root.hover-background; label.color: root.hover-foreground; } ] } export component MenuBarBase inherits Rectangle { in property spacing <=> layout.spacing; in property alignment <=> layout.alignment; in property min-layout-height; min-height: max(root.min-layout-height, layout.min-height); layout := HorizontalLayout { alignment: start; padding: root.padding; padding-left: root.padding-left; padding-right: root.padding-right; padding-top: root.padding-top; padding-bottom: root.padding-bottom; @children } } export component MenuFrameBase inherits Rectangle { in property spacing <=> layout.spacing; in property layout-min-width; clip: true; min-width: max(root.layout-min-width, layout.min-width); layout := VerticalLayout { padding: root.padding; @children } } export component MenuItemBase { in property default-foreground; in property default-background; in property current-foreground; in property current-background; in property separator-color; in property font-size <=> label.font-size; in property font-weight <=> label.font-weight; in property border-radius <=> background-layer.border-radius; in property is-current; in property entry; in property sub-menu-icon; in property spacing <=> layout.spacing; in property icon-size; callback set-current(); callback clear-current(); callback activate(entry : MenuEntry, y: length); background-layer := Rectangle { background: root.default-background; touch-area := TouchArea { visible: !entry.is-separator; enabled: entry.enabled; layout := HorizontalLayout { padding-top: root.padding-top; padding-bottom: root.padding-bottom; padding-left: root.padding-left; padding-right: root.padding-right; label := Text { text: entry.title; color: root.default-foreground; vertical-alignment: center; } if entry.has-sub-menu : Image { width: root.icon-size; y: (parent.height - self.height) / 2; source: root.sub-menu-icon; colorize: label.color; accessible-role: none; } } pointer-event(event) => { if event.kind == PointerEventKind.move && !root.is-current { root.set-current() } else if event.kind == PointerEventKind.down && entry.has-sub-menu && entry.enabled { activate(entry, self.absolute-position.y); } else if event.kind == PointerEventKind.up && self.mouse-y > 0 && self.mouse-y < self.height && self.mouse-x > 0 && self.mouse-x < self.width && entry.enabled { // can't put this in `clicked` because then the menu would close causing a panic in the pointer-event activate(entry, self.absolute-position.y); } } changed has-hover => { if !self.has-hover && root.is-current { root.clear-current(); } } } if entry.is-separator: Rectangle { height: 1px; background: root.separator-color; } } states [ is-current when root.is-current : { background-layer.background: root.current-background; label.color: root.current-foreground; } disabled when !entry.enabled : { label.opacity: 0.5; } ] }