mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-17 05:47:42 +00:00
material: PopupMenu: Changes (https://github.com/slint-ui/material-components/issues/158)
Imported from 81415330ff
This commit is contained in:
parent
f9f872c5e5
commit
f368b401dc
8 changed files with 37 additions and 19 deletions
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
|
||||||
|
title: MenuItem
|
||||||
|
description: MenuItem content
|
||||||
|
---
|
||||||
|
|
||||||
|
`MenuItem`
|
||||||
|
|
||||||
|
This structure represents a MenuItem with an icon, text, trailing text, and enabled state.
|
||||||
|
|
||||||
|
- **`icon`** (_image_): The icon to display in the item.
|
||||||
|
- **`text`** (_string_): The text to display in the item.
|
||||||
|
- **`trailing_text`** (_string_): The trailing text to display in the item.
|
||||||
|
- **`enabled`** (_bool_): Whether the item is enabled.
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
|
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
|
||||||
title: Menu
|
title: PopupMenu
|
||||||
description: Menu API.
|
description: PopupMenu API.
|
||||||
---
|
---
|
||||||
|
|
||||||
import CodeSnippetMD from '/src/components/CodeSnippetMD.astro';
|
import CodeSnippetMD from '/src/components/CodeSnippetMD.astro';
|
||||||
|
@ -9,12 +9,12 @@ import SlintProperty from '/src/components/SlintProperty.astro';
|
||||||
|
|
||||||
<CodeSnippetMD imagePath="/src/assets/generated/menu2.png" scale="3" imageWidth="300" imageHeight="200" imageAlt="">
|
<CodeSnippetMD imagePath="/src/assets/generated/menu2.png" scale="3" imageWidth="300" imageHeight="200" imageAlt="">
|
||||||
```slint
|
```slint
|
||||||
import { Menu } from "./material.slint";
|
import { PopupMenu } from "./material.slint";
|
||||||
export component Example inherits Window {
|
export component Example inherits Window {
|
||||||
width: 400px;
|
width: 400px;
|
||||||
height: 300px;
|
height: 300px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
Menu {
|
PopupMenu {
|
||||||
width: 280px;
|
width: 280px;
|
||||||
height: parent.height;
|
height: parent.height;
|
||||||
items: [
|
items: [
|
||||||
|
@ -27,7 +27,7 @@ export component Example inherits Window {
|
||||||
```
|
```
|
||||||
</CodeSnippetMD>
|
</CodeSnippetMD>
|
||||||
|
|
||||||
A `Menu` display a list of choices on a temporary surface.
|
A `PopupMenu` to display a list of choices on a temporary surface.
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
|
@ -38,5 +38,5 @@ An array of menu items, each containing an icon, a text, and a trailing text.
|
||||||
|
|
||||||
## Callbacks
|
## Callbacks
|
||||||
|
|
||||||
### item_clicked(index: int)
|
### activated(index: int)
|
||||||
Invoked when a menu item is clicked
|
Invoked when a menu item is clicked
|
|
@ -7,6 +7,7 @@ import IconButtonItem from "../../collections/structs/IconButtonItem.md"
|
||||||
import ListItem from "../../collections/structs/ListItem.md"
|
import ListItem from "../../collections/structs/ListItem.md"
|
||||||
import SegmentedItem from "../../collections/structs/SegmentedItem.md"
|
import SegmentedItem from "../../collections/structs/SegmentedItem.md"
|
||||||
import Time from "../../collections/structs/Time.md"
|
import Time from "../../collections/structs/Time.md"
|
||||||
|
import MenuItem from "../../collections/structs/MenuItem.md"
|
||||||
import NavigationItem from "../../collections/structs/NavigationItem.md"
|
import NavigationItem from "../../collections/structs/NavigationItem.md"
|
||||||
import NavigationGroup from "../../collections/structs/NavigationGroup.md"
|
import NavigationGroup from "../../collections/structs/NavigationGroup.md"
|
||||||
|
|
||||||
|
@ -23,6 +24,9 @@ import ScrollBarPolicy from "../../collections/enums/ScrollBarPolicy.md"
|
||||||
### ListItem
|
### ListItem
|
||||||
<ListItem />
|
<ListItem />
|
||||||
|
|
||||||
|
### MenuItem
|
||||||
|
<MenuItem />
|
||||||
|
|
||||||
### NavigationItem
|
### NavigationItem
|
||||||
<NavigationItem />
|
<NavigationItem />
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
NavigationItem,
|
NavigationItem,
|
||||||
NavigationBar,
|
NavigationBar,
|
||||||
SmallAppBar,
|
SmallAppBar,
|
||||||
Menu,
|
PopupMenu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
MaterialStyleMetrics
|
MaterialStyleMetrics
|
||||||
} from "../../../../material.slint";
|
} from "../../../../material.slint";
|
||||||
|
@ -71,12 +71,12 @@ export component MainView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
color_menu := Menu {
|
color_menu := PopupMenu {
|
||||||
x: root.width - MaterialStyleMetrics.size_200 - MaterialStyleMetrics.padding_16;
|
x: root.width - MaterialStyleMetrics.size_200 - MaterialStyleMetrics.padding_16;
|
||||||
y: app_bar.height / 2;
|
y: app_bar.height / 2;
|
||||||
items: MainViewAdapter.palettes;
|
items: MainViewAdapter.palettes;
|
||||||
|
|
||||||
item_clicked(index) => {
|
activated(index) => {
|
||||||
MainViewAdapter.load_palette(index);
|
MainViewAdapter.load_palette(index);
|
||||||
color_menu.close();
|
color_menu.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import {
|
||||||
Slider,
|
Slider,
|
||||||
TextField,
|
TextField,
|
||||||
RadioButtonTile,
|
RadioButtonTile,
|
||||||
Menu,
|
PopupMenu,
|
||||||
DropDownMenu,
|
DropDownMenu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
DatePickerPopup
|
DatePickerPopup
|
||||||
|
@ -439,7 +439,7 @@ export component NavigationView {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
menu := Menu {
|
menu := PopupMenu {
|
||||||
x: menu_button.x + menu_button.width / 2;
|
x: menu_button.x + menu_button.width / 2;
|
||||||
y: menu_button.y + menu_button.height / 2;
|
y: menu_button.y + menu_button.height / 2;
|
||||||
items: [
|
items: [
|
||||||
|
|
|
@ -30,7 +30,7 @@ export { Avatar, ListTile } from "./ui/components/list.slint";
|
||||||
export { ListView } from "./ui/components/list_view.slint";
|
export { ListView } from "./ui/components/list_view.slint";
|
||||||
export { MaterialText } from "./ui/components/material_text.slint";
|
export { MaterialText } from "./ui/components/material_text.slint";
|
||||||
export { MaterialWindow, MaterialWindowAdapter } from "./ui/components/material_window.slint";
|
export { MaterialWindow, MaterialWindowAdapter } from "./ui/components/material_window.slint";
|
||||||
export { Menu } from "./ui/components/menu.slint";
|
export { PopupMenu } from "./ui/components/menu.slint";
|
||||||
export { NavigationBar } from "./ui/components/navigation_bar.slint";
|
export { NavigationBar } from "./ui/components/navigation_bar.slint";
|
||||||
export { NavigationDrawer, ModalNavigationDrawer } from "./ui/components/navigation_drawer.slint";
|
export { NavigationDrawer, ModalNavigationDrawer } from "./ui/components/navigation_drawer.slint";
|
||||||
export { NavigationRail } from "./ui/components/navigation_rail.slint";
|
export { NavigationRail } from "./ui/components/navigation_rail.slint";
|
||||||
|
|
|
@ -93,7 +93,7 @@ export component DropDownMenu {
|
||||||
current_index: root.current_index;
|
current_index: root.current_index;
|
||||||
items: root.items;
|
items: root.items;
|
||||||
|
|
||||||
item_clicked(index) => {
|
activated(index) => {
|
||||||
root.update_selection(index);
|
root.update_selection(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ export component MenuInner {
|
||||||
in property <[MenuItem]> items;
|
in property <[MenuItem]> items;
|
||||||
in_out property <int> current_index: -1;
|
in_out property <int> current_index: -1;
|
||||||
|
|
||||||
callback item_clicked(index: int);
|
callback activated(index: int);
|
||||||
|
|
||||||
// used to fix clipping of shadows
|
// used to fix clipping of shadows
|
||||||
out property <int> elevation: 2;
|
out property <int> elevation: 2;
|
||||||
|
@ -107,17 +107,17 @@ export component MenuInner {
|
||||||
selected: index == root.current_index;
|
selected: index == root.current_index;
|
||||||
|
|
||||||
clicked => {
|
clicked => {
|
||||||
root.item_clicked(index);
|
root.activated(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export component Menu inherits PopupWindow {
|
export component PopupMenu inherits PopupWindow {
|
||||||
in property <[MenuItem]> items;
|
in property <[MenuItem]> items;
|
||||||
|
|
||||||
callback item_clicked(index: int);
|
callback activated(index: int);
|
||||||
|
|
||||||
width: MaterialStyleMetrics.size_200;
|
width: MaterialStyleMetrics.size_200;
|
||||||
close_policy: close_on_click_outside;
|
close_policy: close_on_click_outside;
|
||||||
|
@ -128,8 +128,8 @@ export component Menu inherits PopupWindow {
|
||||||
inner := MenuInner {
|
inner := MenuInner {
|
||||||
items: root.items;
|
items: root.items;
|
||||||
|
|
||||||
item_clicked(index) => {
|
activated(index) => {
|
||||||
root.item_clicked(index);
|
root.activated(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue