-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e20a4fe
commit 8485a0a
Showing
6 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
162
SukiUI.Demo/Features/Playground/PlaygroundView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters