Skip to content

Commit

Permalink
Merge pull request #2458 from eng-myousif/mo_youssef/enable_extending…
Browse files Browse the repository at this point in the history
…_drawable_control_with_custom_canvas

Make use of the virtual method `CreateControl` on wpf `DrawableHandler`
  • Loading branch information
cwensley authored Apr 16, 2023
2 parents 2c752dd + d02c3ba commit ea1d236
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Eto.Wpf/Forms/Controls/DrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

namespace Eto.Wpf.Forms.Controls
{
public class DrawableHandler : WpfPanel<swc.Canvas, Drawable, Drawable.ICallback>, Drawable.IHandler
public class DrawableHandler : DrawableHandler<swc.Canvas, Drawable, Drawable.ICallback> { }

public class DrawableHandler<TControl, TWidget, TCallback> : WpfPanel<TControl, TWidget, TCallback>, Drawable.IHandler
where TControl : swc.Canvas
where TWidget : Drawable
where TCallback : Drawable.ICallback
{
bool tiled;
sw.FrameworkElement content;
Expand Down Expand Up @@ -51,9 +56,9 @@ public Size TileSize
}
}

class EtoMainCanvas : swc.Canvas
public class EtoMainCanvas : swc.Canvas
{
public DrawableHandler Handler { get; set; }
public DrawableHandler<TControl, TWidget, TCallback> Handler { get; set; }

protected override void OnMouseDown(sw.Input.MouseButtonEventArgs e)
{
Expand Down Expand Up @@ -111,7 +116,7 @@ protected override sw.Size ArrangeOverride(sw.Size arrangeSize)
class EtoTile : sw.FrameworkElement
{
Rectangle bounds;
public DrawableHandler Handler { get; set; }
public DrawableHandler<TControl, TWidget, TCallback> Handler { get; set; }

public Rectangle Bounds
{
Expand Down Expand Up @@ -163,18 +168,26 @@ public override void OnUnLoad(EventArgs e)
UnRegisterScrollable();
}

public void Create()
protected override TControl CreateControl()
{
Control = new EtoMainCanvas
return new EtoMainCanvas
{
Handler = this,
SnapsToDevicePixels = true,
FocusVisualStyle = null,
Background = swm.Brushes.Transparent
};
} as TControl;
}

protected override void Initialize()
{
base.Initialize();

Control.Loaded += Control_Loaded;
}

public void Create() { }

public void Create(bool largeCanvas)
{
AllowTiling = largeCanvas;
Expand Down

0 comments on commit ea1d236

Please sign in to comment.