Skip to content

Commit

Permalink
Fit pages to width setting and limit scaling. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed Feb 17, 2020
1 parent 5b381ac commit fe2547c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
18 changes: 18 additions & 0 deletions LRReader.Shared/Internal/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ public int SpacebarScroll
RaisePropertyChanged("SpacebarScroll");
}
}
public bool FitToWidth
{
get => SettingsStorage.GetObjectRoamed("FitToWidth", true);
set
{
SettingsStorage.StoreObjectRoamed("FitToWidth", value);
RaisePropertyChanged("FitToWidth");
}
}
public int FitScaleLimit
{
get => SettingsStorage.GetObjectLocal("FitScaleLimit", 100);
set
{
SettingsStorage.StoreObjectLocal("FitScaleLimit", value);
RaisePropertyChanged("FitScaleLimit");
}
}
public SettingsManager()
{
var profiles = SettingsStorage.GetObjectRoamed<string>("Profiles");
Expand Down
13 changes: 11 additions & 2 deletions LRReader.UWP.Core/Views/Tabs/Content/ArchiveTabContent.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private void ScrollViewer_DoubleTapped(object sender, DoubleTappedRoutedEventArg
var center = ttv.TransformPoint(new Point(0, 0));
var zoomFactor = (float)Math.Min(ScrollViewer.ViewportWidth / ReaderControl.ActualWidth, ScrollViewer.ViewportHeight / ReaderControl.ActualHeight);
if (Math.Abs(ScrollViewer.ZoomFactor - zoomFactor * Global.SettingsManager.BaseZoom) > 0.01)
ScrollViewer.ChangeView(null, null, zoomFactor * Global.SettingsManager.BaseZoom);
FitImages(false);
else
ScrollViewer.ChangeView(point.X - center.X * 2.0, point.Y - center.Y * 2.0, zoomFactor * Global.SettingsManager.ZoomedFactor);
}
Expand All @@ -296,7 +296,16 @@ private void FitImages(bool disableAnim)
{
if (ReaderControl.ActualWidth == 0 || ReaderControl.ActualHeight == 0)
return;
var zoomFactor = (float)Math.Min(ScrollViewer.ViewportWidth / ReaderControl.ActualWidth, ScrollViewer.ViewportHeight / ReaderControl.ActualHeight);
float zoomFactor;
if (Global.SettingsManager.FitToWidth)
{
zoomFactor = (float)Math.Min(ScrollViewer.ViewportWidth / ReaderControl.ActualWidth, Global.SettingsManager.FitScaleLimit * 0.01);
}
else
{
zoomFactor = (float)Math.Min(ScrollViewer.ViewportWidth / ReaderControl.ActualWidth, ScrollViewer.ViewportHeight / ReaderControl.ActualHeight);
}
System.Diagnostics.Debug.WriteLine(zoomFactor);
ScrollViewer.ChangeView(0, 0, zoomFactor * Global.SettingsManager.BaseZoom, disableAnim);
}

Expand Down
20 changes: 20 additions & 0 deletions LRReader.UWP.Core/Views/Tabs/Content/Settings/ReaderPivot.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@
Margin="0,0,0,10" Header="Read right-to-left"
IsOn="{x:Bind Data.SettingsManager.ReadRTL, Mode=TwoWay}"
ToolTipService.ToolTip="Reverses the pages read direction" />
<ToggleSwitch
Margin="0,0,0,10" Header="Fit pages to width"
IsOn="{x:Bind Data.SettingsManager.FitToWidth, Mode=TwoWay}"
ToolTipService.ToolTip="Scales pages into the full width of the window" />
<Grid Width="350" Visibility="{x:Bind Data.SettingsManager.FitToWidth, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Slider
Margin="0,0,0,10" Header="Fit page scale limit" Maximum="400"
Minimum="100" StepFrequency="5" TickFrequency="25.0"
TickPlacement="BottomRight" ToolTipService.ToolTip="Maximum scaling that can be applied to a page"
Value="{x:Bind Data.SettingsManager.FitScaleLimit, Mode=TwoWay}" />
<TextBlock
Grid.Column="1" Margin="0,10,0,0" HorizontalAlignment="Center"
VerticalAlignment="Center">
<Run Text="{x:Bind Data.SettingsManager.FitScaleLimit, Mode=OneWay}" />%
</TextBlock>
</Grid>
<ToggleSwitch
Margin="0,0,0,10" Header="Show two pages"
IsOn="{x:Bind Data.SettingsManager.TwoPages, Mode=TwoWay}"
Expand Down

0 comments on commit fe2547c

Please sign in to comment.