Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ZoomContentControl as a stand alone control in Toolkit #1249

Merged
merged 30 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d5dfef1
feat: ZoomContentControl is a stand alone control in Toolkit now
vatsashah45 Sep 18, 2024
78f7f7b
feat: ZoomContentControl Sample
vatsashah45 Sep 19, 2024
54503df
fix: ZoomContentControl Sample
vatsashah45 Sep 23, 2024
768501b
docs: ZoomContentControl
vatsashah45 Sep 23, 2024
67c3f5a
fix: ZoomContentControl Sample
vatsashah45 Sep 24, 2024
d706f50
chore: resolving comments
vatsashah45 Sep 24, 2024
92fb0d9
chore: misc changes
vatsashah45 Sep 24, 2024
beabc6b
chore: renaming zoomcontentcontrol
vatsashah45 Sep 24, 2024
561f7a5
chore: formatting docs
vatsashah45 Sep 25, 2024
cae0d71
chore: ZoomContentControl Tests
vatsashah45 Sep 25, 2024
b8b0f52
chore: resolving comments
vatsashah45 Sep 27, 2024
05943e1
chore: resolving comments
vatsashah45 Sep 27, 2024
524839e
chore: refactor properties into separate file
Xiaoy312 Oct 3, 2024
81f4bc1
chore: refactor ZoomContentControl.cs
vatsashah45 Oct 4, 2024
6fb19a6
fix: ci build
vatsashah45 Oct 4, 2024
7194825
chore: refactor
Xiaoy312 Oct 10, 2024
d1ddfee
chore: refactor
vatsashah45 Oct 10, 2024
94a3a0a
chore: xml comments for HorizontalScrollValue
vatsashah45 Oct 10, 2024
fc2af3b
chore: removed VerticalScrollValue
vatsashah45 Oct 13, 2024
073320d
fix: VerticalScrollValue and tests
vatsashah45 Oct 14, 2024
dce93da
chore: resolving comments
vatsashah45 Oct 14, 2024
ce59cfb
chore: resolving comments
vatsashah45 Oct 15, 2024
0be5c7a
chore: set default MaxZoomLevel to 10
Xiaoy312 Oct 17, 2024
f8e4153
chore: minor refactor
Xiaoy312 Oct 17, 2024
3b554cd
chore: ZoomContentControl refactor/cleanup
Xiaoy312 Oct 22, 2024
14a373e
chore: update docs and private properties
vatsashah45 Oct 22, 2024
19aaee6
fix: RaiseRenderedContentUpdated being called twice
vatsashah45 Oct 22, 2024
3fbb235
chore: add mouse wheel zooming
Xiaoy312 Oct 23, 2024
beb4d12
chore: bugfixes
Xiaoy312 Oct 23, 2024
4f68669
chore: fix build
Xiaoy312 Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions doc/controls/ZoomContentControl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
uid: Toolkit.Controls.ZoomContentControl
---

# ZoomContentControl

> [!TIP]
> This guide covers details for the `ZoomContentControl`. If you are just getting started with the Uno Toolkit UI Library, please see our [general getting started](../getting-started.md) page to make sure you have the correct setup in place.

## Summary

`ZoomContentControl` allows you to display content that can be zoomed in and out, as well as panned. It is especially useful for scenarios such as viewing large images, maps, or documents where users need control over zoom levels and panning.

### C\#

```csharp
public partial class ZoomContentControl : Control
```

### XAML

```xml
xmlns:utu="using:Uno.Toolkit.UI"
...

<utu:ZoomContentControl ZoomLevel="1.5"
MinZoomLevel="0.5"
MaxZoomLevel="3.0"
IsZoomAllowed="True"
IsPanAllowed="True">
<utu:ZoomContentControl.Content>
<Image Source="ms-appx:///Assets/Media/LargeMedia.svg"
Stretch="Uniform" />
</utu:ZoomContentControl.Content>
</utu:ZoomContentControl>
```

### Inheritance

`Object` &#8594; `DependencyObject` &#8594; `UIElement` &#8594; `FrameworkElement` &#8594; `Control` &#8594; `ContentControl` &#8594; `ZoomContentControl`

### Constructors

| Constructor | Description |
|----------------|-------------------------------------------------------|
| `ZoomContentControl()` | Initializes a new instance of the `ZoomContentControl` class. |

### Properties
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved

| Property | Type | Description |
|------------------------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ZoomLevel` | `double` | Gets or sets the current zoom level for the content. |
| `MinZoomLevel` | `double` | Gets or sets the minimum zoom level allowed for the content. |
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
| `MaxZoomLevel` | `double` | Gets or sets the maximum zoom level allowed for the content |
| `isZoomAllowed` | `bool` | Gets or sets the value indicating whether zooming is allowed. |
| `IsPanAllowed` | `bool` | Gets or sets the value indicating whether panning is allowed. |
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
| `HorizontalOffest` | `double` | Gets or sets the horizontal offset for panning. |
| `VerticalOffset` | `double` | Gets or sets the vertical offset for panning. |
| `HorizontalZoomCenter` | `double` | Gets or sets the horizontal center point of the zooming operation. |
| `VerticalZoomCenter` | `double` | Gets or sets the vertical center point of the zooming operation. |
| `ScaleWheelRatio` | `double` | Gets or sets the ratio for scaling zoom level when using a mouse wheel. |
| `PanWheelRatio` | `double` | Gets or sets the ratio for panning when using a mouse wheel. |
| `ResetWhenNotActive` | `bool` | Gets or sets a value indicating whether the zoom and pan should reset when the control is not active. |

### Methods

| Method | Return Type | Description |
|-----------------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ResetZoom()` | `void` | Resets the zoom level to it's default value. |
| `ResetOffset()` | `void` | Resets the horizontal and vertical offset to it's default value. |
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
| `ZoomToCanvas()` | `void` | Adjust the zoom level so that the content fits within the available space. |
| `Centralize()` | `void` | Centers the content within the available space. |
2 changes: 2 additions & 0 deletions doc/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
href: controls/ShadowContainer.md
- name: TabBar and TabBarItem
href: controls/TabBarAndTabBarItem.md
- name: ZoomContentControl
href: controls/ZoomContentControl.md
# ***************** Reference\Helpers *******************
- name: Helpers
items:
Expand Down
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Page x:Class="Uno.Toolkit.Samples.Content.Controls.ZoomContentControlSamplePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Uno.Toolkit.Samples.Content.Controls"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:sample="using:Uno.Toolkit.Samples"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel Padding="0,20" Spacing="20">
<TextBlock Text="ZoomContentControl Sample"
Style="{StaticResource TitleLarge}" />

