/// <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)); }
/// <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)); }
public static void ForceUpdateLayout(this UIComponent ctrl) { UResizer.UpdateControl(ctrl); }