This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen] Added Fast Layout Opt-in (#13221)
- Loading branch information
1 parent
1d6d7bd
commit 6ea5fa9
Showing
7 changed files
with
448 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using ElmSharp; | ||
using EColor = ElmSharp.Color; | ||
using ERectangle = ElmSharp.Rectangle; | ||
|
||
namespace Xamarin.Forms.Platform.Tizen.Native | ||
{ | ||
public class EvasBox : Container | ||
{ | ||
Interop.CanvasBoxLayoutCallback _layoutCallback; | ||
Lazy<ERectangle> _rectangle; | ||
|
||
public event EventHandler<LayoutEventArgs> LayoutUpdated; | ||
|
||
public EvasBox(EvasObject parent) : base(parent) | ||
{ | ||
_rectangle = new Lazy<ERectangle>(() => | ||
{ | ||
var rectangle = new ERectangle(this) { AlignmentX = -1, AlignmentY = -1, WeightX = 1, WeightY = 1 }; | ||
Interop.evas_object_box_insert_at(Handle, rectangle, 0); | ||
rectangle.Lower(); | ||
rectangle.Show(); | ||
return rectangle; | ||
}); | ||
|
||
SetLayoutCallback(() => { NotifyOnLayout(); }); | ||
} | ||
|
||
public override EColor BackgroundColor | ||
{ | ||
get | ||
{ | ||
return _rectangle.Value.Color; | ||
} | ||
set | ||
{ | ||
_rectangle.Value.Color = value.IsDefault ? EColor.Transparent : value; | ||
} | ||
} | ||
|
||
public void PackEnd(EvasObject content) | ||
{ | ||
Interop.evas_object_box_append(Handle, content); | ||
AddChild(content); | ||
} | ||
|
||
public bool UnPack(EvasObject content) | ||
{ | ||
var ret = Interop.evas_object_box_remove(Handle, content); | ||
if (ret) | ||
RemoveChild(content); | ||
return ret; | ||
} | ||
|
||
public bool UnPackAll() | ||
{ | ||
var ret = Interop.evas_object_box_remove_all(Handle, true); | ||
if (ret) | ||
{ | ||
ClearChildren(); | ||
if (_rectangle.IsValueCreated) | ||
{ | ||
Interop.evas_object_box_append(Handle, _rectangle.Value); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
public void SetLayoutCallback(Action action) | ||
{ | ||
_layoutCallback = (obj, priv, data) => | ||
{ | ||
if (_rectangle.IsValueCreated) | ||
{ | ||
_rectangle.Value.Geometry = Geometry; | ||
} | ||
action(); | ||
}; | ||
Interop.evas_object_box_layout_set(Handle, _layoutCallback, IntPtr.Zero, null); | ||
} | ||
|
||
protected override IntPtr CreateHandle(EvasObject parent) | ||
{ | ||
return Interop.evas_object_box_add(Interop.evas_object_evas_get(parent.Handle)); | ||
} | ||
|
||
void NotifyOnLayout() | ||
{ | ||
if (null != LayoutUpdated) | ||
{ | ||
LayoutUpdated(this, new LayoutEventArgs() { Geometry = Geometry }); | ||
} | ||
} | ||
|
||
class Interop | ||
{ | ||
public const string LibEvas = "libevas.so.1"; | ||
|
||
public delegate void CanvasBoxLayoutCallback(IntPtr obj, IntPtr priv, IntPtr userData); | ||
|
||
public delegate void CanvasBoxDataFreeCallback(IntPtr data); | ||
|
||
[DllImport(LibEvas)] | ||
internal static extern IntPtr evas_object_box_add(IntPtr evas); | ||
|
||
[DllImport(LibEvas)] | ||
internal static extern IntPtr evas_object_evas_get(IntPtr obj); | ||
|
||
[DllImport(LibEvas)] | ||
internal static extern void evas_object_box_append(IntPtr obj, IntPtr child); | ||
|
||
[DllImport(LibEvas)] | ||
internal static extern void evas_object_box_insert_at(IntPtr obj, IntPtr child, int pos); | ||
|
||
[DllImport(LibEvas)] | ||
[return: MarshalAs(UnmanagedType.U1)] | ||
internal static extern bool evas_object_box_remove(IntPtr obj, IntPtr child); | ||
|
||
[DllImport(LibEvas)] | ||
[return: MarshalAs(UnmanagedType.U1)] | ||
internal static extern bool evas_object_box_remove_all(IntPtr obj, bool clear); | ||
|
||
[DllImport(LibEvas)] | ||
internal static extern void evas_object_box_layout_set(IntPtr obj, CanvasBoxLayoutCallback cb, IntPtr data, CanvasBoxDataFreeCallback dataFreeCb); | ||
|
||
[DllImport(LibEvas)] | ||
internal static extern void evas_object_box_layout_set(IntPtr obj, CanvasBoxLayoutCallback cb, IntPtr data, IntPtr dataFreeCb); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using ElmSharp; | ||
|
||
namespace Xamarin.Forms.Platform.Tizen.Native | ||
{ | ||
public class EvasFormsCanvas : EvasBox, IContainable<EvasObject> | ||
{ | ||
public EvasFormsCanvas(EvasObject parent) : base(parent) | ||
{ | ||
Initilize(); | ||
} | ||
|
||
readonly ObservableCollection<EvasObject> _children = new ObservableCollection<EvasObject>(); | ||
|
||
public new IList<EvasObject> Children | ||
{ | ||
get | ||
{ | ||
return _children; | ||
} | ||
} | ||
|
||
protected override void OnUnrealize() | ||
{ | ||
foreach (var child in _children) | ||
{ | ||
child.Unrealize(); | ||
} | ||
|
||
base.OnUnrealize(); | ||
} | ||
|
||
void Initilize() | ||
{ | ||
_children.CollectionChanged += (o, e) => | ||
{ | ||
if (e.Action == NotifyCollectionChangedAction.Add) | ||
{ | ||
foreach (var v in e.NewItems) | ||
{ | ||
var view = v as EvasObject; | ||
if (null != view) | ||
{ | ||
OnAdd(view); | ||
} | ||
} | ||
} | ||
else if (e.Action == NotifyCollectionChangedAction.Remove) | ||
{ | ||
foreach (var v in e.OldItems) | ||
{ | ||
var view = v as EvasObject; | ||
if (null != view) | ||
{ | ||
OnRemove(view); | ||
} | ||
} | ||
} | ||
else if (e.Action == NotifyCollectionChangedAction.Reset) | ||
{ | ||
OnRemoveAll(); | ||
} | ||
}; | ||
} | ||
|
||
void OnAdd(EvasObject view) | ||
{ | ||
PackEnd(view); | ||
} | ||
|
||
void OnRemove(EvasObject view) | ||
{ | ||
UnPack(view); | ||
} | ||
|
||
void OnRemoveAll() | ||
{ | ||
UnPackAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.