A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Improved scroll viewer
Etienne Baudoux9c3690d0635b
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.csindex f90e93b6a..f9a1e147d 100644--- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs+++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs@@ -5,24 +5,47 @@ namespace DevToys.Api;/// <summary>/// Represents the root ui definition of a <see cref="IGuiTool"/>./// </summary>-[DebuggerDisplay($"RootElement = {{{nameof(RootElement)}}}")]+[DebuggerDisplay($"RootElement = {{{nameof(RootElement)}}}, IsScrollable = {{{nameof(IsScrollable)}}}")]public class UIToolView : INotifyPropertyChanged{+ private bool _isScrollable;+/// <summary>/// Creates a new instance of the <see cref="UIToolView"/> class./// </summary>/// <param name="rootElement">The root element of the tool's UI.</param>public UIToolView(IUIElement rootElement)+ : this(true, rootElement)+ {+ }++ /// <summary>+ /// Creates a new instance of the <see cref="UIToolView"/> class.+ /// </summary>+ /// <param name="isScrollable">Indicates whether the UI of the tool is scrollable or should fits to the window boundaries.</param>+ /// <param name="rootElement">The root element of the tool's UI.</param>+ public UIToolView(bool isScrollable, IUIElement rootElement){- Guard.IsNotNull(rootElement);+ IsScrollable = isScrollable;RootElement = rootElement;}+ /// <summary>+ /// Gets whether the UI of the tool is scrollable or should fits to the window boundaries. Default is true.+ /// </summary>+ public bool IsScrollable+ {+ get => _isScrollable;+ internal set => SetPropertyValue(ref _isScrollable, value, IsScrollableChanged);+ }+/// <summary>/// Gets the root element of the tool's UI./// </summary>public IUIElement RootElement { get; }+ public event EventHandler? IsScrollableChanged;+public event PropertyChangedEventHandler? PropertyChanged;protected void SetPropertyValue<T>(diff --git a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razorindex 5705de4af..4e32337ab 100644--- a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor+++ b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor@@ -20,9 +20,10 @@IsVisible="@IsVisible"><ScrollViewer @ref=_scrollViewerOrientation="UIOrientation.Vertical"+ IsEnabled="@IsActuallyEnabled"Class="@(FinalCssClasses)"style="@(Style)"- @attributes="AdditionalAttributes">+ @attributes="@AdditionalAttributes">@if (Header is not null){<div class="header">@Header</div>diff --git a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.js b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.jsindex 281c318e7..e484f8173 100644--- a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.js+++ b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.js@@ -47,7 +47,7 @@ function onGridViewScroll(ev) {// Calculate the best size items in the grid view should take in order to fill// as much space possible while having as many columns at possible.function fitGridViewItemsToContainer(gridView, gridViewBounds, itemMinWidth) {- const gridViewContentContainerStyle = getComputedStyle(gridView.getElementsByClassName("simplebar-content")[0]);+ const gridViewContentContainerStyle = getComputedStyle(gridView.getElementsByClassName("grid-view")[0]);const newGridViewContentSize = gridViewBounds;const gridViewWidth = newGridViewContentSize.width- parseInt(gridViewContentContainerStyle.paddingLeft)diff --git a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.scss b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.scssindex b11bf2c71..16b8b2fb0 100644--- a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.scss+++ b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.scss@@ -10,7 +10,6 @@.footer {margin-top: 24px;- margin-bottom: 24px;}.grid-view-group {diff --git a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.ts b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.tsindex cdb1dc21f..3f91a484d 100644--- a/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.ts+++ b/src/app/dev/DevToys.Blazor/Components/Collections/GridView/GridView.razor.ts@@ -57,7 +57,7 @@ function onGridViewScroll(ev: Event): void {// Calculate the best size items in the grid view should take in order to fill// as much space possible while having as many columns at possible.function fitGridViewItemsToContainer(gridView: HTMLElement, gridViewBounds: DOMRectReadOnly, itemMinWidth: number): void {- const gridViewContentContainerStyle = getComputedStyle(gridView.getElementsByClassName("simplebar-content")[0]);+ const gridViewContentContainerStyle = getComputedStyle(gridView.getElementsByClassName("grid-view")[0]);const newGridViewContentSize = gridViewBounds;const gridViewWidth= newGridViewContentSize.widthdiff --git a/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor b/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razorindex 134b8cee2..2ba276890 100644--- a/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor+++ b/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor@@ -17,11 +17,10 @@IsEnabled="@IsActuallyEnabled"IsVisible="@IsVisible"><div id="@Id"- class="scroll-viewer @(FinalCssClasses)"- style="@(Style)"+ class="scroll-viewer @(_scrollViewerCssClasses)"@ref=Element@attributes="AdditionalAttributes">- <div style="grid-row: 1;">+ <div class="@(FinalCssClasses)" style="@(Style); grid-row: 1;">@ChildContent</div></div>diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.cs b/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.csindex 0fd6a82c1..63b998cbb 100644--- a/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.cs+++ b/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.cs@@ -4,6 +4,8 @@ public partial class ScrollViewer : JSStyledComponentBase{protected override string? JavaScriptFile => "./_content/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.js";+ private string? _scrollViewerCssClasses;+/// <summary>/// Gets or set the orientation in which the content can be scrolled./// </summary>@@ -61,40 +63,20 @@ public partial class ScrollViewer : JSStyledComponentBaseAdditionalAttributes.TryAdd("data-simplebar-not-scrollable", true);}+ var scrollViewerCssClasses = new CssBuilder();if (((Orientation & UIOrientation.Vertical) != 0 && (Orientation & UIOrientation.Horizontal) != 0)|| !IsScrollable){- CSS.Clear();+ scrollViewerCssClasses.AddClass("not-scrollable");}else{- if ((Orientation & UIOrientation.Vertical) != 0)- {- CSS.Add("vertical");- }- else- {- CSS.Remove("vertical");- }-- if ((Orientation & UIOrientation.Horizontal) != 0)- {- CSS.Add("horizontal");- }- else- {- CSS.Remove("horizontal");- }+ scrollViewerCssClasses.AddClass("vertical", (Orientation & UIOrientation.Vertical) != 0);+ scrollViewerCssClasses.AddClass("horizontal", (Orientation & UIOrientation.Horizontal) != 0);}- if (UseNativeScrollBar && IsScrollable)- {- CSS.Add("use-native-scroll");- }- else- {- CSS.Remove("use-native-scroll");- }+ scrollViewerCssClasses.AddClass("use-native-scroll", UseNativeScrollBar && IsScrollable);+ _scrollViewerCssClasses = scrollViewerCssClasses.Build();base.OnParametersSet();}diff --git a/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.scss b/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.scssindex ebf9ee36f..35c37b375 100644--- a/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.scss+++ b/src/app/dev/DevToys.Blazor/Components/Layout/ScrollViewer/ScrollViewer.razor.scss@@ -14,6 +14,11 @@overflow-x: overlay;}+ &.not-scrollable {+ overflow-x: hidden;+ overflow-y: hidden;+ }+&.use-native-scroll {&::-webkit-scrollbar-track {border-radius: 999px;diff --git a/src/app/dev/DevToys.Blazor/Pages/SubPages/ToolPage.razor b/src/app/dev/DevToys.Blazor/Pages/SubPages/ToolPage.razorindex 46bcee477..f029f4e85 100644--- a/src/app/dev/DevToys.Blazor/Pages/SubPages/ToolPage.razor+++ b/src/app/dev/DevToys.Blazor/Pages/SubPages/ToolPage.razor@@ -3,7 +3,7 @@@inherits MefComponentBase<ScrollViewer Class="entrance-theme-transition tool-page-content"- IsScrollable="@(!IsInFullScreenMode)">+ IsScrollable="@(!IsInFullScreenMode && ViewModel.ToolView.IsScrollable)">@RenderToolWithHeader(true)</ScrollViewer>@@ -14,8 +14,7 @@{RenderToolWithHeader = (bool isScrollable) => (__builder) =>{- <Grid PaddingBottom="40"- RowSpacing="12"+ <Grid RowSpacing="12"Rows="@(new List<UIGridLength>{UIGridLength.Auto,