Skip to content
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

Menubar #4839

Merged
merged 28 commits into from
Feb 24, 2022
Merged

Menubar #4839

merged 28 commits into from
Feb 24, 2022

Conversation

PureWeen
Copy link
Member

@PureWeen PureWeen commented Feb 22, 2022

Description of Change

Implements #4640

The API names currently follow the WinUI naming schemes. A few suggested alternatives for names that we can explore could be

MenuFlyoutItem => MenuBarMenuItem
MenuFlyoutSubItem => MenuBarSubMenuItem or MenuFlyoutSubMenuItem

Catalyst already comes with a menu so when implementing the menu on Catalyst you have to modify the existing menu. We will need to add more APIs for being able to remove and fully place menus where you want but at this point it will just try to match up against the Text and then place the menu according to that (see screenshots)

Catalyst Limitations

The Selectors for every single UICommand have to be unique. Because of this we have to compile in some default number of selectors. We chose 50 for the number of selectors. This means that if a user tries to add more than 50 MenuElements they will be met with the following exception

By default we only support 50 MenuItems. You can add more by adding the following code to Sample.MacCatalyst.AppDelegate

[Export("MenuItem50: ")]
internal void MenuItem50(UICommand uICommand)
{
	uICommand.SendClicked();
}

Example

MenuBarItems are added in the same manner as ToolbarItems

<views:BasePage.MenuBarItems>
    <MenuBarItem Text="File"></MenuBarItem>
    <MenuBarItem Text="Custom Menu">
        <MenuFlyoutItem Text="Item 1"></MenuFlyoutItem>
        <MenuFlyoutSubItem Text="Sub Menu 1">
            <MenuFlyoutItem Text="Flyout item 1"></MenuFlyoutItem>
            <MenuFlyoutItem Text="Flyout item 2"></MenuFlyoutItem>
        </MenuFlyoutSubItem>
    </MenuBarItem>
</views:BasePage.MenuBarItems>

Once their are properties that belong to MenuBar that users want to change we can add an attached property Window.MenuBar<xxxx> in order for users to configure those properties in the same way that users will customize NavigationPage.NavBar

Maui.Controls Additions made

public class Page
{
	public IList<MenuBarItem> MenuBarItems
}

Maui.Controls Changes made

  • Removed Menu.cs
  • Removed Attached Property for Menu on Application

Maui.Core Additions made

IMenuBarElement

This is used to attribute a view indicating that it has a MenuBar element that needs to be taken into consideration

public interface IMenuElement : IElement, IImageSourcePart, IText
{
	void Clicked();
}
public interface IMenuBarElement
{
	IMenuBar? MenuBar { get; }
}

IMenuBar

Top Level container.

public interface IMenuBar : IList<IMenuBarItem>, IElement
{
}

IMenuBarItem

Used to describe each primary menu inside the MenuBar (File, edit, etc..)

public interface IMenuBarItem : IList<IMenuElement>, IElement
{
	string Text { get; }
        bool IsEnabled { get; }
}

IMenuFlyoutItem

Describes an item that the user will click on to trigger behavior

public interface IMenuFlyoutItem : IMenuElement
{
}

IMenuFlyoutSubItem

Used to create submenus

public interface IMenuFlyoutSubItem : IMenuFlyoutItem, IList<IMenuElement>
{
}

ScreenShots

WinUI

image

image

MacCatalyst

Screen Shot 2022-02-23 at 6 59 46 PM

Known Issues

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the WinUI, Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

  • Does this PR introduce a new control? (If yes, add an example using SemanticProperties to the SemanticsPage)
  • APIs that modify focusability?
  • APIs that modify any text property on a control?
  • Does this PR modify view nesting or view arrangement in anyway?
  • Is there the smallest possibility that your PR will change accessibility?
  • I'm not sure, please help me

If any of the above checkboxes apply to your PR, then the PR will need to provide testing to demonstrate that accessibility still works.

@PureWeen PureWeen marked this pull request as draft February 22, 2022 21:45
@PureWeen PureWeen marked this pull request as ready for review February 23, 2022 22:09
@Redth Redth merged commit cbace2d into main Feb 24, 2022
@Redth Redth deleted the menubar branch February 24, 2022 14:38
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jul 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
@Eilon Eilon removed area/toolbar legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-image Image loading, sources, caching labels May 10, 2024
@samhouts samhouts added the fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants