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

Ursa view #349

Merged
merged 7 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/Ursa.Demo/App.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Application
x:Class="Ursa.Demo.App"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u-semi="https://irihi.tech/ursa/themes/semi"
xmlns:semi="https://irihi.tech/semi">
<Application.Styles>
Expand Down
1 change: 1 addition & 0 deletions demo/Ursa.Demo/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Ursa.Demo.ViewModels;
Expand Down
4 changes: 1 addition & 3 deletions demo/Ursa.Demo/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
Icon="/Assets/Ursa.ico"
mc:Ignorable="d">
<u:UrsaWindow.RightContent>
<u:ThemeToggleButton
IsThreeState="True"
Mode="Controller" />
<views:TitleBarRightContent/>
</u:UrsaWindow.RightContent>
<views:MainView />
</u:UrsaWindow>
12 changes: 6 additions & 6 deletions demo/Ursa.Demo/Views/SingleView.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl xmlns="https://github.com/avaloniaui"
<u:UrsaView xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -7,8 +7,8 @@
mc:Ignorable="d" d:DesignWidth="800"
d:DesignHeight="450"
x:Class="Ursa.Demo.Views.SingleView">
<Panel>
<views:MainView/>
<u:OverlayDialogHost/>
</Panel>
</UserControl>
<u:UrsaView.RightContent>
<views:TitleBarRightContent/>
</u:UrsaView.RightContent>
<views:MainView/>
</u:UrsaView>
3 changes: 2 additions & 1 deletion demo/Ursa.Demo/Views/SingleView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Avalonia.Controls;
using Ursa.Controls;

namespace Ursa.Demo.Views;

public partial class SingleView : UserControl
public partial class SingleView : UrsaView
{
public SingleView()
{
Expand Down
20 changes: 20 additions & 0 deletions demo/Ursa.Demo/Views/TitleBarRightContent.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:u="https://irihi.tech/ursa"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Ursa.Demo.Views.TitleBarRightContent">
<StackPanel Orientation="Horizontal">
<Button Theme="{DynamicResource BorderlessButton}" Click="OpenRepository">
<PathIcon
Width="16"
Height="16"
Data="M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z"
Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
</Button>
<u:ThemeToggleButton
IsThreeState="True"
Mode="Controller" />
</StackPanel>
</UserControl>
23 changes: 23 additions & 0 deletions demo/Ursa.Demo/Views/TitleBarRightContent.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;

namespace Ursa.Demo.Views;

public partial class TitleBarRightContent : UserControl
{
public TitleBarRightContent()
{
InitializeComponent();
}

private async void OpenRepository(object? sender, RoutedEventArgs e)
{
var top = TopLevel.GetTopLevel(this);
if (top is null) return;
var launcher = top.Launcher;
await launcher.LaunchUriAsync(new Uri("https://github.com/irihitech/Semi.Avalonia"));
rabbitism marked this conversation as resolved.
Show resolved Hide resolved
}
}
50 changes: 50 additions & 0 deletions src/Ursa.Themes.Semi/Controls/UrsaView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:UrsaView}" TargetType="{x:Type u:UrsaView}">
<Setter Property="Background" Value="{DynamicResource WindowDefaultBackground}" />
<Setter Property="Foreground" Value="{DynamicResource WindowDefaultForeground}" />
<Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" />
<Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" />
<Setter Property="u:OverlayDialogHost.IsModalStatusScope" Value="True" />
<Setter Property="Template">
<ControlTemplate TargetType="u:UrsaView">
<Panel>
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
<Panel>
<ContentPresenter
Name="PART_ContentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
<Grid
Margin="{Binding $parent[u:UrsaWindow].TitleBarMargin}"
VerticalAlignment="Top"
ColumnDefinitions="Auto, *, Auto">
<ContentPresenter
Grid.Column="0"
VerticalAlignment="Center"
IsVisible="{TemplateBinding IsTitleBarVisible}"
Content="{TemplateBinding LeftContent}" />
<ContentPresenter
Grid.Column="1"
VerticalAlignment="Center"
IsVisible="{TemplateBinding IsTitleBarVisible}"
Content="{TemplateBinding TitleBarContent}" />
<ContentPresenter
Grid.Column="2"
VerticalAlignment="Center"
IsVisible="{TemplateBinding IsTitleBarVisible}"
Content="{TemplateBinding RightContent}" />
</Grid>
<u:OverlayDialogHost IsModalStatusReporter="True" />
</Panel>
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
4 changes: 4 additions & 0 deletions src/Ursa.Themes.Semi/Controls/UrsaWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<VisualLayerManager Padding="{TemplateBinding OffScreenMargin, Mode=OneWay}">
<VisualLayerManager.ChromeOverlayLayer>
<u:TitleBar
IsTitleVisible="{TemplateBinding IsTitleBarVisible}"
Content="{Binding $parent[u:UrsaWindow].TitleBarContent}"
Margin="{Binding $parent[u:UrsaWindow].TitleBarMargin}"
LeftContent="{Binding $parent[u:UrsaWindow].LeftContent}"
Expand Down Expand Up @@ -97,14 +98,17 @@
<ContentPresenter
Grid.Column="0"
VerticalAlignment="Center"
IsVisible="{TemplateBinding IsTitleVisible}"
Content="{TemplateBinding LeftContent}" />
<ContentPresenter
Grid.Column="1"
VerticalAlignment="Center"
IsVisible="{TemplateBinding IsTitleVisible}"
Content="{TemplateBinding Content}" />
<ContentPresenter
Grid.Column="2"
VerticalAlignment="Center"
IsVisible="{TemplateBinding IsTitleVisible}"
Content="{TemplateBinding RightContent}" />
<u:CaptionButtons
x:Name="PART_CaptionButtons"
Expand Down
1 change: 1 addition & 0 deletions src/Ursa.Themes.Semi/Controls/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<ResourceInclude Source="TwoTonePathIcon.axaml" />
<ResourceInclude Source="ToolBar.axaml" />
<ResourceInclude Source="TimeBox.axaml"/>
<ResourceInclude Source="UrsaView.axaml" />
<ResourceInclude Source="UrsaWindow.axaml"/>
<ResourceInclude Source="PinCode.axaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down
14 changes: 14 additions & 0 deletions src/Ursa.Themes.Semi/Styles/UrsaView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<Design.PreviewWith>
<Border Padding="20">
<!-- Add Controls for Previewer Here -->
</Border>
</Design.PreviewWith>

<!-- Add Styles Here -->
<Style Selector=":is(u|UrsaView)">
<Setter Property="Theme" Value="{DynamicResource {x:Type u:UrsaView}}"/>
</Style>
</Styles>
1 change: 1 addition & 0 deletions src/Ursa.Themes.Semi/Styles/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<StyleInclude Source="Skeleton.axaml" />
<StyleInclude Source="ToolBar.axaml"/>
<StyleInclude Source="TimeBox.axaml"/>
<StyleInclude Source="UrsaView.axaml" />
<!-- Add Styles Here -->
</Styles>
9 changes: 9 additions & 0 deletions src/Ursa/Controls/TitleBar/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public object? RightContent
get => GetValue(RightContentProperty);
set => SetValue(RightContentProperty, value);
}

