Skip to content

Commit

Permalink
Merge pull request #27 from ItsTheSky/features/better-sidebar
Browse files Browse the repository at this point in the history
Better sidebar management
  • Loading branch information
ItsTheSky authored Jan 26, 2024
2 parents 733541c + 9f74dac commit fe884e0
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 31 deletions.
1 change: 1 addition & 0 deletions SkEditor/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Application.Styles>
<sty:FluentAvaloniaTheme />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<StyleInclude Source="/Styles/ButtonStyles.axaml"></StyleInclude>
</Application.Styles>

<Application.Resources>
Expand Down
26 changes: 3 additions & 23 deletions SkEditor/Controls/SideBarControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,11 @@
</Style>
</UserControl.Styles>

<Grid ColumnDefinitions="auto,auto" RowDefinitions="*">
<Grid Name="GridPanels" ColumnDefinitions="auto,auto" RowDefinitions="*">
<Border Grid.Column="0" Width="36" Background="{DynamicResource SkEditorBorderBackground}" CornerRadius="7">
<StackPanel Spacing="10" HorizontalAlignment="Center">
<Button Name="ProjectsButton" Height="36" Width="36" Classes="barButton">
<Button.Content>
<ui:SymbolIcon Symbol="Folder" FontSize="24" Foreground="#bfffffff" />
</Button.Content>
</Button>
<StackPanel Name="Buttons" Spacing="10" HorizontalAlignment="Center">

</StackPanel>
</Border>

<Border Name="ExtendedSideBar" Grid.Column="1" Width="0" Background="{DynamicResource SkEditorBorderBackground}" CornerRadius="7" Margin="10,0,0,0">
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Width" Duration="0:0:0.05" Easing="QuadraticEaseIn"/>
</Transitions>
</Border.Transitions>

<Grid RowDefinitions="auto,auto,*">
<TextBlock Grid.Row="0" Text="Explorer" FontWeight="DemiBold" Margin="20,10,20,10"/>
<Separator Grid.Row="1" Margin="0,0,0,10"/>
<TreeView Grid.Row="2" Name="FileTreeView">

</TreeView>
</Grid>
</Border>
</Grid>
</UserControl>
85 changes: 78 additions & 7 deletions SkEditor/Controls/SideBarControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,94 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Media;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using SkEditor.Controls.Sidebar;
using SkEditor.Utilities;

namespace SkEditor.Controls;
public partial class SideBarControl : UserControl
{
private static readonly List<SidebarPanel> Panels = new();

public readonly ExplorerSidebarPanel.ExplorerPanel ProjectPanel = new();

public static void RegisterPanel(SidebarPanel panel)
{
Panels.Add(panel);
}

private SidebarPanel? _currentPanel;
public SideBarControl()
{
InitializeComponent();

RegisterPanel(ProjectPanel);
}

AssignCommands();
public void LoadPanels()
{
foreach (SidebarPanel panel in Panels)
{
var btn = CreatePanelButton(panel);
var content = panel.Content;
content.Width = 0;

btn.Command = new RelayCommand(() =>
{
if (_currentPanel == panel)
{
_currentPanel.Content.Width = 0; // Close current panel
_currentPanel.OnClose();
_currentPanel = null;
return;
}
if (panel.IsDisabled)
return;
if (_currentPanel != null)
{
_currentPanel.OnClose();
_currentPanel.Content.Width = 0; // Close current panel
_currentPanel = null;
}
_currentPanel = panel;
_currentPanel.Content.Width = 250;
_currentPanel.OnOpen();
});

GridPanels.Children.Add(content);
Grid.SetColumn(content, 1);

Buttons.Children.Add(btn);
}
}

private void AssignCommands()
private Button CreatePanelButton(SidebarPanel panel)
{
ProjectsButton.Command = new RelayCommand(() =>
var icon = panel.Icon;
if (icon is SymbolIconSource symbolIcon) symbolIcon.FontSize = 24;
IconSourceElement iconElement = new()
{
IconSource = icon,
Width = 24,
Height = 24,
Foreground = new SolidColorBrush(Color.Parse("#bfffffff")),
};

Button button = new()
{
ScrollViewer.SetHorizontalScrollBarVisibility(FileTreeView, Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled);
ScrollViewer.SetVerticalScrollBarVisibility(FileTreeView, Avalonia.Controls.Primitives.ScrollBarVisibility.Auto);
ExtendedSideBar.Width = ExtendedSideBar.Width == 0 ? 250 : 0;
});
Height = 36,
Width = 36,
Classes = { "barButton" },
Content = iconElement,
IsEnabled = !panel.IsDisabled,
};

return button;
}
}
37 changes: 37 additions & 0 deletions SkEditor/Controls/Sidebar/ExplorerSidebarPanel.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<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:ui="using:FluentAvalonia.UI.Controls"
x:Class="SkEditor.Controls.Sidebar.ExplorerSidebarPanel">

