using System.Runtime.InteropServices;
using System.Diagnostics;
using Tizen.NUI.Binding;
-using System.Collections.Generic;
namespace Tizen.NUI
{
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty FlexGrowProperty = null;
- private static Dictionary<View, AlignmentType> flexAlignmentSelfMap;
- private static Dictionary<View, float> flexAspectRatioMap;
- private static Dictionary<View, float> flexBasisMap;
- private static Dictionary<View, float> flexShrinkMap;
- private static Dictionary<View, float> flexGrowMap;
-
- private Dictionary<View, HandleRef> childHandleRefMap;
-
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
private bool swigCMemOwn;
private bool disposed;
}
else
{
- if (flexAlignmentSelfMap.TryGetValue(view, out var flexAlignmentSelf))
- {
- return flexAlignmentSelf;
- }
- else
- {
- return AlignmentType.Auto;
- }
+ _ = view ?? throw new ArgumentNullException(nameof(view));
+ return view.GetAttached<LayoutParams>()?.FlexAlignmentSelf ?? AlignmentType.Auto;
}
}
}
else
{
- if (flexAspectRatioMap.TryGetValue(view, out var flexAspectRatio))
- {
- return flexAspectRatio;
- }
- else
- {
- return FlexUndefined;
- }
+ _ = view ?? throw new ArgumentNullException(nameof(view));
+ return view.GetAttached<LayoutParams>()?.FlexAspectRatio ?? FlexUndefined;
}
}
}
else
{
- if (flexBasisMap.TryGetValue(view, out var flexBasis))
- {
- return flexBasis;
- }
- else
- {
- return FlexUndefined;
- }
+ _ = view ?? throw new ArgumentNullException(nameof(view));
+ return view.GetAttached<LayoutParams>()?.FlexBasis ?? FlexUndefined;
}
}
}
else
{
- if (flexShrinkMap.TryGetValue(view, out var flexShrink))
- {
- return flexShrink;
- }
- else
- {
- return 1.0f;
- }
+ _ = view ?? throw new ArgumentNullException(nameof(view));
+ return view.GetAttached<LayoutParams>()?.FlexShrink ?? 1.0f;
}
}
}
else
{
- if (flexGrowMap.TryGetValue(view, out var flexGrow))
- {
- return flexGrow;
- }
- else
- {
- return FlexUndefined;
- }
+ _ = view ?? throw new ArgumentNullException(nameof(view));
+ return view.GetAttached<LayoutParams>()?.FlexGrow ?? FlexUndefined;
}
}
_ = view ?? throw new ArgumentNullException(nameof(view));
if (value >= AlignmentType.Auto && value <= AlignmentType.Stretch)
{
- flexAlignmentSelfMap[view] = value;
- view.Layout?.RequestLayout();
+ var layoutParams = view.GetAttached<LayoutParams>();
+ if (layoutParams != null)
+ {
+ layoutParams.FlexAlignmentSelf = value;
+ }
+ else
+ {
+ view.SetAttached(new LayoutParams() { FlexAlignmentSelf = value });
+ }
}
}
}
_ = view ?? throw new ArgumentNullException(nameof(view));
if (value > 0)
{
- flexAspectRatioMap[view] = value;
- view.Layout?.RequestLayout();
+ var layoutParams = view.GetAttached<LayoutParams>();
+ if (layoutParams != null)
+ {
+ layoutParams.FlexAspectRatio = value;
+ }
+ else
+ {
+ view.SetAttached(new LayoutParams() { FlexAspectRatio = value });
+ }
}
}
}
_ = view ?? throw new ArgumentNullException(nameof(view));
if (value >= 0)
{
- flexBasisMap[view] = value;
- view.Layout?.RequestLayout();
+ var layoutParams = view.GetAttached<LayoutParams>();
+ if (layoutParams != null)
+ {
+ layoutParams.FlexBasis = value;
+ }
+ else
+ {
+ view.SetAttached(new LayoutParams() { FlexBasis = value });
+ }
}
}
}
_ = view ?? throw new ArgumentNullException(nameof(view));
if (value >= 0)
{
- flexShrinkMap[view] = value;
- view.Layout?.RequestLayout();
+ var layoutParams = view.GetAttached<LayoutParams>();
+ if (layoutParams != null)
+ {
+ layoutParams.FlexShrink = value;
+ }
+ else
+ {
+ view.SetAttached(new LayoutParams() { FlexShrink = value });
+ }
}
}
}
_ = view ?? throw new ArgumentNullException(nameof(view));
if (value >= 0)
{
- flexGrowMap[view] = value;
- view.Layout?.RequestLayout();
+ var layoutParams = view.GetAttached<LayoutParams>();
+ if (layoutParams != null)
+ {
+ layoutParams.FlexGrow = value;
+ }
+ else
+ {
+ view.SetAttached(new LayoutParams() { FlexGrow = value });
+ }
}
}
}
FlexGrowProperty = BindableProperty.CreateAttached("FlexGrow", typeof(float), typeof(FlexLayout), FlexUndefined,
validateValue: (bindable, value) => (float)value >= 0, propertyChanged: OnChildPropertyChanged);
}
- else
- {
- flexAlignmentSelfMap = new Dictionary<View, AlignmentType>();
- flexAspectRatioMap = new Dictionary<View, float>();
- flexBasisMap = new Dictionary<View, float>();
- flexShrinkMap = new Dictionary<View, float>();
- flexGrowMap = new Dictionary<View, float>();
- }
}
internal FlexLayout(global::System.IntPtr cPtr, bool cMemoryOwn)
swigCMemOwn = cMemoryOwn;
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
measureChildDelegate = new ChildMeasureCallback(measureChild);
- if (!NUIApplication.IsUsingXaml)
- {
- childHandleRefMap = new Dictionary<View, HandleRef>();
- }
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexLayout obj)
}
else
{
- childHandleRefMap[child.Owner] = childHandleRef;
+ var layoutParams = child.Owner.GetAttached<LayoutParams>();
+ if (layoutParams != null)
+ {
+ layoutParams.FlexItem = childHandleRef;
+ }
+ else
+ {
+ child.Owner.SetAttached(new LayoutParams() { FlexItem = childHandleRef });
+ }
}
}
{
LayoutItem layoutItem = LayoutChildren[i];
View Child = layoutItem?.Owner;
+ if (Child == null)
+ continue;
+
HandleRef childHandleRef;
if (NUIApplication.IsUsingXaml)
{
}
else
{
- childHandleRef = childHandleRefMap[Child];
+ childHandleRef = Child.GetAttached<LayoutParams>()?.FlexItem ?? new HandleRef();
}
- if (childHandleRef.Handle == IntPtr.Zero || Child == null)
+ if (childHandleRef.Handle == IntPtr.Zero)
continue;
AlignmentType flexAlignemnt = GetFlexAlignmentSelf(Child);
}
}
}
+
+ private class LayoutParams
+ {
+ /// <summary>
+ /// Constructs LayoutParams.
+ /// </summary>
+ public LayoutParams()
+ {
+ }
+
+ /// <summary>
+ /// Gets or sets the alignment of the flex layout item.
+ /// </summary>
+ public AlignmentType FlexAlignmentSelf
+ {
+ get;
+ set;
+ } = AlignmentType.Auto;
+
+ /// <summary>
+ /// Gets or sets the aspect ratio of the flex layout item.
+ /// </summary>
+ public float FlexAspectRatio
+ {
+ get;
+ set;
+ } = FlexUndefined;
+
+ /// <summary>
+ /// Gets or sets the basis of the flex layout item.
+ /// </summary>
+ public float FlexBasis
+ {
+ get;
+ set;
+ } = FlexUndefined;
+
+ /// <summary>
+ /// Gets or sets the shrink of the flex layout item.
+ /// </summary>
+ public float FlexShrink
+ {
+ get;
+ set;
+ } = 1.0f;
+
+ /// <summary>
+ /// Gets or sets the grow of the flex layout item.
+ /// </summary>
+ public float FlexGrow
+ {
+ get;
+ set;
+ } = FlexUndefined;
+
+ /// <summary>
+ /// Gets or sets the item handle of the flex layout item.
+ /// </summary>
+ public HandleRef FlexItem
+ {
+ get;
+ set;
+ } = new HandleRef();
+ }
} // FLexlayout
} // namesspace Tizen.NUI