Skip to content

Commit

Permalink
Add TitleBar (#167)
Browse files Browse the repository at this point in the history
* Add TitleBar
  • Loading branch information
Dreamescaper authored Nov 13, 2024
1 parent fbfa452 commit dd834af
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 66 deletions.
145 changes: 79 additions & 66 deletions samples/ControlGallery/AppShell.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,96 @@
@using ControlGallery.Views.Menus

<Window Title="Main Window">
<Shell BackgroundColor="_backgroundColor"
ForegroundColor="_foregroundColor"
UnselectedColor="_unselectedColor"
TabBarTitleColor="_tabBarTitleColor">
<TitleBar>
<TitleBar HeightRequest="48">
<Content>
<SearchBar VerticalOptions="LayoutOptions.Center"
MaximumWidthRequest="300"
HorizontalOptions="LayoutOptions.Fill"
Placeholder="Search" />
</Content>
</TitleBar>
</TitleBar>

@*Present data*@
<BoxViewPage />
<LabelPage />
<Shapes />
<ChildContent>
<Shell BackgroundColor="_backgroundColor"
ForegroundColor="_foregroundColor"
UnselectedColor="_unselectedColor"
TabBarTitleColor="_tabBarTitleColor">

@*Initiate commands*@
<ButtonPage />
<RefreshViewPage />
<SearchBarPage />
<SwipeViewPage />
@*Present data*@
<BoxViewPage />
<LabelPage />
<Shapes />

@*Set values*@
<SliderPage />
<CheckboxPage />
<SwitchPage />
<RadioButtonPage />
<DatePickerPage />
<TimePickerPage />
@*Initiate commands*@
<ButtonPage />
<RefreshViewPage />
<SearchBarPage />
<SwipeViewPage />

@*Edit text*@
<EntryPage />
<EditorPage />
@*Set values*@
<SliderPage />
<CheckboxPage />
<SwitchPage />
<RadioButtonPage />
<DatePickerPage />
<TimePickerPage />

@*Display collections*@
<CarouselViewPage />
<ShellSection Title="CollectionView">
<AddRemovePage />
<GridLayoutPage />
<SelectionPage />
<InfiniteScrollPage />
<DynamicItemsPage />
</ShellSection>
<PickerPage />
<TableViewPage />
<ListViewPage />
@*Edit text*@
<EntryPage />
<EditorPage />

@*Layouts*@
<AbsoluteLayoutPage />
<GridPage />
<FlexLayoutPage />
@*Display collections*@
<CarouselViewPage />
<ShellSection Title="CollectionView">
<AddRemovePage />
<GridLayoutPage />
<SelectionPage />
<InfiniteScrollPage />
<DynamicItemsPage />
</ShellSection>
<PickerPage />
<TableViewPage />
<ListViewPage />

@*Shell*@
<ShellContent Title="Shell Properties">
<ContentTemplate>
<ShellPropertiesPage @bind-ShellBackgroundColor="_backgroundColor"
@bind-ShellForegroundColor="_foregroundColor"
@bind-ShellUnselectedColor="_unselectedColor"
@bind-ShellTabBarTitleColor="_tabBarTitleColor" />
</ContentTemplate>
</ShellContent>
@*Layouts*@
<AbsoluteLayoutPage />
<GridPage />
<FlexLayoutPage />

<ShellItemsPage />
@*Shell*@
<ShellContent Title="Shell Properties">
<ContentTemplate>
<ShellPropertiesPage @bind-ShellBackgroundColor="_backgroundColor"
@bind-ShellForegroundColor="_foregroundColor"
@bind-ShellUnselectedColor="_unselectedColor"
@bind-ShellTabBarTitleColor="_tabBarTitleColor" />
</ContentTemplate>
</ShellContent>

@*Navigation*@
<ShellSection Title="Navigation">
<NavigationPage />
<UriNavigationPage />
</ShellSection>
<ShellItemsPage />

@*Other*@
<ShadowsPage />
<GestureEvents />
<GestureRecognizersPage />
<ErrorBoundariesPage />
@*Navigation*@
<ShellSection Title="Navigation">
<NavigationPage />
<UriNavigationPage />
</ShellSection>

@if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
{
<ContextMenuPage />
<MenuBarPage />
<WindowsPage />
}
</Shell>
@*Other*@
<ShadowsPage />
<GestureEvents />
<GestureRecognizersPage />
<ErrorBoundariesPage />

@if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
{
<ContextMenuPage />
<MenuBarPage />
<WindowsPage />
}
</Shell>
</ChildContent>
</Window>

@code {
Expand Down
126 changes: 126 additions & 0 deletions src/BlazorBindings.Maui/Elements/TitleBar.generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// <auto-generated>
// This code was generated by a BlazorBindings.Maui component generator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>

using BlazorBindings.Core;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui;
using Microsoft.Maui.Graphics;
using System.Threading.Tasks;

#pragma warning disable MBB001

namespace BlazorBindings.Maui.Elements
{
/// <summary>
/// A <see cref="T:Microsoft.Maui.Controls.View" /> control that provides title bar functionality for a window. <br /><br /> The standard title bar height is 32px, but can be set to a larger value. <br /><br /> The title bar can also be hidden by setting the <see cref="P:Microsoft.Maui.Controls.VisualElement.IsVisible" /> property, which will cause the window content to be displayed in the title bar region.
/// </summary>
public partial class TitleBar : TemplatedView
{
static TitleBar()
{
RegisterAdditionalHandlers();
}

/// <summary>
/// Gets or sets the foreground color of the title bar. This color is used for the title and subtitle text.
/// </summary>
[Parameter] public Color ForegroundColor { get; set; }
/// <summary>
/// Gets or sets an optional icon image of the title bar. Icon images should be 16x16 pixels in size. <br /><br /> Setting this property to an empty value will hide the icon.
/// </summary>
[Parameter] public MC.ImageSource Icon { get; set; }
/// <summary>
/// Gets or sets the subtitle text of the title bar. The subtitle usually specifies the secondary information about the application or window
/// </summary>
[Parameter] public string Subtitle { get; set; }
/// <summary>
/// Gets or sets the title text of the title bar. The title usually specifies the name of the application or indicates the purpose of the window
/// </summary>
[Parameter] public string Title { get; set; }
/// <summary>
/// Gets or sets a <see cref="T:Microsoft.Maui.Controls.View" /> control that represents the content.<br /><br /> This content is centered in the title bar, and is allocated the remaining space between the leading and trailing content.<br /><br /><br /> Views set here will block all input to the title bar region and handle input directly.
/// </summary>
[Parameter] public RenderFragment Content { get; set; }
/// <summary>
/// Gets or sets a <see cref="T:Microsoft.Maui.Controls.View" /> control that represents the leading content.<br /><br /> The leading content follows the optional <see cref="P:Microsoft.Maui.Controls.TitleBar.Icon" /> and is aligned to the left or right of the title bar, depending on the <see cref="T:Microsoft.Maui.FlowDirection" />. Views set here will be allocated as much space as they require. <br /><br /> Views set here will block all input to the title bar region and handle input directly.
/// </summary>
[Parameter] public RenderFragment LeadingContent { get; set; }
[Parameter] public RenderFragment PassthroughElements { get; set; }
/// <summary>
/// Gets or sets a <see cref="T:Microsoft.Maui.Controls.View" /> control that represents the trailing content.<br /><br /> The trailing content is aligned to the right or left of the title bar, depending on the <see cref="T:Microsoft.Maui.FlowDirection" />. Views set here will be allocated as much space as they require. <br /><br /> Views set here will block all input to the title bar region and handle input directly.
/// </summary>
[Parameter] public RenderFragment TrailingContent { get; set; }

public new MC.TitleBar NativeControl => (MC.TitleBar)((BindableObject)this).NativeControl;

protected override MC.TitleBar CreateNativeElement() => new();

protected override void HandleParameter(string name, object value)
{
switch (name)
{
case nameof(ForegroundColor):
if (!Equals(ForegroundColor, value))
{
ForegroundColor = (Color)value;
NativeControl.ForegroundColor = ForegroundColor;
}
break;
case nameof(Icon):
if (!Equals(Icon, value))
{
Icon = (MC.ImageSource)value;
NativeControl.Icon = Icon;
}
break;
case nameof(Subtitle):
if (!Equals(Subtitle, value))
{
Subtitle = (string)value;
NativeControl.Subtitle = Subtitle;
}
break;
case nameof(Title):
if (!Equals(Title, value))
{
Title = (string)value;
NativeControl.Title = Title;
}
break;
case nameof(Content):
Content = (RenderFragment)value;
break;
case nameof(LeadingContent):
LeadingContent = (RenderFragment)value;
break;
case nameof(PassthroughElements):
PassthroughElements = (RenderFragment)value;
break;
case nameof(TrailingContent):
TrailingContent = (RenderFragment)value;
break;

default:
base.HandleParameter(name, value);
break;
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty<MC.TitleBar>(builder, sequence++, Content, (x, value) => x.Content = (IView)value);
RenderTreeBuilderHelper.AddContentProperty<MC.TitleBar>(builder, sequence++, LeadingContent, (x, value) => x.LeadingContent = (IView)value);
RenderTreeBuilderHelper.AddListContentProperty<MC.TitleBar, IView>(builder, sequence++, PassthroughElements, x => x.PassthroughElements);
RenderTreeBuilderHelper.AddContentProperty<MC.TitleBar>(builder, sequence++, TrailingContent, (x, value) => x.TrailingContent = (IView)value);
}

static partial void RegisterAdditionalHandlers();
}
}
5 changes: 5 additions & 0 deletions src/BlazorBindings.Maui/Elements/Window.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static Window()
[Parameter] public double? X { get; set; }
[Parameter] public double? Y { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public RenderFragment TitleBar { get; set; }
[Parameter] public EventCallback OnSizeChanged { get; set; }
[Parameter] public EventCallback<MC.ModalPoppedEventArgs> OnModalPopped { get; set; }
[Parameter] public EventCallback<MC.ModalPoppingEventArgs> OnModalPopping { get; set; }
Expand Down Expand Up @@ -131,6 +132,9 @@ protected override void HandleParameter(string name, object value)
case nameof(ChildContent):
ChildContent = (RenderFragment)value;
break;
case nameof(TitleBar):
TitleBar = (RenderFragment)value;
break;
case nameof(OnSizeChanged):
if (!Equals(OnSizeChanged, value))
{
Expand Down Expand Up @@ -282,6 +286,7 @@ protected override void RenderAdditionalElementContent(RenderTreeBuilder builder
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty<MC.Window>(builder, sequence++, ChildContent, (x, value) => x.Page = (MC.Page)value);
RenderTreeBuilderHelper.AddContentProperty<MC.Window>(builder, sequence++, TitleBar, (x, value) => x.TitleBar = (ITitleBar)value);
}

static partial void RegisterAdditionalHandlers();
Expand Down
1 change: 1 addition & 0 deletions src/BlazorBindings.Maui/Properties/AttributeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
[assembly: GenerateComponent(typeof(TemplatedPage), Exclude = [nameof(TemplatedPage.ControlTemplate)])]
[assembly: GenerateComponent(typeof(TemplatedView))]
[assembly: GenerateComponent(typeof(TimePicker), Exclude = [nameof(TimePicker.Time), nameof(TimePicker.TimeSelected)])]
[assembly: GenerateComponent(typeof(TitleBar))]
[assembly: GenerateComponent(typeof(ToolbarItem))]
[assembly: GenerateComponent(typeof(VerticalStackLayout))]
[assembly: GenerateComponent(typeof(View))]
Expand Down

0 comments on commit dd834af

Please sign in to comment.