From 0bd5c7a3885b387a3d8fc0c9d0685335d7711b40 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Mon, 16 Dec 2024 17:39:19 -0800 Subject: [PATCH] Enable scrolling behavior to work correctly by making sure there is a background of transparent on the panels for containers. Update Scroller to have bigger scroll area so it's clearer to see it working Fix bug in AccessText registration which was breaking comboboxes. --- src/Consolonia.Core/Helpers/Observable.cs | 134 ++++++++++++++++++ .../Infrastructure/ConsoloniaApplication.cs | 6 +- .../GalleryViews/GalleryScrollViewer.axaml | 50 +++---- .../GalleryViews/GalleryScrollViewer.axaml.cs | 33 ++++- .../Templates/Controls/ComboBoxItem.axaml | 3 +- .../Templates/Controls/DataGrid.axaml | 3 +- .../Templates/Controls/ListBoxItem.axaml | 3 +- .../Templates/Controls/ScrollViewer.axaml | 32 +++-- 8 files changed, 208 insertions(+), 56 deletions(-) create mode 100644 src/Consolonia.Core/Helpers/Observable.cs diff --git a/src/Consolonia.Core/Helpers/Observable.cs b/src/Consolonia.Core/Helpers/Observable.cs new file mode 100644 index 00000000..c66b9700 --- /dev/null +++ b/src/Consolonia.Core/Helpers/Observable.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Avalonia.Reactive.Operators; +using Avalonia.Threading; +using global::Avalonia.Reactive; + +namespace Consolonia.Core.Helpers +{ + + /// + /// Provides common observable methods as a replacement for the Rx framework. + /// + /// + /// COPIED FROM AVALONIA.BASE BECAUSE IT IS NOT PUBLICLY ACCESSIBLE, + /// it's either do this or pull in all of Rx framework as a dependency + /// + /// + internal static class Observable + { + public static IObservable Create(Func, IDisposable> subscribe) + { + return new CreateWithDisposableObservable(subscribe); + } + + public static IDisposable Subscribe(this IObservable source, Action action) + { + return source.Subscribe(new AnonymousObserver(action)); + } + + public static IObservable Select(this IObservable source, Func selector) + { + return Create(obs => + { + return source.Subscribe(new AnonymousObserver( + input => + { + TResult value; +#pragma warning disable CA1031 // Do not catch general exception types + try + { + value = selector(input); + } + catch (Exception ex) + { + obs.OnError(ex); + return; + } +#pragma warning restore CA1031 // Do not catch general exception types + + obs.OnNext(value); + }, obs.OnError, obs.OnCompleted)); + }); + } + + public static IObservable StartWith(this IObservable source, TSource value) + { + return Create(obs => + { + obs.OnNext(value); + return source.Subscribe(obs); + }); + } + + public static IObservable Where(this IObservable source, Func predicate) + { + return Create(obs => + { + return source.Subscribe(new AnonymousObserver( + input => + { + bool shouldRun; +#pragma warning disable CA1031 // Do not catch general exception types + try + { + shouldRun = predicate(input); + } + catch (Exception ex) + { + obs.OnError(ex); + return; + } +#pragma warning restore CA1031 // Do not catch general exception types + if (shouldRun) + { + obs.OnNext(input); + } + }, obs.OnError, obs.OnCompleted)); + }); + } + + public static IObservable Skip(this IObservable source, int skipCount) + { + if (skipCount <= 0) + { + throw new ArgumentException("Skip count must be bigger than zero", nameof(skipCount)); + } + + return Create(obs => + { + var remaining = skipCount; + return source.Subscribe(new AnonymousObserver( + input => + { + if (remaining <= 0) + { + obs.OnNext(input); + } + else + { + remaining--; + } + }, obs.OnError, obs.OnCompleted)); + }); + } + + + private sealed class CreateWithDisposableObservable : IObservable + { + private readonly Func, IDisposable> _subscribe; + + public CreateWithDisposableObservable(Func, IDisposable> subscribe) + { + _subscribe = subscribe; + } + + public IDisposable Subscribe(IObserver observer) + { + return _subscribe(observer); + } + } + } +} \ No newline at end of file diff --git a/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs b/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs index 31e034ed..b8b91a91 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs @@ -27,13 +27,13 @@ public override void OnFrameworkInitializationCompleted() DataTemplates.Add(new FuncDataTemplate( (data, _) => { - if (data != null && data is string) + if (data != null) { var result = new ConsoloniaAccessText(); // ReSharper disable AccessToStaticMemberViaDerivedType result.Bind(TextBlock.TextProperty, - result.GetObservable(Control.DataContextProperty)); - return result; + result.GetObservable(Control.DataContextProperty).Select(x => x?.ToString())); + return result; } return null; diff --git a/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml b/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml index 76337c6b..c2a93776 100644 --- a/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml +++ b/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml @@ -12,52 +12,34 @@ - - - + - - - + - Focus to ScrollViewer - /; ;\ - __ \\____// - /{_\_/ `'\____ - \___ (o) (o } - _____________________________/ :--' - ,-,'`@@@@@@@@ @@@@@@ \_ `__\ - ;:( @@@@@@@@@ @@@ \___(o'o) - :: ) @@@@ @@@@@@ ,'@@( `====' - :: : @@@@@: @@@@ `@@@: - :: \ @@@@@: @@@@@@@) ( '@@@' - ;; /\ /`, @@@@@@@@@\ :@@@@@) - ::/ ) {_----------------: :~`,~~; - ;;'`; : ) : / `; ; -;;;; : : ; : ; ; : -`'`' / : : : : : : - )_ \__; ";" :_ ; \_\ `,',' - :__\ \ * `,'* \ \ : \ * 8`;'* * - `^' \ :/ `^' `-^-' \v/ : \/ -Bill Ames - - + + + + + + + \ No newline at end of file diff --git a/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs b/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs index 7d989947..1af72a9d 100644 --- a/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs +++ b/src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; @@ -38,8 +39,35 @@ public ScrollViewerPageViewModel() }; HorizontalScrollVisibility = ScrollBarVisibility.Auto; - VerticalScrollVisibility = ScrollBarVisibility.Auto; + VerticalScrollVisibility = ScrollBarVisibility.Visible; AllowAutoHide = true; + List text = new List(); + for(int i=0; i< 30;i++) + { + text.AddRange(""" + /; ;\ + __ \\____// + /{_\_/ `'\____ + \___ (o) (o } + _____________________________/ :--' + ,-,'`@@@@@@@@ @@@@@@ \_ `__\ + ;:( @@@@@@@@@ @@@ \___(o'o) + :: ) @@@@ @@@@@@ ,'@@( `====' + :: : @@@@@: @@@@ `@@@: + :: \ @@@@@: @@@@@@@) ( '@@@' + ;; /\ /`, @@@@@@@@@\ :@@@@@) + ::/ ) {_----------------: :~`,~~; + ;;'`; : ) : / `; ; + ;;;; : : ; : ; ; : + `'`' / : : : : : : + )_ \__; ";" :_ ; \_\ `,',' + :__\ \ * `,'* \ \ : \ * 8`;'* * + `^' \ :/ `^' `-^-' \v/ : \/ + Bill Ames + + """.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries)); + } + Cows = text; } public bool AllowAutoHide @@ -61,6 +89,9 @@ public ScrollBarVisibility VerticalScrollVisibility } public List AvailableVisibility { get; } + + private List _cows = new List(); + public List Cows { get => _cows; init => RaiseAndSetIfChanged(ref _cows, value); } } public class ViewModelBase : INotifyPropertyChanged diff --git a/src/Consolonia.Themes/Templates/Controls/ComboBoxItem.axaml b/src/Consolonia.Themes/Templates/Controls/ComboBoxItem.axaml index 71639bc3..16c6dd81 100644 --- a/src/Consolonia.Themes/Templates/Controls/ComboBoxItem.axaml +++ b/src/Consolonia.Themes/Templates/Controls/ComboBoxItem.axaml @@ -13,7 +13,8 @@ Value="Left" /> - + + Background="Transparent"> diff --git a/src/Consolonia.Themes/Templates/Controls/ListBoxItem.axaml b/src/Consolonia.Themes/Templates/Controls/ListBoxItem.axaml index f6122fa8..f323cb2a 100644 --- a/src/Consolonia.Themes/Templates/Controls/ListBoxItem.axaml +++ b/src/Consolonia.Themes/Templates/Controls/ListBoxItem.axaml @@ -10,10 +10,11 @@ Value="{DynamicResource ThemeTransparentBrush}" /> - + - - - - - + + + + + + +