Ver código fonte

Scrolling startup fixes, scrolling size fixes, scrolling style fixes.

Ruben 7 meses atrás
pai
commit
ca06cf6bf0

+ 7 - 0
src/PicView.Avalonia/CustomControls/MainScrollViewer.cs

@@ -0,0 +1,7 @@
+namespace PicView.Avalonia.CustomControls;
+
+
+public class MainScrollViewer : AutoScrollViewer
+{
+    protected override Type StyleKeyOverride => typeof(MainScrollViewer);
+}

+ 2 - 2
src/PicView.Avalonia/PicViewTheme/Controls/ListBox.axaml

@@ -15,7 +15,7 @@
                     BorderThickness="{TemplateBinding BorderThickness}"
                     CornerRadius="{TemplateBinding CornerRadius}"
                     Name="border">
-                    <customControls:AutoScrollViewer
+                    <customControls:MainScrollViewer
                         AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
                         Background="{TemplateBinding Background}"
                         BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"
@@ -30,7 +30,7 @@
                             ItemsPanel="{TemplateBinding ItemsPanel}"
                             Margin="{TemplateBinding Padding}"
                             Name="PART_ItemsPresenter" />
-                    </customControls:AutoScrollViewer>
+                    </customControls:MainScrollViewer>
                 </Border>
             </ControlTemplate>
         </Setter>

+ 52 - 0
src/PicView.Avalonia/PicViewTheme/Controls/MainScrollViewer.axaml

@@ -0,0 +1,52 @@
+<ResourceDictionary
+    x:ClassModifier="internal"
+    xmlns="https://github.com/avaloniaui"
+    xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+    <ControlTheme TargetType="customControls:MainScrollViewer" x:Key="{x:Type customControls:MainScrollViewer}">
+        <Setter Property="Background" Value="Transparent" />
+        <Setter Property="Template">
+            <ControlTemplate>
+                <Grid ColumnDefinitions="*,Auto" RowDefinitions="*,Auto">
+                    <ScrollContentPresenter
+                        Background="{TemplateBinding Background}"
+                        HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}"
+                        HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}"
+                        Name="PART_ContentPresenter"
+                        Padding="{TemplateBinding Padding}"
+                        ScrollViewer.IsScrollInertiaEnabled="{TemplateBinding IsScrollInertiaEnabled}"
+                        VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}"
+                        VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}">
+                        <ScrollContentPresenter.GestureRecognizers>
+                            <ScrollGestureRecognizer
+                                CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}"
+                                CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}"
+                                IsScrollInertiaEnabled="{Binding (ScrollViewer.IsScrollInertiaEnabled), ElementName=PART_ContentPresenter}" />
+                        </ScrollContentPresenter.GestureRecognizers>
+                    </ScrollContentPresenter>
+                    <ScrollBar
+                        Grid.Column="0"
+                        Grid.Row="1"
+                        Name="PART_HorizontalScrollBar"
+                        Orientation="Horizontal"
+                        Theme="{StaticResource MainScrollbar}" />
+                    <ScrollBar
+                        Grid.Column="1"
+                        Grid.Row="0"
+                        Name="PART_VerticalScrollBar"
+                        Orientation="Vertical"
+                        Theme="{StaticResource MainScrollbar}" />
+                    <Canvas Grid.Column="0" Grid.Row="0">
+                        <customControls:AutoScrollSign
+                            HorizontalAlignment="Center"
+                            IsVisible="False"
+                            Name="PART_AutoScrollSign"
+                            VerticalAlignment="Center" />
+                    </Canvas>
+                </Grid>
+            </ControlTemplate>
+        </Setter>
+
+    </ControlTheme>
+
+</ResourceDictionary>

+ 223 - 0
src/PicView.Avalonia/PicViewTheme/Controls/MainScrollbar.axaml

@@ -0,0 +1,223 @@
+<ResourceDictionary
+    x:ClassModifier="internal"
+    xmlns="https://github.com/avaloniaui"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+    <ControlTheme TargetType="ScrollBar" x:Key="MainScrollbar">
+        <Setter Property="Cursor" Value="Arrow" />
+
+        <Style Selector="^:horizontal">
+            <Setter Property="Height" Value="18" />
+            <Setter Property="Focusable" Value="False" />
+            <Setter Property="Template">
+                <ControlTemplate>
+                    <Border
+                        Background="{DynamicResource WindowButtonBackgroundColor}"
+                        Name="PART_Track"
+                        UseLayoutRounding="False">
+                        <Grid ColumnDefinitions="Auto,*,Auto">
+                            <RepeatButton
+                                Background="Transparent"
+                                Classes="repeat"
+                                Focusable="False"
+                                Grid.Column="0"
+                                Grid.Row="0"
+                                Height="16"
+                                Interval="55"
+                                MinWidth="30"
+                                Name="PART_LineUpButton"
+                                VerticalAlignment="Center"
+                                Width="16">
+                                <Path
+                                    Data="M321.94 98L158.82 237.78a24 24 0 000 36.44L321.94 414c15.57 13.34 39.62 2.28 39.62-18.22v-279.6c0-20.5-24.05-31.56-39.62-18.18z"
+                                    Fill="{TemplateBinding Foreground}"
+                                    Height="12"
+                                    HorizontalAlignment="Center"
+                                    Stretch="Fill"
+                                    VerticalAlignment="Center"
+                                    Width="12" />
+                            </RepeatButton>
+                            <Track
+                                DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
+                                Grid.Column="1"
+                                Grid.Row="1"
+                                Maximum="{TemplateBinding Maximum}"
+                                Minimum="{TemplateBinding Minimum}"
+                                Orientation="{TemplateBinding Orientation}"
+                                Value="{TemplateBinding Value,
+                                                        Mode=TwoWay}"
+                                ViewportSize="{TemplateBinding ViewportSize}">
+                                <Track.DecreaseButton>
+                                    <RepeatButton
+                                        Background="Transparent"
+                                        Classes="repeattrack"
+                                        Focusable="False"
+                                        Interval="55"
+                                        Name="PART_PageUpButton" />
+                                </Track.DecreaseButton>
+                                <Track.IncreaseButton>
+                                    <RepeatButton
+                                        Background="Transparent"
+                                        Classes="repeattrack"
+                                        Focusable="False"
+                                        Interval="55"
+                                        Name="PART_PageDownButton" />
+                                </Track.IncreaseButton>
+                                <Thumb Name="thumb" />
+                            </Track>
+                            <RepeatButton
+                                Background="Transparent"
+                                Classes="repeat"
+                                Focusable="False"
+                                Grid.Column="2"
+                                Height="16"
+                                Interval="55"
+                                MinWidth="30"
+                                Name="PART_LineDownButton"
+                                VerticalAlignment="Center"
+                                Width="16">
+                                <Path
+                                    Data="M190.06 414l163.12-139.78a24 24 0 000-36.44L190.06 98c-15.57-13.34-39.62-2.28-39.62 18.22v279.6c0 20.5 24.05 31.56 39.62 18.18z"
+                                    Fill="{TemplateBinding Foreground}"
+                                    Height="12"
+                                    HorizontalAlignment="Center"
+                                    Stretch="Fill"
+                                    VerticalAlignment="Center"
+                                    Width="12" />
+                            </RepeatButton>
+                        </Grid>
+                    </Border>
+                </ControlTemplate>
+            </Setter>
+        </Style>
+
+        <Style Selector="^:vertical">
+            <Setter Property="Width" Value="30" />
+            <Setter Property="Template">
+                <ControlTemplate>
+                    <Border
+                        Background="{DynamicResource WindowButtonBackgroundColor}"
+                        BorderBrush="{DynamicResource MainBorderColor}"
+                        BorderThickness="1,0,0,0"
+                        UseLayoutRounding="False">
+                        <Grid RowDefinitions="Auto,*,Auto">
+                            <RepeatButton
+                                Background="Transparent"
+                                Classes="repeat"
+                                Focusable="False"
+                                Grid.Row="0"
+                                HorizontalAlignment="Center"
+                                Interval="55"
+                                MinHeight="{StaticResource ScrollBarThickness}"
+                                Name="PART_LineUpButton">
+                                <Path
+                                    Data="F1 M512,512z M0,0z M414,321.94L274.22,158.82A24,24,0,0,0,237.78,158.82L98,321.94C84.66,337.51,95.72,361.56,116.22,361.56L395.82,361.56C416.32,361.56,427.38,337.51,414,321.94z"
+                                    Fill="{TemplateBinding Foreground}"
+                                    Height="16"
+                                    HorizontalAlignment="Center"
+                                    Stretch="Fill"
+                                    VerticalAlignment="Center"
+                                    Width="16" />
+                            </RepeatButton>
+                            <Track
+                                DeferThumbDrag="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
+                                Grid.Column="1"
+                                Grid.Row="1"
+                                IsDirectionReversed="True"
+                                Maximum="{TemplateBinding Maximum}"
+                                Minimum="{TemplateBinding Minimum}"
+                                Orientation="{TemplateBinding Orientation}"
+                                Value="{TemplateBinding Value,
+                                                        Mode=TwoWay}"
+                                ViewportSize="{TemplateBinding ViewportSize}">
+                                <Track.DecreaseButton>
+                                    <RepeatButton
+                                        Background="Transparent"
+                                        Classes="repeattrack"
+                                        Focusable="False"
+                                        Interval="55"
+                                        Name="PART_PageUpButton" />
+                                </Track.DecreaseButton>
+                                <Track.IncreaseButton>
+                                    <RepeatButton
+                                        Background="Transparent"
+                                        Classes="repeattrack"
+                                        Focusable="False"
+                                        Interval="55"
+                                        Name="PART_PageDownButton" />
+                                </Track.IncreaseButton>
+                                <Thumb Name="thumb" />
+                            </Track>
+                            <RepeatButton
+                                Background="Transparent"
+                                Classes="repeat"
+                                Focusable="False"
+                                Grid.Column="2"
+                                Grid.Row="2"
+                                HorizontalAlignment="Center"
+                                Interval="55"
+                                MinHeight="{StaticResource ScrollBarThickness}"
+                                Name="PART_LineDownButton">
+                                <Path
+                                    Data="F1 M512,512z M0,0z M98,190.06L237.78,353.18A24,24,0,0,0,274.22,353.18L414,190.06C427.34,174.49,416.28,150.44,395.78,150.44L116.18,150.44C95.6799999999999,150.44,84.6199999999999,174.49,97.9999999999999,190.06z"
+                                    Fill="{TemplateBinding Foreground}"
+                                    Height="16"
+                                    HorizontalAlignment="Center"
+                                    Stretch="Fill"
+                                    VerticalAlignment="Center"
+                                    Width="16" />
+                            </RepeatButton>
+                        </Grid>
+                    </Border>
+                </ControlTemplate>
+            </Setter>
+        </Style>
+
+        <Style Selector="^ /template/ Thumb#thumb">
+            <Setter Property="Background" Value="{DynamicResource MainBackgroundColor}" />
+            <Setter Property="BorderThickness" Value="1" />
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate>
+                        <Border
+                            Background="{TemplateBinding Background}"
+                            BorderBrush="{DynamicResource TertiaryBorderColor}"
+                            BorderThickness="1" />
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <Style Selector="^ /template/ Thumb#thumb:pointerover">
+            <Setter Property="Background" Value="{DynamicResource AccentColor}" />
+        </Style>
+        <Style Selector="^ /template/ Thumb#thumb:pressed">
+            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
+        </Style>
+        <Style Selector="^:horizontal /template/ Thumb#thumb">
+            <Setter Property="MinWidth" Value="{StaticResource ScrollBarThickness}" />
+            <Setter Property="Height" Value="16" />
+        </Style>
+        <Style Selector="^:vertical /template/ Thumb#thumb">
+            <Setter Property="MinHeight" Value="{DynamicResource ScrollBarThickness}" />
+            <Setter Property="Width" Value="16" />
+        </Style>
+        <Style Selector="^ /template/ RepeatButton.repeat">
+            <Setter Property="Padding" Value="2" />
+            <Setter Property="BorderThickness" Value="0" />
+        </Style>
+        <Style Selector="^ /template/ RepeatButton.repeattrack">
+            <Setter Property="Template">
+                <ControlTemplate>
+                    <Border Background="Transparent" />
+                </ControlTemplate>
+            </Setter>
+        </Style>
+
+        <Style Selector="^ /template/ RepeatButton &gt; Path">
+            <Setter Property="Fill" Value="{TemplateBinding Foreground}" />
+        </Style>
+
+        <Style Selector="^ /template/ RepeatButton:pointerover &gt; Path">
+            <Setter Property="Fill" Value="{DynamicResource AccentColor}" />
+        </Style>
+    </ControlTheme>
+</ResourceDictionary>

