feat: add window resizer for Ursa.
This commit is contained in:
31
src/Ursa.Themes.Semi/Controls/Resizer.axaml
Normal file
31
src/Ursa.Themes.Semi/Controls/Resizer.axaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
|
xmlns:iri="https://irihi.tech/shared">
|
||||||
|
<!-- Add Resources Here -->
|
||||||
|
<ControlTheme TargetType="u:WindowResizerThumb" x:Key="{x:Type u:WindowResizerThumb}">
|
||||||
|
<Setter Property="Background" Value="Transparent" />
|
||||||
|
<Setter Property="Template">
|
||||||
|
<ControlTemplate TargetType="u:WindowResizerThumb">
|
||||||
|
<iri:PureRectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{TemplateBinding Background}"/>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter>
|
||||||
|
</ControlTheme>
|
||||||
|
|
||||||
|
<ControlTheme TargetType="u:WindowResizer" x:Key="{x:Type u:WindowResizer}">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<ControlTemplate TargetType="u:WindowResizer">
|
||||||
|
<Grid RowDefinitions="Auto, *, Auto" ColumnDefinitions="Auto, *, Auto" >
|
||||||
|
<u:WindowResizerThumb Grid.Row="0" Grid.Column="0" ResizeDirection="TopLeft" Cursor="TopLeftCorner" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="0" Grid.Column="1" ResizeDirection="Top" Cursor="TopSide" Height="{DynamicResource ResizerThumbHeight}" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="0" Grid.Column="2" ResizeDirection="TopRight" Cursor="TopRightCorner" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="1" Grid.Column="0" ResizeDirection="Left" Cursor="LeftSide" Width="{DynamicResource ResizerThumbWidth}" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="1" Grid.Column="2" ResizeDirection="Right" Cursor="RightSide" Width="{DynamicResource ResizerThumbWidth}" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="2" Grid.Column="0" ResizeDirection="BottomLeft" Cursor="BottomLeftCorner" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="2" Grid.Column="1" ResizeDirection="Bottom" Cursor="BottomSide" Height="{DynamicResource ResizerThumbHeight}" />
|
||||||
|
<u:WindowResizerThumb Grid.Row="2" Grid.Column="2" ResizeDirection="BottomRight" Cursor="BottomRightCorner" />
|
||||||
|
</Grid>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter>
|
||||||
|
</ControlTheme>
|
||||||
|
</ResourceDictionary>
|
||||||
@@ -71,7 +71,13 @@
|
|||||||
LeftContent="{Binding $parent[u:UrsaWindow].LeftContent}"
|
LeftContent="{Binding $parent[u:UrsaWindow].LeftContent}"
|
||||||
RightContent="{Binding $parent[u:UrsaWindow].RightContent}" />
|
RightContent="{Binding $parent[u:UrsaWindow].RightContent}" />
|
||||||
<VisualLayerManager>
|
<VisualLayerManager>
|
||||||
<u:OverlayDialogHost IsTopLevel="True" IsModalStatusReporter="True" />
|
<Panel>
|
||||||
|
<u:OverlayDialogHost IsModalStatusReporter="True" IsTopLevel="True" />
|
||||||
|
<u:WindowResizer
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
IsVisible="{Binding $parent[u:UrsaWindow].IsManagedResizerVisible}" />
|
||||||
|
</Panel>
|
||||||
</VisualLayerManager>
|
</VisualLayerManager>
|
||||||
</VisualLayerManager.ChromeOverlayLayer>
|
</VisualLayerManager.ChromeOverlayLayer>
|
||||||
<Panel>
|
<Panel>
|
||||||
@@ -82,6 +88,7 @@
|
|||||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
Content="{TemplateBinding Content}"
|
Content="{TemplateBinding Content}"
|
||||||
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
||||||
|
|
||||||
</Panel>
|
</Panel>
|
||||||
</VisualLayerManager>
|
</VisualLayerManager>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
<ResourceInclude Source="Pagination.axaml" />
|
<ResourceInclude Source="Pagination.axaml" />
|
||||||
<ResourceInclude Source="RangeSlider.axaml" />
|
<ResourceInclude Source="RangeSlider.axaml" />
|
||||||
<ResourceInclude Source="Rating.axaml" />
|
<ResourceInclude Source="Rating.axaml" />
|
||||||
|
<ResourceInclude Source="Resizer.axaml" />
|
||||||
<ResourceInclude Source="ScrollToButton.axaml" />
|
<ResourceInclude Source="ScrollToButton.axaml" />
|
||||||
<ResourceInclude Source="SelectionList.axaml" />
|
<ResourceInclude Source="SelectionList.axaml" />
|
||||||
<ResourceInclude Source="TagInput.axaml" />
|
<ResourceInclude Source="TagInput.axaml" />
|
||||||
|
|||||||
6
src/Ursa.Themes.Semi/Themes/Shared/Resizer.axaml
Normal file
6
src/Ursa.Themes.Semi/Themes/Shared/Resizer.axaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
|
<!-- Add Resources Here -->
|
||||||
|
<x:Double x:Key="ResizerThumbWidth">6</x:Double>
|
||||||
|
<x:Double x:Key="ResizerThumbHeight">6</x:Double>
|
||||||
|
</ResourceDictionary>
|
||||||
@@ -1,29 +1,30 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<MergeResourceInclude Source="Avatar.axaml" />
|
<ResourceInclude Source="Avatar.axaml" />
|
||||||
<MergeResourceInclude Source="Badge.axaml" />
|
<ResourceInclude Source="Badge.axaml" />
|
||||||
<MergeResourceInclude Source="Banner.axaml" />
|
<ResourceInclude Source="Banner.axaml" />
|
||||||
<MergeResourceInclude Source="ButtonGroup.axaml" />
|
<ResourceInclude Source="ButtonGroup.axaml" />
|
||||||
<MergeResourceInclude Source="DatePicker.axaml" />
|
<ResourceInclude Source="DatePicker.axaml" />
|
||||||
<MergeResourceInclude Source="DateTimePicker.axaml" />
|
<ResourceInclude Source="DateTimePicker.axaml" />
|
||||||
<MergeResourceInclude Source="Dialog.axaml" />
|
<ResourceInclude Source="Dialog.axaml" />
|
||||||
<MergeResourceInclude Source="DialogShared.axaml" />
|
<ResourceInclude Source="DialogShared.axaml" />
|
||||||
<MergeResourceInclude Source="Divider.axaml" />
|
<ResourceInclude Source="Divider.axaml" />
|
||||||
<MergeResourceInclude Source="Drawer.axaml" />
|
<ResourceInclude Source="Drawer.axaml" />
|
||||||
<MergeResourceInclude Source="DualBadge.axaml" />
|
<ResourceInclude Source="DualBadge.axaml" />
|
||||||
<MergeResourceInclude Source="IPv4Box.axaml" />
|
<ResourceInclude Source="IPv4Box.axaml" />
|
||||||
<MergeResourceInclude Source="KeyGestureInput.axaml" />
|
<ResourceInclude Source="KeyGestureInput.axaml" />
|
||||||
<MergeResourceInclude Source="MessageBox.axaml" />
|
<ResourceInclude Source="MessageBox.axaml" />
|
||||||
<MergeResourceInclude Source="NavigationMenu.axaml" />
|
<ResourceInclude Source="NavigationMenu.axaml" />
|
||||||
<MergeResourceInclude Source="Notification.axaml" />
|
<ResourceInclude Source="Notification.axaml" />
|
||||||
<MergeResourceInclude Source="Pagination.axaml" />
|
<ResourceInclude Source="Pagination.axaml" />
|
||||||
<MergeResourceInclude Source="Rating.axaml" />
|
<ResourceInclude Source="Rating.axaml" />
|
||||||
<MergeResourceInclude Source="ScrollToButton.axaml" />
|
<ResourceInclude Source="Resizer.axaml"/>
|
||||||
<MergeResourceInclude Source="TagInput.axaml" />
|
<ResourceInclude Source="ScrollToButton.axaml" />
|
||||||
<MergeResourceInclude Source="Skeleton.axaml" />
|
<ResourceInclude Source="TagInput.axaml" />
|
||||||
<MergeResourceInclude Source="ThemeSelector.axaml" />
|
<ResourceInclude Source="Skeleton.axaml" />
|
||||||
<MergeResourceInclude Source="Toast.axaml" />
|
<ResourceInclude Source="ThemeSelector.axaml" />
|
||||||
<MergeResourceInclude Source="ToolBar.axaml" />
|
<ResourceInclude Source="Toast.axaml" />
|
||||||
<MergeResourceInclude Source="TimeBox.axaml" />
|
<ResourceInclude Source="ToolBar.axaml" />
|
||||||
|
<ResourceInclude Source="TimeBox.axaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
13
src/Ursa/Controls/Resizers/ResizeDirection.cs
Normal file
13
src/Ursa/Controls/Resizers/ResizeDirection.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public enum ResizeDirection
|
||||||
|
{
|
||||||
|
Top,
|
||||||
|
Bottom,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
TopLeft,
|
||||||
|
TopRight,
|
||||||
|
BottomLeft,
|
||||||
|
BottomRight,
|
||||||
|
}
|
||||||
8
src/Ursa/Controls/Resizers/WindowResizer.cs
Normal file
8
src/Ursa/Controls/Resizers/WindowResizer.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Avalonia.Controls.Primitives;
|
||||||
|
|
||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public class WindowResizer : TemplatedControl
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
45
src/Ursa/Controls/Resizers/WindowResizerThumb.cs
Normal file
45
src/Ursa/Controls/Resizers/WindowResizerThumb.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Primitives;
|
||||||
|
using Avalonia.Input;
|
||||||
|
|
||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public class WindowResizerThumb: Thumb
|
||||||
|
{
|
||||||
|
private Window? _window;
|
||||||
|
|
||||||
|
public static readonly StyledProperty<ResizeDirection> ResizeDirectionProperty = AvaloniaProperty.Register<WindowResizerThumb, ResizeDirection>(
|
||||||
|
nameof(ResizeDirection));
|
||||||
|
|
||||||
|
public ResizeDirection ResizeDirection
|
||||||
|
{
|
||||||
|
get => GetValue(ResizeDirectionProperty);
|
||||||
|
set => SetValue(ResizeDirectionProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate(e);
|
||||||
|
_window = TopLevel.GetTopLevel(this) as Window;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnPointerPressed(e);
|
||||||
|
if (_window is null || !_window.CanResize) return;
|
||||||
|
var windowEdge = ResizeDirection switch
|
||||||
|
{
|
||||||
|
ResizeDirection.Top => WindowEdge.North,
|
||||||
|
ResizeDirection.TopRight => WindowEdge.NorthEast,
|
||||||
|
ResizeDirection.Right => WindowEdge.East,
|
||||||
|
ResizeDirection.BottomRight => WindowEdge.SouthEast,
|
||||||
|
ResizeDirection.Bottom => WindowEdge.South,
|
||||||
|
ResizeDirection.BottomLeft => WindowEdge.SouthWest,
|
||||||
|
ResizeDirection.Left => WindowEdge.West,
|
||||||
|
ResizeDirection.TopLeft => WindowEdge.NorthWest,
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
};
|
||||||
|
_window.BeginResizeDrag(windowEdge, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,15 @@ public class UrsaWindow: Window
|
|||||||
get => GetValue(IsTitleBarVisibleProperty);
|
get => GetValue(IsTitleBarVisibleProperty);
|
||||||
set => SetValue(IsTitleBarVisibleProperty, value);
|
set => SetValue(IsTitleBarVisibleProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<bool> IsManagedResizerVisibleProperty = AvaloniaProperty.Register<UrsaWindow, bool>(
|
||||||
|
nameof(IsManagedResizerVisible));
|
||||||
|
|
||||||
|
public bool IsManagedResizerVisible
|
||||||
|
{
|
||||||
|
get => GetValue(IsManagedResizerVisibleProperty);
|
||||||
|
set => SetValue(IsManagedResizerVisibleProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<object?> TitleBarContentProperty = AvaloniaProperty.Register<UrsaWindow, object?>(
|
public static readonly StyledProperty<object?> TitleBarContentProperty = AvaloniaProperty.Register<UrsaWindow, object?>(
|
||||||
nameof(TitleBarContent));
|
nameof(TitleBarContent));
|
||||||
|
|||||||
Reference in New Issue
Block a user