Skip to content

Commit

Permalink
Merge pull request #1958 from IbraheemOsama/InfiniteCanvas
Browse files Browse the repository at this point in the history
Infinite canvas
  • Loading branch information
azchohfi authored May 23, 2018
2 parents d9d80c7 + 7a00d8f commit 3dc89b9
Show file tree
Hide file tree
Showing 38 changed files with 2,604 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
<Content Include="SamplePages\InAppNotification\InAppNotification.png" />
<Content Include="SamplePages\Incremental Loading Collection\icon.png" />
<Content Include="SamplePages\LayoutTransformControl\LayoutTransformControl.png" />
<Content Include="SamplePages\InfiniteCanvas\InfiniteCanvas.png" />
<Content Include="SamplePages\Light\LightBehavior.png" />
<Content Include="SamplePages\LinkedIn Service\LinkedInLogo.png" />
<Content Include="Assets\Helpers.png" />
Expand Down Expand Up @@ -507,6 +508,7 @@
</Content>
<Content Include="SamplePages\GazeInteraction\GazeInteractionCode.bind" />
<Content Include="SamplePages\GazeTracing\GazeTracingCode.bind" />
<Content Include="SamplePages\InfiniteCanvas\InfiniteCanvas.bind" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
Expand Down Expand Up @@ -603,6 +605,9 @@
<Compile Include="SamplePages\LayoutTransformControl\LayoutTransformControlPage.xaml.cs">
<DependentUpon>LayoutTransformControlPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\InfiniteCanvas\InfiniteCanvasPage.xaml.cs">
<DependentUpon>InfiniteCanvasPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\ListViewExtensions\ListViewExtensionsPage.xaml.cs">
<DependentUpon>ListViewExtensionsPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -970,6 +975,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\InfiniteCanvas\InfiniteCanvasPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\MarkdownParser\MarkdownParserPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid>
<controls:InfiniteCanvas Name="canvas" IsToolbarVisible="@[IsToolbarVisible:Bool:True]"/>
</Grid>
</Page>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.InfiniteCanvasPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System;
using System.Collections.Generic;
using Windows.Storage;
using Windows.UI.Popups;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// InfinteCanvas sample page.
/// </summary>
public sealed partial class InfiniteCanvasPage : Page, IXamlRenderListener
{
private InfiniteCanvas _infiniteCanvas;

public InfiniteCanvasPage()
{
InitializeComponent();
}

public void OnXamlRendered(FrameworkElement control)
{
_infiniteCanvas = control.FindChildByName("canvas") as InfiniteCanvas;
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

Shell.Current.RegisterNewCommand("Export & Save", async (sender, args) =>
{
if (_infiniteCanvas != null)
{
var savePicker = new Windows.Storage.Pickers.FileSavePicker
{
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary
};
savePicker.FileTypeChoices.Add("application/json", new List<string> { ".json" });
savePicker.SuggestedFileName = "Infinite Canvas Export";

StorageFile file = await savePicker.PickSaveFileAsync();
if (file != null)
{
var json = _infiniteCanvas.ExportAsJson();
CachedFileManager.DeferUpdates(file);
await FileIO.WriteTextAsync(file, json);
}
}
});

Shell.Current.RegisterNewCommand("Import and Load", async (sender, args) =>
{
if (_infiniteCanvas != null)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker
{
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary
};
picker.FileTypeFilter.Add(".json");
var file = await picker.PickSingleFileAsync();

if (file != null)
{
try
{
var json = await FileIO.ReadTextAsync(file);
_infiniteCanvas.ImportFromJson(json);
}
catch
{
var dialog = new MessageDialog("Invalid File");
await dialog.ShowAsync();
}
}
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<converters:ToolbarFormatActiveConverter x:Key="IsFormatMarkdown"
Format="MarkDown" />
Format="MarkDown" />
</Page.Resources>

<Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ private void AddCustomButton()
else
{
_toolbar.Formatter.Selected.Text = $"This was filled by {demoText} button ";

_toolbar.Formatter.Selected.CharacterFormat.Size = 40;
}
}
};
Expand Down
9 changes: 9 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@
"XamlCodeFile": "LayoutTransformControlXaml.bind",
"Icon": "/SamplePages/LayoutTransformControl/LayoutTransformControl.png",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/docs/controls/LayoutTransformControl.md"
},
{
"Name": "InfiniteCanvas",
"Type": "InfiniteCanvasPage",
"About": "InfiniteCanvas is a canvas that supports Infinite Scrolling, Ink, Text, Format Text, Zoom in/out, Redo, Undo, Export canvas data, Import canvas data.",
"CodeUrl": "https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InfiniteCanvas",
"XamlCodeFile": "InfiniteCanvas.bind",
"Icon": "/SamplePages/InfiniteCanvas/InfiniteCanvas.png",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/docs/controls/InfiniteCanvas.md"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
internal interface IInfiniteCanvasCommand
{
void Execute();

void Undo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System.Collections.Generic;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
internal class InfiniteCanvasClearAllCommand : IInfiniteCanvasCommand
{
private readonly List<IDrawable> _drawableList;
private IDrawable[] _storeList;

public InfiniteCanvasClearAllCommand(List<IDrawable> drawableList)
{
_drawableList = drawableList;
}

public void Execute()
{
_storeList = new IDrawable[_drawableList.Count];
for (int i = 0; i < _drawableList.Count; i++)
{
_storeList[i] = _drawableList[i];
}

_drawableList.Clear();
}

public void Undo()
{
foreach (var drawable in _storeList)
{
_drawableList.Add(drawable);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System.Collections.Generic;
using Windows.UI.Input.Inking;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
internal class InfiniteCanvasCreateInkCommand : IInfiniteCanvasCommand
{
private readonly List<IDrawable> _drawableList;
private readonly InkDrawable _drawable;

public InfiniteCanvasCreateInkCommand(List<IDrawable> drawableList, IReadOnlyList<InkStroke> strokes)
{
_drawable = new InkDrawable(strokes);
_drawableList = drawableList;
}

public void Execute()
{
_drawableList.Add(_drawable);
}

public void Undo()
{
_drawableList.Remove(_drawable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System.Collections.Generic;
using Windows.UI;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
internal class InfiniteCanvasCreateTextBoxCommand : IInfiniteCanvasCommand
{
private readonly List<IDrawable> _drawableList;
private readonly TextDrawable _drawable;

public InfiniteCanvasCreateTextBoxCommand(List<IDrawable> drawableList, double x, double y, double width, double height, int textFontSize, string text, Color color, bool isBold, bool isItalic)
{
_drawable = new TextDrawable(
x,
y,
width,
height,
textFontSize,
text,
color,
isBold,
isItalic);
_drawableList = drawableList;
}

public void Execute()
{
_drawableList.Add(_drawable);
}

public void Undo()
{
_drawableList.Remove(_drawable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System.Collections.Generic;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
internal class InfiniteCanvasEraseInkCommand : IInfiniteCanvasCommand
{
private readonly List<IDrawable> _drawableList;
private readonly IDrawable _drawable;

public InfiniteCanvasEraseInkCommand(List<IDrawable> drawableList, IDrawable drawable)
{
_drawable = drawable;
_drawableList = drawableList;
}

public void Execute()
{
_drawableList.Remove(_drawable);
}

public void Undo()
{
_drawableList.Add(_drawable);
}
}
}
Loading

0 comments on commit 3dc89b9

Please sign in to comment.