Skip to content

Commit

Permalink
Creating Playground page
Browse files Browse the repository at this point in the history
  • Loading branch information
kikipoulet committed Feb 6, 2024
1 parent e20a4fe commit 8485a0a
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 1 deletion.
11 changes: 10 additions & 1 deletion SukiUI.Demo/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
<Application.DataTemplates>
<common:ViewLocator />
</Application.DataTemplates>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="Styles/CompletionWindowStyles.axaml"></ResourceInclude>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<Application.Styles>
<FluentTheme />
<FluentTheme></FluentTheme>
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
<sukiUi:SukiTheme ThemeColor="Red" />
<StyleInclude Source="avares://SukiUI.Demo/Styles/ShowMeTheXamlStyles.axaml" />
<StyleInclude Source="avares://SukiUI.Demo/Styles/WrapPanelStyles.axaml" />
<StyleInclude Source="avares://SukiUI.Demo/Styles/TextStyles.axaml" />
<StyleInclude Source="avares://SukiUI.Demo/Styles/GlassCardStyles.axaml" />
<avalonia:MaterialIconStyles />
</Application.Styles>

</Application>
23 changes: 23 additions & 0 deletions SukiUI.Demo/Features/Playground/PlaygroundView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit"
xmlns:controls="clr-namespace:SukiUI.Controls;assembly=SukiUI"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SukiUI.Demo.Features.Playground.PlaygroundView">
<controls:SukiStackPage>
<controls:SukiStackPage.Content>
<Grid Name="Playground" ColumnDefinitions="*, 4, *">
<controls:GlassCard Margin="20">
<avaloniaEdit:TextEditor TextChanged="Editor_OnTextChanged" Text="" Name="Editor"
ShowLineNumbers="True"
/>
</controls:GlassCard>
<GridSplitter Grid.Column="1" Background="Transparent" ResizeDirection="Columns"/>
<controls:GlassCard Name="GlassExample" Grid.Column="2" Margin="20">
</controls:GlassCard>
</Grid>
</controls:SukiStackPage.Content>
</controls:SukiStackPage>
</UserControl>
162 changes: 162 additions & 0 deletions SukiUI.Demo/Features/Playground/PlaygroundView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Styling;
using AvaloniaEdit;
using AvaloniaEdit.TextMate;
using AvaloniaEdit.CodeCompletion;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Indentation.CSharp;
using SukiUI.Controls;
using TextMateSharp.Grammars;

namespace SukiUI.Demo.Features.Playground
{
public partial class PlaygroundView : UserControl
{
private CompletionWindow _completionWindow;

private TextEditor _textEditor;
private GlassCard _glassPlayground;

public PlaygroundView()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);

_textEditor = this.FindControl<TextEditor>("Editor");
_glassPlayground = this.FindControl<GlassCard>("GlassExample");
_textEditor.TextArea.TextEntered += textEditor_TextArea_TextEntered;
_textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering;
_textEditor.Text = StartingString;
_textEditor.TextArea.IndentationStrategy = new CSharpIndentationStrategy(_textEditor.Options);

OnBaseThemeChanged(Application.Current.ActualThemeVariant);
SukiTheme.GetInstance().OnBaseThemeChanged += OnBaseThemeChanged;

}

private void OnBaseThemeChanged(ThemeVariant CurrentTheme)
{
var _registryOptions = new RegistryOptions( CurrentTheme == ThemeVariant.Dark ? ThemeName.DarkPlus : ThemeName.LightPlus);

var _textMateInstallation = _textEditor.InstallTextMate(_registryOptions);
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".xaml").Id));

}


private void textEditor_TextArea_TextEntering(object sender, TextInputEventArgs e)
{
if (e.Text.Length > 0 && _completionWindow != null)
{
if (!char.IsLetterOrDigit(e.Text[0]))
{
// Whenever a non-letter is typed while the completion window is open,
// insert the currently selected element.
_completionWindow.CompletionList.RequestInsertion(e);
}
}



// Do not set e.Handled=true.
// We still want to insert the character that was typed.
}

private void textEditor_TextArea_TextEntered(object sender, TextInputEventArgs e)
{
if (e.Text == "<" || e.Text == "/")
{

_completionWindow = new CompletionWindow(_textEditor.TextArea);
_completionWindow.Closed += (o, args) => _completionWindow = null;

var data = _completionWindow.CompletionList.CompletionData;
data.Add(new MyCompletionData("suki:GlassCard"));
data.Add(new MyCompletionData("Grid"));
data.Add(new MyCompletionData("Button"));
data.Add(new MyCompletionData("TextBlock"));

_completionWindow.Show();
}

}

private void Editor_OnTextChanged(object? sender, EventArgs e)
{
string PreviewCode = "<Grid xmlns:icons=\"clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia\" xmlns:suki=\"clr-namespace:SukiUI.Controls;assembly=SukiUI\" xmlns='https://github.com/avaloniaui' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>" +
_textEditor.Text + "</Grid>";

try
{
Control DemoContent = AvaloniaRuntimeXamlLoader.Parse<Grid>(PreviewCode);
_glassPlayground.Content = DemoContent;
}
catch
{

}
}

