public class LayoutItem : IDisposable
{
private bool disposed = false;
- static bool LayoutDebugFrameData = false; // Debug flag
- private MeasureSpecification OldWidthMeasureSpec; // Store measure specification to compare against later
- private MeasureSpecification OldHeightMeasureSpec; // Store measure specification to compare against later
+ private MeasureSpecification oldWidthMeasureSpec; // Store measure specification to compare against later
+ private MeasureSpecification oldHeightMeasureSpec; // Store measure specification to compare against later
- private LayoutFlags Flags = LayoutFlags.None;
+ private LayoutFlags flags = LayoutFlags.None;
- private ILayoutParent Parent;
+ private ILayoutParent parent;
- LayoutData _layoutPositionData;
+ LayoutData layoutPositionData;
- private Extents _padding;
- private Extents _margin;
+ private Extents padding;
+ private Extents margin;
private bool parentReplacement = false;
private bool setPositionByLayout = true;
{
get
{
- return _margin;
+ return margin;
}
set
{
- _margin = value;
+ margin = value;
RequestLayout();
}
}
{
get
{
- return _padding;
+ return padding;
}
set
{
- _padding = value;
+ padding = value;
RequestLayout();
}
}
/// <param name="parent">Parent to set on this Layout.</param>
internal void SetParent(ILayoutParent parent)
{
- Parent = parent as LayoutGroup;
+ this.parent = parent as LayoutGroup;
}
/// <summary>
OnUnparent();
// Remove myself from parent
- Parent?.Remove(this);
+ parent?.Remove(this);
// Remove parent reference
- Parent = null;
+ parent = null;
// Lastly, clear layout from owning View.
Owner?.ResetLayout();
private void Initialize()
{
LayoutWithTransition = false;
- _layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0);
- _padding = new Extents(0, 0, 0, 0);
- _margin = new Extents(0, 0, 0, 0);
+ layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0);
+ padding = new Extents(0, 0, 0, 0);
+ margin = new Extents(0, 0, 0, 0);
}
/// <summary>
/// <since_tizen> 6 </since_tizen>
public void Measure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
{
+ OnMeasure(widthMeasureSpec, heightMeasureSpec);
+ OnMeasureIndependentChildren(widthMeasureSpec, heightMeasureSpec);
+ flags = flags | LayoutFlags.LayoutRequired;
+ flags &= ~LayoutFlags.ForceLayout;
+
+ oldWidthMeasureSpec = widthMeasureSpec;
+ oldHeightMeasureSpec = heightMeasureSpec;
+ }
+
+ internal bool NeedsLayout(float widthSize, float heightSize, MeasureSpecification.ModeType widthMode, MeasureSpecification.ModeType heightMode)
+ {
+ if (LayoutRequested)
+ {
+ return true;
+ }
+
// Check if relayouting is required.
- bool specChanged = (widthMeasureSpec.Size != OldWidthMeasureSpec.Size) ||
- (heightMeasureSpec.Size != OldHeightMeasureSpec.Size) ||
- (widthMeasureSpec.Mode != OldWidthMeasureSpec.Mode) ||
- (heightMeasureSpec.Mode != OldHeightMeasureSpec.Mode);
+ bool specChanged = (widthSize != oldWidthMeasureSpec.Size.AsDecimal()) || (widthMode != oldWidthMeasureSpec.Mode) ||
+ (heightSize != oldHeightMeasureSpec.Size.AsDecimal()) || (heightMode != oldHeightMeasureSpec.Mode);
- bool isSpecExactly = (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly) &&
- (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly);
+ bool isSpecExactly = (widthMode == MeasureSpecification.ModeType.Exactly) &&
+ (heightMode == MeasureSpecification.ModeType.Exactly);
- bool matchesSpecSize = (MeasuredWidth.Size == widthMeasureSpec.Size) &&
- (MeasuredHeight.Size == heightMeasureSpec.Size);
+ bool matchesSpecSize = (MeasuredWidth.Size.AsDecimal() == widthSize) && (MeasuredHeight.Size.AsDecimal() == heightSize);
bool needsLayout = specChanged && (!isSpecExactly || !matchesSpecSize);
- needsLayout = needsLayout || ((Flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout);
- if (needsLayout)
- {
- OnMeasure(widthMeasureSpec, heightMeasureSpec);
- OnMeasureIndependentChildren(widthMeasureSpec, heightMeasureSpec);
- Flags = Flags | LayoutFlags.LayoutRequired;
- Flags &= ~LayoutFlags.ForceLayout;
- }
- OldWidthMeasureSpec = widthMeasureSpec;
- OldHeightMeasureSpec = heightMeasureSpec;
+ return needsLayout;
}
/// <summary>
bottom.AsRoundedValue(), independent);
// Check if Measure needed before Layouting
- if (changed || ((Flags & LayoutFlags.LayoutRequired) == LayoutFlags.LayoutRequired))
+ if (changed || ((flags & LayoutFlags.LayoutRequired) == LayoutFlags.LayoutRequired))
{
OnLayout(changed, left, top, right, bottom);
OnLayoutIndependentChildren(changed, left, top, right, bottom);
// Clear flag
- Flags &= ~LayoutFlags.LayoutRequired;
+ flags &= ~LayoutFlags.LayoutRequired;
}
}
/// <since_tizen> 6 </since_tizen>
public ILayoutParent GetParent()
{
- return Parent;
+ return parent;
}
/// <summary>
/// <since_tizen> 6 </since_tizen>
public void RequestLayout()
{
- Flags = Flags | LayoutFlags.ForceLayout;
- if (Parent != null)
+ flags = flags | LayoutFlags.ForceLayout;
+ if (parent != null)
{
- LayoutGroup layoutGroup = Parent as LayoutGroup;
+ LayoutGroup layoutGroup = parent as LayoutGroup;
if (layoutGroup != null && !layoutGroup.LayoutRequested)
{
layoutGroup.RequestLayout();
{
get
{
- return (Flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout;
+ return (flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout;
}
}
{
get
{
- float maximumWidth = Owner.MaximumSize.Width;
- float minimumWidth = Owner.MinimumSize.Width;
-
- float baseHeight = Owner.MaximumSize.Height > 0 ? Math.Min(Owner.MaximumSize.Height, Owner.NaturalSize.Height) : Owner.NaturalSize.Height;
- float baseWidth = Owner.GetWidthForHeight(baseHeight);
-
- float result = minimumWidth > 0 ? Math.Max(baseWidth, minimumWidth) : baseWidth;
- result = maximumWidth > 0 ? Math.Min(result, maximumWidth) : result;
-
- return new LayoutLength(result);
+ return Owner.SuggestedMinimumWidth;
}
}
{
get
{
- float maximumHeight = Owner.MaximumSize.Height;
- float minimumHeight = Owner.MinimumSize.Height;
-
- float baseWidth = Owner.MaximumSize.Width > 0 ? Math.Min(Owner.MaximumSize.Width, Owner.NaturalSize.Width) : Owner.NaturalSize.Width;
- float baseHeight = Owner.GetHeightForWidth(baseWidth);
-
- float result = minimumHeight > 0 ? Math.Max(baseHeight, minimumHeight) : baseHeight;
- result = maximumHeight > 0 ? Math.Min(result, maximumHeight) : result;
-
- return new LayoutLength(result);
+ return Owner.SuggestedMinimumHeight;
}
}
{
MeasuredWidth = measuredWidth;
MeasuredHeight = measuredHeight;
- Flags = Flags | LayoutFlags.MeasuredDimensionSet;
+ flags = flags | LayoutFlags.MeasuredDimensionSet;
}
/// <summary>
{
bool changed = false;
- if (_layoutPositionData.Left != left ||
- _layoutPositionData.Right != right ||
- _layoutPositionData.Top != top ||
- _layoutPositionData.Bottom != bottom)
+ if (layoutPositionData.Left != left ||
+ layoutPositionData.Right != right ||
+ layoutPositionData.Top != top ||
+ layoutPositionData.Bottom != bottom)
{
changed = true;
- float oldWidth = _layoutPositionData.Right - _layoutPositionData.Left;
- float oldHeight = _layoutPositionData.Bottom - _layoutPositionData.Top;
- float newWidth = right - left;
- float newHeight = bottom - top;
- bool sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight);
-
// Set condition to layout changed as currently unspecified. Add, Remove would have specified a condition.
if (ConditionForAnimation.Equals(TransitionCondition.Unspecified))
{
}
// Store new layout position data
- _layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom);
+ layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom);
- Debug.WriteLineIf(LayoutDebugFrameData, "LayoutItem FramePositionData View:" + _layoutPositionData.Item.Owner.Name +
- " left:" + _layoutPositionData.Left +
- " top:" + _layoutPositionData.Top +
- " right:" + _layoutPositionData.Right +
- " bottom:" + _layoutPositionData.Bottom);
+ NUILog.Debug("LayoutItem FramePositionData View:" + layoutPositionData.Item?.Owner?.Name +
+ " left:" + layoutPositionData.Left +
+ " top:" + layoutPositionData.Top +
+ " right:" + layoutPositionData.Right +
+ " bottom:" + layoutPositionData.Bottom);
- Container onwerContainer = Owner.GetParent();
- View onwerView = onwerContainer is Layer ? new View(Layer.getCPtr(onwerContainer).Handle, false) : onwerContainer as View;
+ View ownerView = Owner.GetParent() as View;
- if (onwerView != null && onwerView.Layout != null && onwerView.Layout.LayoutWithTransition)
+ if (ownerView?.Layout?.LayoutWithTransition ?? false)
{
- NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(_layoutPositionData);
+ NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(layoutPositionData);
}
else
{
- if (Owner.Position != null)
+ if (independent)
{
- if(independent)
- {
- // If height or width specification is not explicitly defined,
- // the size of the owner view must be reset even the ExcludeLayouting is true.
- if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0)
- {
- Owner.SetSize(right - left, bottom - top);
- }
- }
- else
+ // If height or width specification is not explicitly defined,
+ // the size of the owner view must be reset even the ExcludeLayouting is true.
+ if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0)
{
Owner.SetSize(right - left, bottom - top);
- Owner.SetPosition(left, top);
}
}
+ else
+ {
+ Owner.SetSize(right - left, bottom - top);
+ Owner.SetPosition(left, top);
+ }
}
// Reset condition for animation ready for next transition when required.
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void Dispose(bool disposing)
{
- if(disposed)
+ if (disposed)
{
return;
}
if (disposing)
{
- _margin?.Dispose();
- _padding?.Dispose();
+ margin?.Dispose();
+ padding?.Dispose();
}
disposed = true;
}