Skip to content

Commit 8ac198e

Browse files
committed
Added the animated list box everywhere possible
1 parent b2a7944 commit 8ac198e

18 files changed

+140
-274
lines changed

src/CutCode.CrossPlatform/App.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<StyleInclude Source="/Styles/ScrollBarStyles.axaml"/>
2525
<StyleInclude Source="/Styles/TextBoxStyles.axaml"/>
2626
<StyleInclude Source="/Styles/ComboBox.axaml"/>
27-
<StyleInclude Source="/Styles/ListBoxItem.axaml"/>
27+
<StyleInclude Source="/Styles/AnimatedListBoxItem.axaml"/>
2828

2929
<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml" />
3030

src/CutCode.CrossPlatform/Controls/AnimatedListBoxItem.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88

99
namespace CutCode.CrossPlatform.Controls;
1010

11-
[PseudoClasses(":Added"), PseudoClasses(":Removed")]
11+
[PseudoClasses(":Added", ":Removed")]
1212
public class AnimatedListBoxItem : ListBoxItem, IStyleable
1313
{
14-
Type IStyleable.StyleKey => typeof(ListBoxItem);
15-
14+
Type IStyleable.StyleKey => typeof(AnimatedListBoxItem);
15+
16+
private bool isAttached = false;
1617
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
1718
{
18-
PseudoClasses.Set(":Added", true);
1919
base.OnAttachedToVisualTree(e);
20+
if (isAttached) return;
21+
PseudoClasses.Set(":Added", true);
22+
isAttached = true;
2023
}
2124

2225
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<Styles xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:controls="clr-namespace:CutCode.CrossPlatform.Controls">
4+
<Style Selector="controls|AnimatedListBoxItem">
5+
<Setter Property="Background" Value="Transparent"/>
6+
<Setter Property="Margin" Value="0"/>
7+
<Setter Property="Padding" Value="0"/>
8+
<Setter Property="Template">
9+
<ControlTemplate>
10+
<ContentPresenter Name="PART_ContentPresenter"
11+
Background="{TemplateBinding Background}"
12+
BorderBrush="{TemplateBinding BorderBrush}"
13+
BorderThickness="{TemplateBinding BorderThickness}"
14+
CornerRadius="{TemplateBinding CornerRadius}"
15+
ContentTemplate="{TemplateBinding ContentTemplate}"
16+
Content="{TemplateBinding Content}"
17+
Padding="{TemplateBinding Padding}"
18+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
19+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
20+
</ControlTemplate>
21+
</Setter>
22+
</Style>
23+
<Style Selector="controls|AnimatedListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter">
24+
<Setter Property="Background" Value="Transparent"/>
25+
</Style>
26+
<Style Selector="controls|AnimatedListBoxItem:pressed /template/ ContentPresenter#PART_ContentPresenter">
27+
<Setter Property="Background" Value="Transparent"/>
28+
</Style>
29+
<Style Selector="controls|AnimatedListBoxItem:selected /template/ ContentPresenter#PART_ContentPresenter">
30+
<Setter Property="Background" Value="Transparent"/>
31+
</Style>
32+
33+
<Style Selector="controls|AnimatedListBoxItem:Added /template/ ContentPresenter#PART_ContentPresenter">
34+
<Style.Animations>
35+
<Animation Duration="0:0:0.3">
36+
<KeyFrame Cue="0%">
37+
<Setter Property="Opacity" Value="0.0"/>
38+
</KeyFrame>
39+
<KeyFrame Cue="100%">
40+
<Setter Property="Opacity" Value="1.0"/>
41+
</KeyFrame>
42+
</Animation>
43+
</Style.Animations>
44+
</Style>
45+
<Style Selector="controls|AnimatedListBoxItem:Removed /template/ ContentPresenter#PART_ContentPresenter">
46+
<Style.Animations>
47+
<Animation Duration="0:0:0.3">
48+
<KeyFrame Cue="0%">
49+
<Setter Property="Opacity" Value="1.0"/>
50+
</KeyFrame>
51+
<KeyFrame Cue="100%">
52+
<Setter Property="Opacity" Value="0.0"/>
53+
</KeyFrame>
54+
</Animation>
55+
</Style.Animations>
56+
</Style>
57+
</Styles>

src/CutCode.CrossPlatform/Styles/ListBoxItem.axaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/CutCode.CrossPlatform/ViewModels/AddViewModel.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public AddViewModel(IScreen screen)
5555
this.WhenAnyValue(x => x.SelectedLanguage2).WhereNotNull().Subscribe(GlobalEvents.LanguageSet);
5656
}
5757

58-
public static AddViewModel Current { get; } = new();
59-
6058
public ObservableCollection<CodeCellViewModel?> Cells { get; }
6159
public IList<string> AllLangs { get; set; }
6260

@@ -142,11 +140,6 @@ public async void Save()
142140
}
143141
}
144142

