// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: MIT import { Theme } from "../theme.slint"; import { MenuButton } from "menu_button.slint"; import { MenuBackground } from "../components/menu_background.slint"; export component Menu { in-out property menu-button-visible; in property start-y; in property end-y; in property stays-open; in property menu-width <=> i-menu-container.width; in property menu-height <=> i-menu-container.height; out property open; callback opened(); callback closed(); public function hide-button() { menu-button-visible = false; } public function open-menu() { open = true; } public function hide() { menu-button-visible = false; open = false; closed(); } private property container-visibility; states [ open when root.open : { container-visibility: 1.0; i-menu-container.y: end-y; in { animate i-menu-container.y { duration: Theme.durations.medium; } } out { animate container-visibility, i-menu-container.y { duration: Theme.durations.medium; } } } ] if (open) : Rectangle { background: Theme.palette.pure-black; opacity: 0.5; TouchArea { clicked => { hide(); } } } i-menu-container := Rectangle { x: (parent.width - self.width) / 2; y: parent.height - start-y; width: root.width / 3; height: root.height - 75px; i-container := MenuBackground { visible: container-visibility == 1.0; // avoid click-through TouchArea {} @children } if(menu-button-visible || container-visibility == 1.0 || stays-open) : HorizontalLayout { y: -i-menu-button.height / 2; alignment: center; VerticalLayout { alignment: start; i-menu-button := MenuButton { clicked => { if(open) { hide(); } else { open-menu(); } } } } } } } export component MobileMenu { out property open; in property end-y; in property menu-x; out property menu-width: 200px; if (root.open) : Rectangle { background: Theme.palette.pure-black; opacity: 0.5; TouchArea { clicked => { hide(); } } } public function open-menu() { root.open = true; } public function hide() { root.open = false; } Rectangle { clip: true; menu := Rectangle { x: root.menu-x; y: -self.height; width: root.menu-width; height: root.height / 2; visible: visibility > 0.0; private property visibility; MenuBackground { // avoid click-through TouchArea {} @children } states [ open when root.open : { menu.y: end-y; visibility: 1.0; out { animate visibility { duration: Theme.durations.medium; } } } ] animate y { duration: Theme.durations.fast; } } } }