Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions.
()
| 211 | /// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions. |
| 212 | /// </summary> |
| 213 | public virtual void ResizeAuto() |
| 214 | { |
| 215 | if (Surface == null) |
| 216 | return; |
| 217 | var width = 0.0f; |
| 218 | var height = 0.0f; |
| 219 | var leftHeight = 0.0f; |
| 220 | var rightHeight = 0.0f; |
| 221 | var leftWidth = 40.0f; |
| 222 | var rightWidth = 40.0f; |
| 223 | var boxLabelFont = Style.Current.FontSmall; |
| 224 | var titleLabelFont = Style.Current.FontLarge; |
| 225 | for (int i = 0; i < Children.Count; i++) |
| 226 | { |
| 227 | var child = Children[i]; |
| 228 | if (!child.Visible) |
| 229 | continue; |
| 230 | |
| 231 | // Input boxes |
| 232 | if (child is InputBox inputBox) |
| 233 | { |
| 234 | var boxWidth = boxLabelFont.MeasureText(inputBox.Text).X + 25; |
| 235 | if (inputBox.DefaultValueEditor != null && inputBox.DefaultValueEditor.Visible) |
| 236 | boxWidth += inputBox.DefaultValueEditor.Width + 4; |
| 237 | leftWidth = Mathf.Max(leftWidth, boxWidth); |
| 238 | leftHeight = Mathf.Max(leftHeight, inputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderHeight + Constants.BoxRowHeight); |
| 239 | } |
| 240 | // Output boxes |
| 241 | else if (child is OutputBox outputBox) |
| 242 | { |
| 243 | rightWidth = Mathf.Max(rightWidth, boxLabelFont.MeasureText(outputBox.Text).X + 25); |
| 244 | rightHeight = Mathf.Max(rightHeight, outputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderHeight + Constants.BoxRowHeight); |
| 245 | } |
| 246 | // Elements (Float-, int-, uint- value boxes, asset pickers, etc.) |
| 247 | // These will only ever be on the left side of the node, so we only adjust left width and height |
| 248 | else if (child is SurfaceNodeElementControl elementControl) |
| 249 | { |
| 250 | leftWidth = Mathf.Max(leftWidth, elementControl.Width + 8f); |
| 251 | leftHeight = Mathf.Max(leftHeight, elementControl.Height); |
| 252 | } |
| 253 | // Other controls in the node |
| 254 | else if (child is Control control) |
| 255 | { |
| 256 | if (control.AnchorPreset == AnchorPresets.TopLeft) |
| 257 | { |
| 258 | width = Mathf.Max(width, control.Right + 15 + Constants.NodeMarginX); |
| 259 | height = Mathf.Max(height, control.Bottom - Constants.NodeMarginY - Constants.NodeHeaderHeight); |
| 260 | } |
| 261 | else if (!_headerRect.Intersects(control.Bounds)) |
| 262 | { |
| 263 | width = Mathf.Max(width, control.Width + 15 + Constants.NodeMarginX); |
| 264 | height = Mathf.Max(height, control.Height); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | width = Mathf.Max(width, leftWidth + rightWidth + 10); |
| 269 | width = Mathf.Max(width, titleLabelFont.MeasureText(Title).X + 30); |
| 270 | height = Mathf.Max(height, Mathf.Max(leftHeight, rightHeight)); |
no test coverage detected