Size2D cellPadding = String.IsNullOrEmpty(buttonText.Text) ? new Size2D(0, 0) : itemSpacing;
#pragma warning restore CA2000
+ // If LayoutItems() is called by OnInitialize(), then layout would be null.
+ // Because layout is set by ApplyStyle() which is called after OnInitialize().
+ var layout = Layout as LinearLayout;
+ if (layout != null)
+ {
+ layout.HorizontalAlignment = itemHorizontalAlignment;
+ layout.VerticalAlignment = itemVerticalAlignment;
+ layout.CellPadding = cellPadding;
+ }
+
if (IconRelativeOrientation == IconOrientation.Left)
{
- Layout = new LinearLayout()
+ if (layout != null)
{
- LinearOrientation = LinearLayout.Orientation.Horizontal,
- HorizontalAlignment = itemHorizontalAlignment,
- VerticalAlignment = itemVerticalAlignment,
- CellPadding = cellPadding
- };
+ layout.LinearOrientation = LinearLayout.Orientation.Horizontal;
+ }
Add(buttonIcon);
Add(buttonText);
}
else if (IconRelativeOrientation == IconOrientation.Right)
{
- Layout = new LinearLayout()
+ if (layout != null)
{
- LinearOrientation = LinearLayout.Orientation.Horizontal,
- HorizontalAlignment = itemHorizontalAlignment,
- VerticalAlignment = itemVerticalAlignment,
- CellPadding = cellPadding
- };
+ layout.LinearOrientation = LinearLayout.Orientation.Horizontal;
+ }
Add(buttonText);
Add(buttonIcon);
}
else if (IconRelativeOrientation == IconOrientation.Top)
{
- Layout = new LinearLayout()
+ if (layout != null)
{
- LinearOrientation = LinearLayout.Orientation.Vertical,
- HorizontalAlignment = itemHorizontalAlignment,
- VerticalAlignment = itemVerticalAlignment,
- CellPadding = cellPadding
- };
+ layout.LinearOrientation = LinearLayout.Orientation.Vertical;
+ }
Add(buttonIcon);
Add(buttonText);
}
else if (IconRelativeOrientation == IconOrientation.Bottom)
{
- Layout = new LinearLayout()
+ if (layout != null)
{
- LinearOrientation = LinearLayout.Orientation.Vertical,
- HorizontalAlignment = itemHorizontalAlignment,
- VerticalAlignment = itemVerticalAlignment,
- CellPadding = cellPadding
- };
+ layout.LinearOrientation = LinearLayout.Orientation.Vertical;
+ }
Add(buttonText);
Add(buttonIcon);
{
TextColor = new Color("#FDFDFD"),
PixelSize = 24,
- }
+ },
+ Layout = new LinearLayout()
+ {
+ LinearOrientation = LinearLayout.Orientation.Horizontal,
+ HorizontalAlignment = HorizontalAlignment.Center,
+ VerticalAlignment = VerticalAlignment.Center,
+ CellPadding = new Size2D(8, 8),
+ },
});
// CheckBox base style
private Selector<Rectangle> backgroundImageBorderSelector;
private Selector<Color> colorSelector;
private VisualTransformPolicyType? cornerRadiusPolicy;
+ private LayoutItem layout;
static ViewStyle() { }
public bool SolidNull { get; set; } = false;
/// <summary>
+ /// Layout to position the View's children.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public LayoutItem Layout
+ {
+ get => (LayoutItem)GetValue(LayoutProperty);
+ set => SetValue(LayoutProperty, value);
+ }
+
+ /// <summary>
/// HashSet of dirty properties. Internal use only.
/// </summary>
internal HashSet<BindableProperty> DirtyProperties { get; private set; }
if (destinationProperty != null)
{
- InternalSetValue(destinationProperty, sourceValue);
+ if (sourceProperty.PropertyName.Equals("Layout") && (sourceValue is LayoutItem layout))
+ {
+ InternalSetValue(destinationProperty, layout.Clone());
+ }
+ else
+ {
+ InternalSetValue(destinationProperty, sourceValue);
+ }
}
}
var buttonStyle = (ViewStyle)bindable;
return buttonStyle.isEnabled;
});
+
+ /// <summary> Bindable property of Layout.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty LayoutProperty = BindableProperty.Create(nameof(Layout), typeof(LayoutItem), typeof(ViewStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ ((ViewStyle)bindable).layout = (LayoutItem)newValue;
+ }, defaultValueCreator: (bindable) => ((ViewStyle)bindable).layout);
}
}
if (destinationProperty != null)
{
- InternalSetValue(destinationProperty, sourceValue);
+ if (sourceProperty.PropertyName.Equals("Layout") && (sourceValue is LayoutItem layout))
+ {
+ InternalSetValue(destinationProperty, layout.Clone());
+ }
+ else
+ {
+ InternalSetValue(destinationProperty, sourceValue);
+ }
}
}
}
*
*/
+using System.ComponentModel;
+
namespace Tizen.NUI
{
/// <summary>
{
}
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override LayoutItem Clone()
+ {
+ var layout = new AbsoluteLayout();
+
+ foreach (var prop in layout.GetType().GetProperties())
+ {
+ if (prop.GetSetMethod() != null)
+ {
+ prop.SetValue(layout, this.GetType().GetProperty(prop.Name).GetValue(this));
+ }
+ }
+
+ return layout;
+ }
+
/// <summary>
/// Measure the layout and its content to determine the measured width and the measured height.<br />
/// </summary>
Absolute
}
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override LayoutItem Clone()
+ {
+ var layout = new FlexLayout();
+
+ foreach (var prop in layout.GetType().GetProperties())
+ {
+ if (prop.GetSetMethod() != null)
+ {
+ prop.SetValue(layout, this.GetType().GetProperty(prop.Name).GetValue(this));
+ }
+ }
+
+ return layout;
+ }
+
private void measureChild(global::System.IntPtr childPtr, float width, int measureModeWidth, float height, int measureModeHeight, out MeasuredSize measureSize)
{
// We need to measure child layout
/// <since_tizen> 8 </since_tizen>
End = 2,
}
+
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override LayoutItem Clone()
+ {
+ var layout = new GridLayout();
+
+ foreach (var prop in layout.GetType().GetProperties())
+ {
+ if (prop.GetSetMethod() != null)
+ {
+ prop.SetValue(layout, this.GetType().GetProperty(prop.Name).GetValue(this));
+ }
+ }
+
+ return layout;
+ }
}
// Extension Method of GridLayout.Alignment.
{
get
{
- return Owner.SuggestedMinimumWidth;
+ return (Owner != null) ? Owner.SuggestedMinimumWidth : new LayoutLength(0);
}
}
{
get
{
- return Owner.SuggestedMinimumHeight;
+ return (Owner != null) ? Owner.SuggestedMinimumHeight : new LayoutLength(0);
}
}
}
}
}
+
+ /// <summary>
+ /// Creates a cloned LayoutItem.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public virtual LayoutItem Clone()
+ {
+ var layout = new LayoutItem();
+
+ foreach (var prop in layout.GetType().GetProperties())
+ {
+ if (prop.GetSetMethod() != null)
+ {
+ prop.SetValue(layout, this.GetType().GetProperty(prop.Name).GetValue(this));
+ }
+ }
+
+ return layout;
+ }
}
}
{
}
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override LayoutItem Clone()
+ {
+ var layout = new LinearLayout();
+
+ foreach (var prop in layout.GetType().GetProperties())
+ {
+ if (prop.GetSetMethod() != null)
+ {
+ prop.SetValue(layout, this.GetType().GetProperty(prop.Name).GetValue(this));
+ }
+ }
+
+ return layout;
+ }
+
/// <summary>
/// Measure the layout and its content to determine the measured width and the measured height.
/// </summary>
public static void SetFillVertical(View view, bool value) => SetAttachedValue(view, FillVerticalProperty, value);
/// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override LayoutItem Clone()
+ {
+ var layout = new RelativeLayout();
+
+ foreach (var prop in layout.GetType().GetProperties())
+ {
+ if (prop.GetSetMethod() != null)
+ {
+ prop.SetValue(layout, this.GetType().GetProperty(prop.Name).GetValue(this));
+ }
+ }
+
+ return layout;
+ }
+
+ /// <inheritdoc/>
/// <since_tizen> 9 </since_tizen>
protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
{