/// <summary>Calls <see cref="onResize_"/> if it is not null.</summary>
        /// <param name="control">The control which is to be refreshed.</param>
        /// <param name="previousSibling">Previous sibling if exists, for control stacking.</param>
        /// <param name="childrenBox">The bounding box of all children of that control.</param>
        /// <returns>Updated box for that control.</returns>
        public static UBoundingBox?CallOnResize([NotNull] UIComponent control,
                                                [CanBeNull] UIComponent previousSibling,
                                                UBoundingBox childrenBox)
        {
            if (control is ISmartSizableControl currentAsResizable)
            {
                UResizerConfig resizerConfig = currentAsResizable.GetResizerConfig();

                if (resizerConfig.onResize_ != null)
                {
                    // Create helper UResizer and run it
                    UResizer resizer = new UResizer(
                        control: control,
                        config: resizerConfig,
                        previousSibling,
                        childrenBox);
                    try {
                        resizerConfig.onResize_(resizer);
                    }
                    catch (Exception e) {
                        Log.Error($"While calling OnResize on {control.name}: {e}");
                    }
                }

                if (!resizerConfig.ContributeToBoundingBox)
                {
                    return(null);
                }
            }
            else
            {
                Log._Debug("CallOnResize for a non-ISmartSizableControl");
            }
            return(new UBoundingBox(control));
        }
Exemple #2
0
        /// <summary>Grow the bounding box to include the new box.</summary>
        /// <param name="box">The new box.</param>
        public void ExpandToFit(UBoundingBox box)
        {
            A.x = Mathf.Min(A.x, box.A.x);
            A.y = Mathf.Min(A.y, box.A.y);

            B.x = Mathf.Max(B.x, box.B.x);
            B.y = Mathf.Max(B.y, box.B.y);
        }
Exemple #3
0
 public UResizer([NotNull] UIComponent control,
                 [NotNull] UResizerConfig config,
                 [CanBeNull] UIComponent previousSibling,
                 UBoundingBox childrenBox)
 {
     ChildrenBox     = childrenBox;
     Config          = config;
     Control         = control;
     PreviousSibling = previousSibling;
 }
Exemple #4
0
        /// <summary>Calls <see cref="onResize_"/> if it is not null.</summary>
        /// <param name="control">The control which is to be refreshed.</param>
        /// <param name="previousSibling">Previous sibling if exists, for control stacking.</param>
        /// <param name="childrenBox">The bounding box of all children of that control.</param>
        /// <returns>Updated box for that control.</returns>
        public static UBoundingBox?CallOnResize([NotNull] UIComponent control,
                                                [CanBeNull] UIComponent previousSibling,
                                                UBoundingBox childrenBox)
        {
            if (control is ISmartSizableControl currentAsResizable)
            {
                UResizerConfig resizerConfig = currentAsResizable.GetResizerConfig();
                UResizer       resizer       = new UResizer(
                    control: control,
                    config: resizerConfig,
                    previousSibling,
                    childrenBox);

                // Apply predefined decision: fixed size
                if (resizerConfig.SizeChoice == USizeChoice.Predefined)
                {
                    resizer.Width(UValue.FixedSize(resizerConfig.FixedSize.x));
                    resizer.Height(UValue.FixedSize(resizerConfig.FixedSize.y));
                }

                // Apply predefined decision: stacking and spacing
                if (resizerConfig.StackingChoice == UStackingChoice.Predefined)
                {
                    resizer.Stack(
                        mode: resizerConfig.Stacking,
                        spacing: resizerConfig.StackingSpacing);
                }

                // Call the resize function to apply user decisions on the size and position
                if (resizerConfig.onResize_ != null)
                {
                    // Create helper UResizer and run it
                    try {
                        resizerConfig.onResize_(resizer);
                    }
                    catch (Exception e) {
                        Log.Error($"While calling OnResize on {control.name}: {e}");
                    }
                }

                if (!resizerConfig.ContributeToBoundingBox)
                {
                    return(null);
                }
            }
            else
            {
                Log._Debug("CallOnResize for a non-ISmartSizableControl");
            }
            return(new UBoundingBox(control));
        }