+ 2 - 0
src/PicView.Avalonia/PicViewTheme/Index.axaml

@@ -19,6 +19,8 @@
                 <ResourceInclude Source="Controls/FlyoutPresenter.axaml" />
                 <ResourceInclude Source="Controls/ListBox.axaml" />
                 <ResourceInclude Source="Controls/ListBoxItem.axaml" />
+                <ResourceInclude Source="Controls/MainScrollbar.axaml" />
+                <ResourceInclude Source="Controls/MainScrollViewer.axaml" />
                 <ResourceInclude Source="Controls/Menu.axaml" />
                 <ResourceInclude Source="Controls/MenuFlyoutPresenter.axaml" />
                 <ResourceInclude Source="Controls/NumericUpDown.axaml" />

+ 5 - 7
src/PicView.Avalonia/StartUp/QuickLoad.cs

@@ -52,6 +52,7 @@ public static class QuickLoad
             Task.Run(() => { NavigationManager.InitializeImageIterator(vm); }, cancellationTokenSource.Token),
             Task.Run(async () => imageModel = await ProgressiveImageLoader.LoadProgressivelyAsync(
                 fileInfo,vm, cancellationTokenSource.Token), cancellationTokenSource.Token));
+        vm.IsLoading = false;
         await RenderingFixes(vm, imageModel, null);
         SetPicViewerValues(vm, imageModel, fileInfo);
         if (TiffManager.IsTiff(imageModel.FileInfo.FullName))