private string StartingString =
"<suki:GlassCard Width=\"300\" Height=\"320\" Margin=\"15\" VerticalAlignment=\"Top\">\n" +
" <Grid>\n" +
" <TextBlock FontSize=\"16\" FontWeight=\"DemiBold\" Text=\"Humidity\" />\n" +
" <Viewbox Width=\"175\" Height=\"175\" Margin=\"0,0,0,5\" HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\">\n" +
" <suki:WaveProgress Value=\"{Binding Value, ElementName=SliderT}\" />\n" +
" </Viewbox>\n" +
" <DockPanel VerticalAlignment=\"Bottom\">\n" +
" <icons:MaterialIcon Width=\"20\" Height=\"20\" DockPanel.Dock=\"Left\" Foreground=\"#666666\" Kind=\"TemperatureLow\" /> \n" +
" <icons:MaterialIcon Width=\"20\" Height=\"20\" DockPanel.Dock=\"Right\" Foreground=\"#666666\" Kind=\"TemperatureHigh\" />\n" +
" <Slider Name=\"SliderT\" Margin=\"8,0\" Maximum=\"100\" Minimum=\"0\" Value=\"23\" />\n" +
" </DockPanel>\n" +
" </Grid>\n" +
"</suki:GlassCard>";

}


public class MyCompletionData : ICompletionData
{
public MyCompletionData(string text)
{
Text = text;
}

public IImage Image => null;

public string Text { get; }

// Use this property if you want to show a fancy UIElement in the list.
public object Content => Text;

public object Description => "Avalonia Control";

public double Priority { get; } = 0;

public void Complete(TextArea textArea, ISegment completionSegment,
EventArgs insertionRequestEventArgs)
{
textArea.Document.Replace(completionSegment, Text);
}
}

}
12 changes: 12 additions & 0 deletions SukiUI.Demo/Features/Playground/PlaygroundViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Material.Icons;

namespace SukiUI.Demo.Features.Playground
{
public class PlaygroundViewModel : DemoPageBase
{
public PlaygroundViewModel() : base("Playground", MaterialIconKind.Pencil, -150)
{

}
}
}
72 changes: 72 additions & 0 deletions SukiUI.Demo/Styles/CompletionWindowStyles.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion;assembly=AvaloniaEdit"
xmlns:theme="clr-namespace:SukiUI.Theme;assembly=SukiUI">
<ControlTheme x:Key="{x:Type cc:CompletionListBox}" TargetType="cc:CompletionListBox"
BasedOn="{StaticResource {x:Type ListBox}}">
<Setter Property="Padding" Value="0" />
<Setter Property="ItemContainerTheme">
<ControlTheme TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="TextBlock.Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="Background" Value="Red" />
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource ListBoxBorderThemeThickness}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="Padding" Value="4,1" />
<Setter Property="FontSize" Value="12"></Setter>
<Setter Property="FontWeight" Value="DemiBold"></Setter>
</ControlTheme>
</Setter>
<Setter Property="Template">
<ControlTemplate>

<Border Name="border"
Background="{DynamicResource SukiCardBackground}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0"
ClipToBounds="{TemplateBinding ClipToBounds}"
CornerRadius="{TemplateBinding CornerRadius}">
<Border.Resources>
<theme:BiggestItemListBoxConverter x:Key="BiggestListitem" />
</Border.Resources>
<Grid>
<ListBoxItem Margin="0,0,32,0"
Content="{TemplateBinding ItemsSource,
Converter={StaticResource BiggestListitem}}"
Opacity="0" />
<ScrollViewer Name="PART_ScrollViewer"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
<ItemsPresenter Name="PART_ItemsPresenter"
Margin="{TemplateBinding Padding}"
ItemsPanel="{TemplateBinding ItemsPanel}" />
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</ControlTheme>

<ControlTheme x:Key="{x:Type cc:CompletionList}" TargetType="cc:CompletionList">
<Setter Property="Template">
<ControlTemplate>
<Border Margin="10" BoxShadow="{DynamicResource SukiPopupShadow}" ClipToBounds="True" CornerRadius="8" >
<cc:CompletionListBox Name="PART_ListBox">
<cc:CompletionListBox.ItemTemplate>
<DataTemplate x:DataType="cc:ICompletionData">
<StackPanel Orientation="Horizontal" Margin="0">
<Image Source="{Binding Image}"
Width="16"
Height="16"
Margin="0,0,2,0" />
<ContentPresenter Content="{Binding Content}" />
</StackPanel>
</DataTemplate>
</cc:CompletionListBox.ItemTemplate>
</cc:CompletionListBox>
</Border>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions SukiUI.Demo/SukiUI.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.6" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.6" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.6" />
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.0.6" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
Expand Down

0 comments on commit 8485a0a

Please sign in to comment.