Skip to content

Commit

Permalink
Merge pull request #200 from AuroraZiling/ui
Browse files Browse the repository at this point in the history
[Feat] Customize `OpenPaneLength` and `TogglePaneButton` Position
  • Loading branch information
kikipoulet authored May 25, 2024
2 parents 6775ed3 + 0303793 commit cf80f3d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ body:
options:
- label: I have looked up relevant Issue
required: false
- label: I've read [How To Ask Questions](https://github.com/betaseeker/How-To-Ask-Questions)
required: false
- type: textarea
id: description
attributes:
Expand Down
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ body:
options:
- label: I have looked up relevant Issue
required: false
- label: I've read [How To Ask Questions](https://github.com/betaseeker/How-To-Ask-Questions)
required: false
- type: textarea
id: description
attributes:
Expand Down
5 changes: 2 additions & 3 deletions SukiUI/Controls/SukiSideMenu.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:content="clr-namespace:SukiUI.Content"
xmlns:suki="clr-namespace:SukiUI.Controls"
xmlns:sukiUi="clr-namespace:SukiUI"
xmlns:theme="clr-namespace:SukiUI.Theme">
<ControlTheme x:Key="SukiSideMenuStyle" TargetType="suki:SukiSideMenu">
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="Template">
<ControlTemplate>
<SplitView DisplayMode="CompactInline"
IsPaneOpen="{TemplateBinding IsMenuExpanded}"
OpenPaneLength="220">
OpenPaneLength="{TemplateBinding OpenPaneLength}">
<SplitView.Pane>
<Border>
<Grid Background="Transparent">
Expand All @@ -20,7 +19,7 @@
<DockPanel>
<Button Name="PART_SidebarToggleButton"
Margin="7"
HorizontalAlignment="Right"
HorizontalAlignment="{TemplateBinding TogglePaneButtonPosition}"
VerticalAlignment="Top"
Classes="Basic"
DockPanel.Dock="Top">
Expand Down
48 changes: 40 additions & 8 deletions SukiUI/Controls/SukiSideMenu.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Threading;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using Avalonia.Layout;
using SukiUI.Enums;

namespace SukiUI.Controls;

Expand All @@ -23,6 +23,38 @@ public bool IsMenuExpanded
get => GetValue(IsMenuExpandedProperty);
set => SetValue(IsMenuExpandedProperty, value);
}

public static readonly StyledProperty<int> OpenPaneLengthProperty =
AvaloniaProperty.Register<SukiSideMenu, int>(nameof(OpenPaneLength), defaultValue: 220);

public int OpenPaneLength
{
get => GetValue(OpenPaneLengthProperty);
set => SetValue(OpenPaneLengthProperty, value switch
{
>= 200 => value,
_ => throw new ArgumentOutOfRangeException($"OpenPaneLength must be greater than or equal to 200, but was {value}")
});
}

public static readonly StyledProperty<HorizontalAlignment> TogglePaneButtonPositionProperty =
AvaloniaProperty.Register<SukiSideMenu, HorizontalAlignment>(nameof(TogglePaneButtonPosition), defaultValue: HorizontalAlignment.Right);

public SideMenuTogglePaneButtonPositionOptions TogglePaneButtonPosition
{
get => GetValue(TogglePaneButtonPositionProperty) switch
{
HorizontalAlignment.Right => SideMenuTogglePaneButtonPositionOptions.Right,
HorizontalAlignment.Left => SideMenuTogglePaneButtonPositionOptions.Left,
_ => SideMenuTogglePaneButtonPositionOptions.Right
};
set => SetValue(TogglePaneButtonPositionProperty, value switch
{
SideMenuTogglePaneButtonPositionOptions.Right => HorizontalAlignment.Right,
SideMenuTogglePaneButtonPositionOptions.Left => HorizontalAlignment.Left,
_ => HorizontalAlignment.Right
});
}

public static readonly StyledProperty<bool> IsSelectedItemContentMovableProperty =
AvaloniaProperty.Register<SukiSideMenu, bool>(nameof(IsSelectedItemContentMovable), defaultValue: true);
Expand Down Expand Up @@ -75,13 +107,13 @@ private void MenuExpandedClicked()
{
IsMenuExpanded = !IsMenuExpanded;

if(_SideMenuItems.Any())
foreach (SukiSideMenuItem item in _SideMenuItems)
if(_sideMenuItems.Any())
foreach (var item in _sideMenuItems)
item.IsTopMenuExpanded = IsMenuExpanded;

else if(Items.FirstOrDefault() is SukiSideMenuItem)
foreach (SukiSideMenuItem item in Items)
item.IsTopMenuExpanded = IsMenuExpanded;
foreach (SukiSideMenuItem? item in Items)
item!.IsTopMenuExpanded = IsMenuExpanded;
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Expand Down Expand Up @@ -139,11 +171,11 @@ protected override Control CreateContainerForItemOverride(object? item, int inde
? sukiMenuItem
: new SukiSideMenuItem();
menuItem.IsContentMovable = IsSelectedItemContentMovable;
_SideMenuItems.Add(menuItem);
_sideMenuItems.Add(menuItem);
return menuItem;
}

private List<SukiSideMenuItem> _SideMenuItems = new List<SukiSideMenuItem>();
private List<SukiSideMenuItem> _sideMenuItems = new();

protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
Expand Down
7 changes: 7 additions & 0 deletions SukiUI/Enums/SideMenuTogglePaneButtonPositionOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SukiUI.Enums;

public enum SideMenuTogglePaneButtonPositionOptions
{
Left,
Right
}

0 comments on commit cf80f3d

Please sign in to comment.