@@ -138,13 +139,6 @@ public static class QuickLoad
             {
                 SetSize(vm, imageModel, secondaryModel);
             }
-            
-            if (Settings.Zoom.ScrollEnabled)
-            {
-                // Bad fix for scrolling
-                // TODO: Implement proper startup scrolling fix
-                Settings.Zoom.ScrollEnabled = false;
-            }
         }, DispatcherPriority.Send);
         
         if (Settings.Zoom.ScrollEnabled)
@@ -155,6 +149,10 @@ public static class QuickLoad
             await Dispatcher.UIThread.InvokeAsync(() => SetSize(vm, imageModel, secondaryModel), DispatcherPriority.Render);
             Settings.Zoom.ScrollEnabled = true;
             await Dispatcher.UIThread.InvokeAsync(() => SetSize(vm, imageModel, secondaryModel), DispatcherPriority.Send);
+            if (Settings.WindowProperties.AutoFit)
+            {
+                await Dispatcher.UIThread.InvokeAsync(() => WindowFunctions.CenterWindowOnScreen());
+            }
         }
     }
     

+ 2 - 2
src/PicView.Avalonia/Views/ImageViewer.axaml

@@ -15,7 +15,7 @@
         <vm:MainViewModel />
     </Design.DataContext>
     <LayoutTransformControl x:Name="ImageLayoutTransformControl">
