Skip to content

Commit 34d73b5

Browse files
sung-surookiejava
authored andcommitted
[Tizen] Add BorderDrawable (#224)
* Move to platform specific * Fix border handler for Tizen * Rename ToDrawable method * Fix border content layout * Fix BorderView * Apply rebase
1 parent 6a3a8f0 commit 34d73b5

File tree

8 files changed

+176
-69
lines changed

8 files changed

+176
-69
lines changed

src/Core/src/Graphics/PaintExtensions.Tizen.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ public static IDrawable ToDrawable(this Paint paint, PathF path)
66
{
77
return new BackgroundDrawable(paint, path);
88
}
9+
10+
public static IDrawable ToDrawable(this Paint paint, IBorder border)
11+
{
12+
return new BorderDrawable(paint, border);
13+
}
914
}
1015
}

src/Core/src/Handlers/Border/BorderHandler.Tizen.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace Microsoft.Maui.Handlers
44
{
5-
public partial class BorderHandler : ViewHandler<IBorder, ContentCanvas>
5+
public partial class BorderHandler : ViewHandler<IBorder, BorderView>
66
{
77
INativeViewHandler? _contentHandler;
88

9-
protected override ContentCanvas CreateNativeView()
9+
protected override BorderView CreateNativeView()
1010
{
1111
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a Page");
1212
_ = NativeParent ?? throw new InvalidOperationException($"{nameof(NativeParent)} cannot be null");
1313

14-
var view = new ContentCanvas(NativeParent, VirtualView)
14+
var view = new BorderView(NativeParent, VirtualView)
1515
{
1616
CrossPlatformMeasure = VirtualView.CrossPlatformMeasure,
1717
CrossPlatformArrange = VirtualView.CrossPlatformArrange
@@ -46,13 +46,12 @@ void UpdateContent()
4646
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
4747
_ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
4848

49-
NativeView.Children.Clear();
5049
_contentHandler?.Dispose();
5150
_contentHandler = null;
5251

5352
if (VirtualView.PresentedContent is IView view)
5453
{
55-
NativeView.Children.Add(view.ToNative(MauiContext));
54+
NativeView.Content = view.ToNative(MauiContext);
5655
if (view.Handler is INativeViewHandler thandler)
5756
{
5857
thandler?.SetParent(this);

src/Core/src/Handlers/View/ViewHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public virtual bool NeedsContainer
8383
{
8484
get
8585
{
86-
#if WINDOWS || TIZEN
86+
#if WINDOWS
8787
if(VirtualView is IBorder border)
8888
return border?.Shape != null || border?.Stroke != null;
8989

src/Core/src/Graphics/BackgroundDrawable.Tizen.cs renamed to src/Core/src/Platform/Tizen/BackgroundDrawable.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Microsoft.Maui.Graphics
1+
using Microsoft.Maui.Graphics;
2+
3+
namespace Microsoft.Maui
24
{
35
public class BackgroundDrawable : IDrawable
46
{
@@ -31,4 +33,4 @@ public void Draw(ICanvas canvas, RectangleF dirtyRect)
3133
canvas.RestoreState();
3234
}
3335
}
34-
}
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Microsoft.Maui.Graphics;
2+
3+
namespace Microsoft.Maui
4+
{
5+
public class BorderDrawable : IDrawable
6+
{
7+
Paint _paint;
8+
IBorder _border;
9+
10+
public BorderDrawable(Paint paint, IBorder border)
11+
{
12+
_paint = paint;
13+
_border = border;
14+
}
15+
16+
public void Draw(ICanvas canvas, RectangleF dirtyRect)
17+
{
18+
canvas.SaveState();
19+
20+
var borderPath = _border.Shape?.PathForBounds(dirtyRect) ?? null;
21+
if (borderPath != null)
22+
{
23+
canvas.MiterLimit = _border.StrokeMiterLimit;
24+
canvas.StrokeColor = _border.Stroke.ToColor();
25+
canvas.StrokeDashPattern = _border.StrokeDashPattern;
26+
canvas.StrokeLineCap = _border.StrokeLineCap;
27+
canvas.StrokeLineJoin = _border.StrokeLineJoin;
28+
canvas.StrokeSize = (float)_border.StrokeThickness;
29+
30+
canvas.DrawPath(borderPath);
31+
32+
canvas.SetFillPaint(_paint, dirtyRect);
33+
canvas.FillPath(borderPath);
34+
}
35+
36+
canvas.RestoreState();
37+
}
38+
}
39+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using ElmSharp;
3+
using Microsoft.Maui.Graphics;
4+
using Microsoft.Maui.Graphics.Skia.Views;
5+
using Tizen.UIExtensions.Common;
6+
7+
namespace Microsoft.Maui
8+
{
9+
public class BorderView : ContentCanvas, IWrapperViewCanvas
10+
{
11+
WrapperView _wrapperView;
12+
13+
public BorderView(EvasObject parent, IView view) : base(parent, view)
14+
{
15+
_wrapperView = new WrapperView(parent);
16+
_wrapperView.Show();
17+
Children.Add(_wrapperView);
18+
_wrapperView.Lower();
19+
Content?.RaiseTop();
20+
21+
LayoutUpdated += OnLayout;
22+
23+
}
24+
25+
public IShape? Clip
26+
{
27+
get
28+
{
29+
return _wrapperView.Clip;
30+
}
31+
set
32+
{
33+
_wrapperView.Clip = value;
34+
}
35+
}
36+
37+
38+
public IShadow? Shadow
39+
{
40+
get
41+
{
42+
return _wrapperView.Shadow;
43+
}
44+
set
45+
{
46+
_wrapperView.Shadow = value;
47+
}
48+
}
49+
50+
public EvasObject? Content
51+
{
52+
get
53+
{
54+
return _wrapperView.Content;
55+
}
56+
set
57+
{
58+
if (_wrapperView.Content != value)
59+
{
60+
if (_wrapperView.Content != null)
61+
{
62+
Children.Remove(_wrapperView);
63+
_wrapperView.Content = null;
64+
}
65+
_wrapperView.Content = value;
66+
if (_wrapperView.Content != null)
67+
{
68+
Children.Add(_wrapperView);
69+
_wrapperView.RaiseTop();
70+
}
71+
}
72+
_wrapperView.Content = value;
73+
}
74+
}
75+
76+
public IWrapperViewDrawables Drawables => _wrapperView.Drawables;
77+
78+
void OnLayout(object? sender, LayoutEventArgs e)
79+
{
80+
if (Content != null)
81+
{
82+
_wrapperView.Geometry = Geometry;
83+
}
84+
}
85+
}
86+
}

src/Core/src/Graphics/ShadowDrawable.Tizen.cs renamed to src/Core/src/Platform/Tizen/ShadowDrawable.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Microsoft.Maui.Graphics
1+
using Microsoft.Maui.Graphics;
2+
3+
namespace Microsoft.Maui
24
{
35
public class ShadowDrawable : IDrawable
46
{

src/Core/src/Platform/Tizen/StrokeExtensions.cs

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,125 +3,99 @@
33

44
namespace Microsoft.Maui
55
{
6-
// TODO : Need to impl
76
public static class StrokeExtensions
87
{
98
public static void UpdateStrokeShape(this EvasObject nativeView, IBorder border)
109
{
1110
var borderShape = border.Shape;
12-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
13-
14-
//if (background == null && borderShape == null)
15-
// return;
11+
var canvas = nativeView as IWrapperViewCanvas;
12+
if (canvas == null && borderShape == null)
13+
return;
1614

1715
nativeView.UpdateMauiDrawable(border);
1816
}
1917

2018
public static void UpdateStroke(this EvasObject nativeView, IBorder border)
2119
{
2220
var stroke = border.Stroke;
23-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
24-
25-
//if (background == null && stroke.IsNullOrEmpty())
26-
// return;
21+
var canvas = nativeView as IWrapperViewCanvas;
22+
if (canvas == null && stroke.IsNullOrEmpty())
23+
return;
2724

2825
nativeView.UpdateMauiDrawable(border);
2926
}
3027

3128
public static void UpdateStrokeThickness(this EvasObject nativeView, IBorder border)
3229
{
33-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
34-
//bool hasBorder = border.Shape != null && border.Stroke != null;
35-
36-
//if (background == null && !hasBorder)
37-
// return;
30+
var canvas = nativeView as IWrapperViewCanvas;
31+
bool hasBorder = border.Shape != null && border.Stroke != null;
32+
if (canvas == null && !hasBorder)
33+
return;
3834

3935
nativeView.UpdateMauiDrawable(border);
4036
}
4137

4238
public static void UpdateStrokeDashPattern(this EvasObject nativeView, IBorder border)
4339
{
4440
var strokeDashPattern = border.StrokeDashPattern;
45-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
46-
47-
//bool hasBorder = border.Shape != null && border.Stroke != null;
48-
49-
//if (background == null && !hasBorder && (strokeDashPattern == null || strokeDashPattern.Length == 0))
50-
// return;
41+
var canvas = nativeView as IWrapperViewCanvas;
42+
bool hasBorder = border.Shape != null && border.Stroke != null;
43+
if (canvas == null && !hasBorder && (strokeDashPattern == null || strokeDashPattern.Length == 0))
44+
return;
5145

5246
nativeView.UpdateMauiDrawable(border);
5347
}
5448

5549
public static void UpdateStrokeDashOffset(this EvasObject nativeView, IBorder border)
5650
{
57-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
58-
59-
//bool hasBorder = border.Shape != null && border.Stroke != null;
60-
61-
//if (background == null && !hasBorder)
62-
// return;
51+
var canvas = nativeView as IWrapperViewCanvas;
52+
bool hasBorder = border.Shape != null && border.Stroke != null;
53+
if (canvas == null && !hasBorder)
54+
return;
6355

6456
nativeView.UpdateMauiDrawable(border);
6557
}
6658

6759
public static void UpdateStrokeMiterLimit(this EvasObject nativeView, IBorder border)
6860
{
69-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
70-
71-
//bool hasBorder = border.Shape != null && border.Stroke != null;
72-
73-
//if (background == null && !hasBorder)
74-
// return;
61+
var canvas = nativeView as IWrapperViewCanvas;
62+
bool hasBorder = border.Shape != null && border.Stroke != null;
63+
if (canvas == null && !hasBorder)
64+
return;
7565

7666
nativeView.UpdateMauiDrawable(border);
7767
}
7868

7969
public static void UpdateStrokeLineCap(this EvasObject nativeView, IBorder border)
8070
{
81-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
82-
//bool hasBorder = border.Shape != null && border.Stroke != null;
83-
84-
//if (background == null && !hasBorder)
85-
// return;
71+
var canvas = nativeView as IWrapperViewCanvas;
72+
bool hasBorder = border.Shape != null && border.Stroke != null;
73+
if (canvas == null && !hasBorder)
74+
return;
8675

8776
nativeView.UpdateMauiDrawable(border);
8877
}
8978

9079
public static void UpdateStrokeLineJoin(this EvasObject nativeView, IBorder border)
9180
{
92-
//MauiDrawable? background = nativeView.Background as MauiDrawable;
93-
//bool hasBorder = border.Shape != null && border.Stroke != null;
94-
95-
//if (background == null && !hasBorder)
96-
// return;
81+
var canvas = nativeView as IWrapperViewCanvas;
82+
bool hasBorder = border.Shape != null && border.Stroke != null;
83+
if (canvas == null && !hasBorder)
84+
return;
9785

9886
nativeView.UpdateMauiDrawable(border);
9987
}
10088

10189
internal static void UpdateMauiDrawable(this EvasObject nativeView, IBorder border)
10290
{
10391
bool hasBorder = border.Shape != null && border.Stroke != null;
104-
10592
if (!hasBorder)
10693
return;
10794

108-
//MauiDrawable? mauiDrawable = nativeView.Background as MauiDrawable;
109-
110-
//if (mauiDrawable == null)
111-
//{
112-
// mauiDrawable = new MauiDrawable(nativeView.Context);
113-
114-
// nativeView.Background = mauiDrawable;
115-
//}
116-
117-
//mauiDrawable.SetBackground(border.Background);
118-
//mauiDrawable.SetBorderBrush(border.Stroke);
119-
//mauiDrawable.SetBorderWidth(border.StrokeThickness);
120-
//mauiDrawable.SetBorderDash(border.StrokeDashPattern, border.StrokeDashOffset);
121-
//mauiDrawable.SetBorderMiterLimit(border.StrokeMiterLimit);
122-
//mauiDrawable.SetBorderLineJoin(border.StrokeLineJoin);
123-
//mauiDrawable.SetBorderLineCap(border.StrokeLineCap);
124-
//mauiDrawable.SetBorderShape(border.Shape);
95+
if (nativeView is IWrapperViewCanvas canvas)
96+
{
97+
canvas.Drawables.BorderDrawable = border.Background?.ToDrawable(border) ?? null;
98+
}
12599
}
126100
}
127101
}

0 commit comments

Comments
 (0)