<utu:ZoomContentControl x:Name="ZoomContent"
Width="400"
Height="300"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ZoomLevel="1.5"
MinZoomLevel="0.5"
MaxZoomLevel="3.0"
IsZoomAllowed="True"
IsPanAllowed="True">
<utu:ZoomContentControl.Content>
<Image Source="ms-appx:///Assets/Media/LargeMedia.svg"
Stretch="Uniform" />
</utu:ZoomContentControl.Content>
</utu:ZoomContentControl>

<StackPanel Orientation="Horizontal" Spacing="12" HorizontalAlignment="Center">
<Button Content="Zoom In"
Click="OnZoomInClick" />
<Button Content="Zoom Out"
Click="OnZoomOutClick" />
<Button Content="Reset"
Click="OnResetClick" />
</StackPanel>
</StackPanel>

</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.Toolkit.Samples.Entities;
using Windows.Foundation;
using Windows.Foundation.Collections;

#if IS_WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
#else
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
#endif


namespace Uno.Toolkit.Samples.Content.Controls
{
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
[SamplePage(SampleCategory.Controls, "ZoomContentControl")]
public sealed partial class ZoomContentControlSamplePage : Page
{
public ZoomContentControlSamplePage()
{
this.InitializeComponent();
}

private void OnZoomInClick(object sender, RoutedEventArgs e)
{
if (ZoomContent.ZoomLevel < ZoomContent.MaxZoomLevel)
{
ZoomContent.ZoomLevel += 0.2;
}
}

private void OnZoomOutClick(object sender, RoutedEventArgs e)
{
if (ZoomContent.ZoomLevel > ZoomContent.MinZoomLevel)
{
ZoomContent.ZoomLevel -= 0.2;
}
}

private void OnResetClick(object sender, RoutedEventArgs e)
{
ZoomContent.ResetZoom();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\VisualStateManagerExtensionsSamplePage.xaml.cs">
<DependentUpon>VisualStateManagerExtensionsSamplePage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\ZoomContentControlSamplePage.xaml.cs">
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
<DependentUpon>ZoomContentControlSamplePage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Helpers\BindingExtensionsSamplePage.xaml.cs">
<DependentUpon>BindingExtensionsSamplePage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -317,6 +320,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\Controls\ZoomContentControlSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\Helpers\BindingExtensionsSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -583,4 +590,4 @@
<Content Include="$(MSBuildThisFileDirectory)Assets\Media\SmallMedia.scale-400.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\UnoLogo.png" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ctl="using:Uno.Toolkit.UI">
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved

<Style x:Key="DefaultZoomContentControlStyle"
TargetType="ctl:ZoomContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ctl:ZoomContentControl">
<Grid x:Name="PART_RootGrid"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Canvas x:Name="PART_Canvas">
<ContentPresenter x:Name="PART_Presenter"
Grid.Row="0"
Grid.Column="0"
Margin="0"
Padding="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}">
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
<ContentPresenter.RenderTransform>
<TransformGroup>
<ScaleTransform CenterX="{TemplateBinding HorizontalZoomCenter}"
CenterY="{TemplateBinding VerticalZoomCenter}"
ScaleX="{TemplateBinding ZoomLevel}"
ScaleY="{TemplateBinding ZoomLevel}" />
<TranslateTransform X="{TemplateBinding HorizontalOffset}"
Y="{TemplateBinding VerticalOffset}" />
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
</Canvas>
<!-- Vertical ScrollBar -->
<ScrollBar x:Name="PART_ScrollV"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Stretch"
IndicatorMode="MouseIndicator"
LargeChange="10"
Maximum="{TemplateBinding VerticalMaxScroll}"
Minimum="{TemplateBinding VerticalMinScroll}"
Orientation="Vertical"
SmallChange="1"
Visibility="{TemplateBinding IsVerticalScrollBarVisible}"
ViewportSize="{TemplateBinding ViewPortHeight}"
Value="{TemplateBinding VerticalScrollValue}" />
vatsashah45 marked this conversation as resolved.
Show resolved Hide resolved
<!-- Horizontal ScrollBar -->
<ScrollBar x:Name="PART_ScrollH"
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
IndicatorMode="MouseIndicator"
LargeChange="10"
Maximum="{TemplateBinding HorizontalMaxScroll}"
Minimum="{TemplateBinding HorizontalMinScroll}"
Orientation="Horizontal"
SmallChange="1"
Visibility="{TemplateBinding IsHorizontalScrollBarVisible}"
ViewportSize="{TemplateBinding ViewPortWidth}"
Value="{TemplateBinding HorizontalScrollValue}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style BasedOn="{StaticResource DefaultZoomContentControlStyle}"
TargetType="ctl:ZoomContentControl" />

</ResourceDictionary>
Loading
Loading