-        <customControls:AutoScrollViewer
+        <customControls:MainScrollViewer
             Focusable="False"
             Height="{CompiledBinding PicViewer.ScrollViewerHeight,
                                      Mode=OneWay}"
@@ -45,6 +45,6 @@
                     UseLayoutRounding="True"
                     x:Name="MainImage" />
             </Border>
-        </customControls:AutoScrollViewer>
+        </customControls:MainScrollViewer>
     </LayoutTransformControl>
 </UserControl>

+ 4 - 3
src/PicView.Avalonia/WindowBehavior/WindowResizing.cs

@@ -100,9 +100,10 @@ public static class WindowResizing
             }
             else
             {
+                var scrollbarSize = Settings.Zoom.ScrollEnabled ? SizeDefaults.ScrollbarSize : 0;
                 vm.GalleryWidth = vm.RotationAngle is 90 or 270
-                    ? Math.Max(size.Height, SizeDefaults.WindowMinSize + 15)
-                    : Math.Max(size.Width, SizeDefaults.WindowMinSize + 15);
+                    ? Math.Max(size.Height + scrollbarSize, SizeDefaults.WindowMinSize + scrollbarSize)
+                    : Math.Max(size.Width + scrollbarSize, SizeDefaults.WindowMinSize + scrollbarSize);
             }
         }
         else
@@ -229,7 +230,7 @@ public static class WindowResizing
         }
         else
         {
-            size = ImageSizeCalculationHelper.GetImageSize(
+            size = ImageSizeCalculationHelper.GetSideBySideImageSize(
                 width,
                 height,
                 screenSize.WorkingAreaWidth,

+ 5 - 5
src/PicView.Core/Calculations/ImageSizeCalculationHelper.cs

@@ -16,7 +16,7 @@ public static class ImageSizeCalculationHelper
         return RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 165 : 215;
     }
 
-    public static ImageSize GetImageSize(double width,
+    public static ImageSize GetSideBySideImageSize(double width,
         double height,
         double monitorWidth,
         double monitorHeight,
@@ -134,7 +134,6 @@ public static class ImageSizeCalculationHelper
                 xHeight = height * aspectRatio;
 
                 scrollWidth = Math.Max(xWidth + SizeDefaults.ScrollbarSize, SizeDefaults.WindowMinSize + SizeDefaults.ScrollbarSize + Padding + 16);
-                scrollHeight = containerHeight - margin;
             }
             else
             {
@@ -142,8 +141,9 @@ public static class ImageSizeCalculationHelper
                 xHeight = height / width * xWidth;
                 
                 scrollWidth = containerWidth + SizeDefaults.ScrollbarSize;
-                scrollHeight = containerHeight - margin;
             }
+
+            scrollHeight = containerHeight - margin;
         }
         else
         {
@@ -184,11 +184,11 @@ public static class ImageSizeCalculationHelper
         }
 
         // Get sizes for both images
-        var firstSize = GetImageSize(width, height, monitorWidth, monitorHeight, monitorMinWidth, monitorMinHeight,
+        var firstSize = GetSideBySideImageSize(width, height, monitorWidth, monitorHeight, monitorMinWidth, monitorMinHeight,
             interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize, galleryHeight,
             containerWidth,
             containerHeight);
-        var secondSize = GetImageSize(secondaryWidth, secondaryHeight, monitorWidth, monitorHeight, monitorMinWidth,
+        var secondSize = GetSideBySideImageSize(secondaryWidth, secondaryHeight, monitorWidth, monitorHeight, monitorMinWidth,
             monitorMinHeight, interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize,
             galleryHeight,
             containerWidth, containerHeight);