<UserControl.Styles>
<Style Selector="Button.barButton">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
<Style Selector="Separator">
<Setter Property="Margin" Value="0,1"/>
</Style>
<Style Selector="TreeViewItem">
<Setter Property="FontWeight" Value="Regular"/>
</Style>
</UserControl.Styles>

<Border Name="ExtendedSideBar" Background="{DynamicResource SkEditorBorderBackground}" CornerRadius="7" Margin="10,0,0,0">
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Width" Duration="0:0:0.05" Easing="QuadraticEaseIn"/>
</Transitions>
</Border.Transitions>

<Grid RowDefinitions="auto,auto,*">
<TextBlock Grid.Row="0" Text="Explorer" FontWeight="DemiBold" Margin="20,10,20,10"/>
<Separator Grid.Row="1" Margin="0,0,0,10"/>
<TreeView Grid.Row="2" Name="FileTreeView">

</TreeView>
</Grid>
</Border>
</UserControl>
24 changes: 24 additions & 0 deletions SkEditor/Controls/Sidebar/ExplorerSidebarPanel.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using FluentAvalonia.UI.Controls;
using SkEditor.Utilities;

namespace SkEditor.Controls.Sidebar;

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

public class ExplorerPanel : SidebarPanel
{
public override UserControl Content => Panel;
public override IconSource Icon => new SymbolIconSource() { Symbol = Symbol.Folder };
public override bool IsDisabled => false;

public readonly ExplorerSidebarPanel Panel = new ();
}
}
4 changes: 4 additions & 0 deletions SkEditor/SkEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
<Compile Update="Views\Settings\Personalization\ThemePage.axaml.cs">
<DependentUpon>ThemePage.axaml</DependentUpon>
</Compile>
<Compile Update="Controls\Sidebar\CodeParser\ParserSidebarPanel.axaml.cs">
<DependentUpon>ParserSidebarPanel.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
178 changes: 178 additions & 0 deletions SkEditor/Styles/ButtonStyles.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia">
<Design.PreviewWith>
<Border Padding="20">
<StackPanel>
<Button Classes="success" Content="Success Button" Margin="8" HorizontalAlignment="Center" />
<Button Classes="accent" Content="FA Accent Button" Margin="8" HorizontalAlignment="Center" />
<Button Classes="danger" Content="Danger Button" Margin="8" HorizontalAlignment="Center" />
<Button Classes="info" Content="Info Button" Margin="8" HorizontalAlignment="Center" />
<Button Content="Disabled Button" Margin="8" IsEnabled="False" HorizontalAlignment="Center" />
</StackPanel>
</Border>
</Design.PreviewWith>

<Style Selector="Button.success">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeGreenColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeGreenColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
</Style>

<Style Selector="^:pointerover">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeDarkGreenColor}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeDarkGreenColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPointerOver}" />
</Style>
</Style>

<Style Selector="^:pressed">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeDarkDarkGreenColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeDarkDarkGreenColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPressed}" />
</Style>
</Style>

<Style Selector="^:disabled">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundDisabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushDisabled}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundDisabled}" />
</Style>
</Style>
</Style>

<!-- Danger -->
<Style Selector="Button.danger">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeRedColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeRedColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
</Style>

<Style Selector="^:pointerover">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeDarkRedColor}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeDarkRedColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPointerOver}" />
</Style>
</Style>

<Style Selector="^:pressed">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeDarkDarkRedColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeDarkDarkRedColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPressed}" />
</Style>
</Style>

<Style Selector="^:disabled">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundDisabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushDisabled}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundDisabled}" />
</Style>
</Style>
</Style>

<!-- Info -->
<Style Selector="Button.info">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeLightBlueColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeLightBlueColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
</Style>

<Style Selector="^:pointerover">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeBlueColor}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBlueColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPointerOver}" />
</Style>
</Style>

<Style Selector="^:pressed">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ThemeDarkBlueColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeDarkBlueColor}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPressed}" />
</Style>
</Style>

<Style Selector="^:disabled">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundDisabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushDisabled}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundDisabled}" />
</Style>
</Style>
</Style>

<!--Accent Button-->
<Style Selector="Button.accent">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource AccentButtonBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrush}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource AccentButtonForeground}" />
</Style>

<Style Selector="^:pointerover">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource AccentButtonBackgroundPointerOver}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrushPointerOver}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource AccentButtonForegroundPointerOver}" />
</Style>
</Style>

<Style Selector="^:pressed">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource AccentButtonBackgroundPressed}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrushPressed}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource AccentButtonForegroundPressed}" />
</Style>
</Style>

<Style Selector="^:disabled">
<Style Selector="^ /template/ ui|FABorder#Root">
<Setter Property="Background" Value="{DynamicResource AccentButtonBackgroundDisabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource AccentButtonBorderBrushDisabled}" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource AccentButtonForegroundDisabled}" />
</Style>
</Style>
</Style>
</Styles>
Loading

0 comments on commit fe884e0

Please sign in to comment.