145-
public static void DeleteCell(AddViewModel vm, CodeCellViewModel cell)
146-
{
147-
vm.Cells.Remove(cell);
148-
}
149-
150143
public async void LanguageChanged(string selectedLanguage)
151144
{
152145
_selectedLanguage = selectedLanguage;

src/CutCode.CrossPlatform/ViewModels/CodeCellViewModel.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CodeCellViewModel : PageBaseViewModel
1010
{
1111
private readonly AddViewModel AddViewModelInstance;
1212
private readonly CodeViewModel CodeViewModelInstance;
13-
13+
private readonly bool isFromAddPage;
1414
[Reactive] public TextDocument Document { get; set; } = new TextDocument();
1515

1616
public CodeCellViewModel(AddViewModel viewModelInstance)
@@ -20,6 +20,17 @@ public CodeCellViewModel(AddViewModel viewModelInstance)
2020
IsEditable = true;
2121
IsMoreClickable = false;
2222
Code = "";
23+
isFromAddPage = true;
24+
}
25+
26+
public CodeCellViewModel(CodeViewModel viewModelInstance)
27+
{
28+
// Creating new one
29+
CodeViewModelInstance = viewModelInstance;
30+
IsEditable = true;
31+
IsMoreClickable = false;
32+
Code = "";
33+
isFromAddPage = false;
2334
}
2435

2536
public CodeCellViewModel(CodeViewModel viewModelInstance, string description, string code)
@@ -32,6 +43,7 @@ public CodeCellViewModel(CodeViewModel viewModelInstance, string description, st
3243

3344
IsEditable = false;
3445
IsMoreClickable = true;
46+
isFromAddPage = false;
3547

3648
GlobalEvents.OnViewRegistered += (sender, o) =>
3749
{
@@ -69,7 +81,10 @@ protected override void OnDarkThemeIsSet()
6981

7082
public async void DeleteCell(CodeCellViewModel cell)
7183
{
72-
if (AddViewModelInstance != null) AddViewModel.DeleteCell(AddViewModelInstance, cell);
73-
else CodeViewModel.DeleteCell(CodeViewModelInstance, cell);
84+
if (!IsEditable) return;
85+
if (isFromAddPage)
86+
AddViewModelInstance.Cells.Remove(cell);
87+
else
88+
CodeViewModelInstance.Cells.Remove(cell);
7489
}
7590
}

src/CutCode.CrossPlatform/ViewModels/CodeViewModel.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private void OnDarkThemeIsSet()
181181

182182
public async void AddCell()
183183
{
184-
Cells.Add(new CodeCellViewModel(AddViewModel.Current));
184+
Cells.Add(new CodeCellViewModel(this));
185185
}
186186

187187
public async void Cancel()
@@ -252,14 +252,4 @@ public async void DeleteCode()
252252
if (delete) GlobalEvents.CancelClicked();
253253
// if it wasn't deleted, we will show notificaiton
254254
}
255-
256-
public async void Share()
257-
{
258-
// will be implemented later
259-
}
260-
261-
public static void DeleteCell(CodeViewModel vm, CodeCellViewModel cell)
262-
{
263-
if (vm.IsEditEnabled) vm.Cells.Remove(cell);
264-
}
265255
}

src/CutCode.CrossPlatform/ViewModels/DeveloperCardViewModel.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/CutCode.CrossPlatform/ViewModels/SettingsViewModel.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,10 @@ public SettingsViewModel()
2929
[Reactive] public Color CardColor { get; set; }
3030

3131
[Reactive] public Color BtnColor { get; set; }
32-
33-
public ObservableCollection<DeveloperCardViewModel> developers { get; set; }
34-
32+
3533
public string? UrlPathSegment => Guid.NewGuid().ToString().Substring(0, 5);
3634
public IScreen HostScreen { get; }
3735

38-
protected override void OnLoad()
39-
{
40-
developers = new ObservableCollection<DeveloperCardViewModel>
41-
{
42-
new(
43-
"avares://CutCode.CrossPlatform/Assets/Images/Developers/abdesol.png",
44-
"Abdella Solomon",
45-
"C# and Python Programmer. Currently into AI/ML",
46-
"@abdesol",
47-
"https://github.com/Abdesol",
48-
"https://twitter.com/AbdellaSolomon"),
49-
50-
new(
51-
"avares://CutCode.CrossPlatform/Assets/Images/Developers/piero.png",
52-
"Piero Castillo",
53-
"Student and C# programmer who lives in Lima, Peru",
54-
"@sharped_net",
55-
"https://github.com/PieroCastillo",
56-
"https://twitter.com/sharped_net")
57-
};
58-
}
59-
6036
protected override void OnLightThemeIsSet()
6137
{
6238
BackgroundColor = Color.Parse("#FCFCFC");

src/CutCode.CrossPlatform/Views/AddView.axaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
BorderBrush="{Binding TextAreaOverlayBackground, Converter={StaticResource ColorToBrushConverter}}"
4747
BorderThickness="0"/>
4848
<ComboBox Name="Choose Language" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right"
49+
Margin="0,0,18,0"
4950
Items="{Binding AllLanguages}"
5051
SelectedItem="{Binding SelectedLanguage2}"
5152
Background="{Binding ComboBoxBackground, Converter={StaticResource ColorToBrushConverter}}"
@@ -54,15 +55,18 @@
5455

5556
</Grid>
5657

57-
<ScrollViewer Grid.Row="1" IsVisible="{Binding !IsCellEmpty}">
58-
<ItemsControl Items="{Binding Cells}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
59-
<ItemsControl.ItemsPanel>
60-
<ItemsPanelTemplate>
61-
<StackPanel/>
62-
</ItemsPanelTemplate>
63-
</ItemsControl.ItemsPanel>
64-
</ItemsControl>
65-
</ScrollViewer>
58+
<controllers:AnimatedListBox Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
59+
Items="{Binding Cells}" Background="Transparent"
60+
IsVisible="{Binding !IsCellEmpty}"
61+
BorderThickness="0"
62+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
63+
ScrollViewer.VerticalScrollBarVisibility="Visible">
64+
<controllers:AnimatedListBox.ItemsPanel>
65+
<ItemsPanelTemplate>
66+
<StackPanel/>
67+
</ItemsPanelTemplate>
68+
</controllers:AnimatedListBox.ItemsPanel>
69+
</controllers:AnimatedListBox>
6670

6771
<Label Grid.Row="1" IsVisible="{Binding IsCellEmpty}"
6872
Content="You don't have any cells yet"

0 commit comments

Comments
 (0)