public static readonly StyledProperty<bool> IsTitleVisibleProperty = AvaloniaProperty.Register<TitleBar, bool>(
nameof(IsTitleVisible));

public bool IsTitleVisible
{
get => GetValue(IsTitleVisibleProperty);
set => SetValue(IsTitleVisibleProperty, value);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
Expand Down
55 changes: 55 additions & 0 deletions src/Ursa/Windows/UrsaView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Avalonia;
using Avalonia.Controls;

namespace Ursa.Controls;

/// <summary>
/// Ursa window is designed to
/// </summary>
public class UrsaView: ContentControl
{
public static readonly StyledProperty<bool> IsTitleBarVisibleProperty =
UrsaWindow.IsTitleBarVisibleProperty.AddOwner<UrsaView>();

public bool IsTitleBarVisible
{
get => GetValue(IsTitleBarVisibleProperty);
set => SetValue(IsTitleBarVisibleProperty, value);
}

public static readonly StyledProperty<object?> LeftContentProperty =
UrsaWindow.LeftContentProperty.AddOwner<UrsaView>();

public object? LeftContent
{
get => GetValue(LeftContentProperty);
set => SetValue(LeftContentProperty, value);
}

public static readonly StyledProperty<object?> RightContentProperty =
UrsaWindow.RightContentProperty.AddOwner<UrsaView>();

public object? RightContent
{
get => GetValue(RightContentProperty);
set => SetValue(RightContentProperty, value);
}

public static readonly StyledProperty<object?> TitleBarContentProperty =
UrsaWindow.TitleBarContentProperty.AddOwner<UrsaView>();

public object? TitleBarContent
{
get => GetValue(TitleBarContentProperty);
set => SetValue(TitleBarContentProperty, value);
}

public static readonly StyledProperty<Thickness> TitleBarMarginProperty =
UrsaWindow.TitleBarMarginProperty.AddOwner<UrsaView>();

public Thickness TitleBarMargin
{
get => GetValue(TitleBarMarginProperty);
set => SetValue(TitleBarMarginProperty, value);
}
}
2 changes: 1 addition & 1 deletion src/Ursa/Windows/UrsaWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool IsCloseButtonVisible
}

public static readonly StyledProperty<bool> IsTitleBarVisibleProperty = AvaloniaProperty.Register<UrsaWindow, bool>(
nameof(IsTitleBarVisible));
nameof(IsTitleBarVisible), true);

public bool IsTitleBarVisible
{
Expand Down