-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document MenuBar and ContextMenu #7502
Merged
+128
−26
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
docs/astro/src/content/docs/reference/window/contextmenu.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
<!-- Copyright © SixtyFPS GmbH <[email protected]> ; SPDX-License-Identifier: MIT --> | ||
title: ContextMenu | ||
description: ContextMenu element api. | ||
--- | ||
import SlintProperty from '/src/components/SlintProperty.astro'; | ||
import Link from '/src/components/Link.astro'; | ||
|
||
Use the non-visual `ContextMenu` element to declare a context menu. | ||
|
||
The context menu is shown if the user right-clicks on the area covered by the `ContextMenu` element, | ||
or if the user presses the "Menu" key on their keyboard while a `FocusScope` within the `ContextMenu` has focus. | ||
Call the `show()` function on the `ContextMenu` element to programmatically show the context menu. | ||
|
||
Define the structure of the menu by placing `MenuItem` elements into the `ContextMenu`. | ||
|
||
## Function | ||
|
||
### show(Point) | ||
|
||
Call this function to programmatically show the context menu at the given position relative to the `ContextMenu` element. | ||
|
||
## `MenuItem` | ||
|
||
A `MenuItem` represents a single menu entry. It can be placed as a child of a `ContextMenu`, | ||
<Link type="MenuBar" />, or another `MenuItem`. | ||
|
||
### Properties of `MenuItem` | ||
|
||
#### title | ||
<SlintProperty propName="title" typeName="string" defaultValue='""'> | ||
The label of the entry within the menu. | ||
</SlintProperty> | ||
|
||
### Callbacks of `MenuItem` | ||
|
||
#### activated() | ||
|
||
Invoked when the menu entry is activated. | ||
|
||
:::note{Note} | ||
This is only called if the menu entry doesn't have submenus. | ||
::: | ||
|
||
## Example | ||
|
||
```slint | ||
export component Example { | ||
ContextMenu { | ||
MenuItem { | ||
title: @tr("Cut"); | ||
activated => { debug("Cut"); } | ||
} | ||
MenuItem { | ||
title: @tr("Copy"); | ||
activated => { debug("Copy"); } | ||
} | ||
MenuItem { | ||
title: @tr("Paste"); | ||
activated => { debug("Paste"); } | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling that we might revisit these semantics in the API review ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, feel free to let me know what feels wrong there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guts feeling is that we may be better off accepting absolute coordinates, to disambiguate the API.
The relative coordinates make sense when
ContextMenu
surrounds the area that provides the context menu, but I'm not sure one would callshow()
then and instead rely on the automatic support for the right click?And when it's not surrounding, the relative coordinates require additional steps:
As opposed to just taking absolute coordinates: