Skip to content

Commit

Permalink
chore: wip commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsashah45 committed Oct 17, 2024
1 parent ce59cfb commit b598c4c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public double MinZoomLevel
nameof(MaxZoomLevel),
typeof(double),
typeof(ZoomContentControl),
new PropertyMetadata(500d, OnMaxZoomLevelChanged));
new PropertyMetadata(10d, OnMaxZoomLevelChanged));

/// <summary>Gets or sets the maximum zoom level allowed.</summary>
public double MaxZoomLevel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Uno.Toolkit.UI;
[TemplatePart(Name = TemplateParts.Presenter, Type = typeof(ContentPresenter))]
[TemplatePart(Name = TemplateParts.VerticalScrollBar, Type = typeof(ScrollBar))]
[TemplatePart(Name = TemplateParts.HorizontalScrollBar, Type = typeof(ScrollBar))]
[TemplatePart(Name = TemplateParts.TranslateTransform, Type = typeof(TranslateTransform))]
public partial class ZoomContentControl : ContentControl
{
private static class TemplateParts
Expand All @@ -47,12 +48,16 @@ private static class TemplateParts
public const string Presenter = "PART_Presenter";
public const string HorizontalScrollBar = "PART_ScrollH";
public const string VerticalScrollBar = "PART_ScrollV";
public const string TranslateTransform = "PART_TranslateTransform";
}

// Fields
// Template parts
private ContentPresenter? _presenter;
private ScrollBar? _scrollV;
private ScrollBar? _scrollH;
private TranslateTransform? _translateTransform;

// Fields
private Point _lastPosition = new Point(0, 0);
private (bool Horizontal, bool Vertical) _movementDirection = (false, false);
private bool IsAllowedToWork => (IsEnabled && IsActive && _presenter is not null);
Expand Down Expand Up @@ -98,6 +103,7 @@ private async void OnVerticalOffsetChanged()
{
UpdateContentBoundsVisibility();
UpdateScrollVisibility();
UpdateTranslation();
await RaiseRenderedContentUpdated();
}

Expand Down Expand Up @@ -216,12 +222,32 @@ T FindTemplatePart<T>(string name) where T : class =>
_scrollV = FindTemplatePart<ScrollBar>(TemplateParts.VerticalScrollBar);
_scrollH = FindTemplatePart<ScrollBar>(TemplateParts.HorizontalScrollBar);

_translateTransform = FindTemplatePart<TranslateTransform>("PART_TranslateTransform");

if (_scrollH != null)
{
_scrollH.Scroll += (sender, e) => UpdateTranslation();
}

if (_scrollV != null)
{
_scrollV.Scroll += (sender, e) => UpdateTranslation();
}

ResetOffset();
ResetZoom();

RegisterToControlEvents();
}

private void UpdateTranslation()
{
if (_translateTransform != null && _scrollH != null && _scrollV != null)
{
_translateTransform.X = -_scrollH.Value;
_translateTransform.Y = _scrollV.Value;
}
}

// Event handlers
private void OnLoaded(object sender, RoutedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
CenterY="{TemplateBinding VerticalZoomCenter}"
ScaleX="{TemplateBinding ZoomLevel}"
ScaleY="{TemplateBinding ZoomLevel}" />
<TranslateTransform X="{TemplateBinding HorizontalOffset}"
Y="{TemplateBinding VerticalOffset}" />
<TranslateTransform x:Name="PART_TranslateTransform"/>
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
Expand All @@ -58,7 +57,7 @@
SmallChange="1"
Visibility="{TemplateBinding IsVerticalScrollBarVisible}"
ViewportSize="{TemplateBinding ViewportHeight}"
Value="{TemplateBinding VerticalOffset}" />
Value="{TemplateBinding VerticalScrollValue}" />
<!-- Horizontal ScrollBar -->
<ScrollBar x:Name="PART_ScrollH"
Grid.Row="1"
Expand Down

0 comments on commit b598c4c

Please sign in to comment.