LogoLogo
  • Gum Tool
    • Introduction
    • Setup
      • Running from Source
    • Showcase
    • Tutorials and Examples
      • Intro Tutorials
        • 1 - The Basics
        • 2 - Variables Tab
        • 3 - Files
        • 4 - Components
        • 5 - Exposing Variables
        • 6 - Parent
        • 7 - States
        • 8 - State Categories
      • Animation Tutorials
        • 1 - Introduction to Animation
        • 2 - Creating an Animation
        • 3 - Playing Animations inside other Animations
        • 4 - Combining Multiple Categories
      • Examples
        • Bottom-Up Stack
        • Centering
        • Custom NineSlice
        • Health Bar
        • Padding
    • Gum Elements
      • General Properties
        • Alpha
        • Base Type (Inheritance)
        • Blend
        • Clips Children
        • Has Events
        • Height Units
        • Ignored By Parent Size
        • Locked
        • Max Height
        • Max Width
        • Min Height
        • Min Width
        • Order
        • Parent
        • Rotation
        • Visible
        • Variable References
        • Width Units
        • X
        • X Origin
        • X Units
        • Y
        • Y Origin
        • Y Units
      • Behaviors
        • Default Implementation
      • Circle
      • ColoredRectangle
      • Component
        • Default Child Container
      • Container
        • Children Layout
        • Contained Type
        • Is Render Target
        • Stack Spacing
        • Wraps Children
      • NineSlice
        • Blend
        • Custom Frame Texture Coordinate Width
        • Texture Address
        • Texture Left
        • Texture Top
      • Polygon
        • Points
      • Skia Standard Elements
        • General Properties
          • Has Dropshadow
          • Is Filled
          • Use Gradient
        • Arc
          • Start Angle
          • Sweep Angle
          • Thickness
        • Canvas
        • ColoredCircle
        • LottieAnimation
        • RoundedRectangle
          • Corner Radius
        • Svg
      • Sprite
        • Color
        • Source File
        • Texture Address
        • Wrap
      • States
        • Categories
      • Text
        • Blue
        • Color
        • Font
        • Font Scale
        • Font Size
        • Green
        • Is Bold
        • Is Italic
        • MaxLettersToShow
        • Outline Thickness
        • Red
        • Text
        • Text Overflow Horizontal Mode
        • Text Overflow Vertical Mode
        • Use Custom Font
        • Use Font Smoothing
    • Project Tab
    • Code Tab
      • Runtime Generation Details
      • Generation Scope
      • Inheritance Location
      • Is CodeGen Plugin Enabled
      • Show CodeGen Preview
    • Localization
    • Menu
      • Content
      • Project Properties
    • Plugins
      • AddAndRemoveVariablesForType
      • AddMenuItem
      • Export
      • Setting Up Post Build Events
    • Variables
      • Add Variable
    • Bitmap font generator (.fnt)
    • Upgrading
      • Migrating 2025 April 27 to Preview
      • Breaking Changes
        • Removal of Variable Spaces
  • Code
    • Gum Code Reference
      • AnimationRuntime
      • BitmapCharacterInfo
      • BitmapFont
      • Camera
      • CircleRuntime
      • ColoredRectangleRuntime
      • Component Runtimes
      • ContainerRuntime
      • Cursor
      • Gum Class Overview
      • DataUiGrid
        • Reflection
        • Categories
      • ElementSave
        • ToGraphicalUiElement
      • GraphicalUiElement
        • Absolute Values
        • AddToManagers
        • AnimateSelf
        • ApplyState
        • BlendState
        • CanvasHeight
        • CanvasWidth
        • Children
        • ContainedElements
        • Font Values
        • GetAbsoluteHeight
        • GetAbsoluteWidth
        • GetChildByNameRecursively
        • GetFrameworkElementByName
        • IsAllLayoutSuspended
        • Parent
        • RemoveFromManagers
        • UpdateLayout
      • GumProjectSave
      • IDataUi
      • InstanceMember
      • InstanceSave
      • InteractiveGue
        • CurrentInputReceiver
        • RaiseChildrenEventsOutsideOfBounds
        • RollOverBubbling
      • IPositionedSizedObject
      • Layer
      • NineSliceRuntime
      • RectangleRuntime
      • Renderer
        • SinglePixelTexture
      • SelectedState
      • SpriteRenderer
        • LastFrameDrawStates
      • SpriteRuntime
        • TextureAddress
        • TextureHeight
        • TextureLeft
        • TextureTop
        • TextureWidth
      • TextRuntime
        • Color
        • FontScale
        • FontSize
        • HorizontalAlignment
        • Text Wrapping
        • VerticalAlignment
      • VariableSave
    • FNA
    • Kni
    • Meadow
    • MonoGame
      • Setup
        • Linking Game Project to Source (Optional)
      • Tutorials
        • Gum Project Forms Tutorial
          • Setup
          • Gum Screens
          • Common Component Types
          • Styling
          • Multiple Screens
        • Code-Only Gum Forms Tutorial
          • Setup
          • Forms Controls
          • ListBox Items
          • Input in Forms
        • [Deprecated] Gum Project (.gumx) Tutorial
          • Setup
          • Gum Screens
          • Gum Forms
          • Customizing Forms
          • Strongly Typed Components Using Code Generation
          • Multiple Screens
      • Setup for GumBatch (Optional)
      • Loading a Gum Project (Optional)
      • async Programming
      • Custom Runtimes
      • GumBatch
      • Gum Forms
        • Binding (ViewModels)
        • Controls
          • Button
          • CheckBox
          • FrameworkElement
            • BindingContext
            • IsEnabled
            • IsFocused
            • ModalRoot and PopupRoot
            • SetBinding
          • ListBox
          • ListBoxItem
          • MenuItem
          • PasswordBox
          • RadioButton
          • ScrollViewer
            • VerticalScrollBarValue
          • StackPanel
          • Slider
          • TextBox
        • Control Customization In Code
          • MenuItem
        • Control Customization in Gum Tool
        • Gamepad Support
        • Keyboard Support
        • Troubleshooting
      • File Loading
      • Resizing the Game Window
      • Known Issues
      • Samples
        • MonoGameGumFormsSample
    • Nez
    • Silk.NET
    • SkiaGum
      • Setup
        • WPF
    • .NET MAUI
      • Setup
Powered by GitBook
On this page
  • Introduction
  • Common Usage
  • Code Example - Measuring Layout Calls

Was this helpful?

Edit on GitHub
Export as PDF
  1. Code
  2. Gum Code Reference
  3. GraphicalUiElement

IsAllLayoutSuspended

Introduction

The static IsAllLayoutSuspended property controls whether GraphicalUiElement layout calls are skipped. If this value is true, all GraphicalUiElements return immediately when calling Layout rather than performing a full layout. This includes explicit calls to Layout as well as calls performed as a result of changing properties such as Width.

This property is false by default, which mean layout is not suspended.

Common Usage

By default changes to Gum immediately result in a layout. For example, consider the following code:

var child = new ColoredRectangleRuntime();
parent.Children.Add(child);

child.X = 100;
child.Y = 200;
child.Width = 50;
child.Height = 30;

The parent in the code above may be sized according to its children. If so, any change to the child (X, Y, Width, and Height) cause the parent to update its layout. In addition, adding the child to the parent also results in a layout call. Furthermore, the parent may contain other children which would be updated in response to the parent. This code could result in hundreds or even thousands of layout calls.

However, typically a layout is not needed until all objects have been added and after all of their variables have been modified. Therefore, the following modifications could be made:

GraphicalUiElement.IsAllLayoutSuspended = true;

var child = new ColoredRectangleRuntime();
parent.Children.Add(child);

child.X = 100;
child.Y = 200;
child.Width = 50;
child.Height = 30;

GraphicalUiElement.IsAllLayoutSuspended = false;
// after resuming layouts, explicitly call layout at the top level:
parent.UpdateLayout();

Code Example - Measuring Layout Calls

The UpdateLayoutCallCount property can be used to measure the number of UpdateLayout calls. It can be used to compare the number of layout calls reduced by using IsAllLayoutSuspended.

For example, the followign code can be used to display layout calls:

var stackingContainer = new ContainerRuntime();

stackingContainer.Width = 200;
stackingContainer.ChildrenLayout = Gum.Managers.ChildrenLayout.LeftToRightStack;
stackingContainer.StackSpacing = 3;
stackingContainer.WrapsChildren = true;
stackingContainer.Y = 10;
stackingContainer.Height = 10;
stackingContainer.HeightUnits = Gum.DataTypes.DimensionUnitType.RelativeToChildren;

for (int i = 0; i < 70; i++)
{
    var rectangle = new ColoredRectangleRuntime();
    stackingContainer.Children.Add(rectangle);
    rectangle.Width = 7;
    rectangle.Height = 7;
}

Root.Children.Add(stackingContainer);
var layoutCountAfter = GraphicalUiElement.UpdateLayoutCallCount;
System.Diagnostics.Debug.WriteLine($"Number of layout calls: {layoutCountAfter - layoutCountBefore}");

This produes a large number of layouts:

Number of layout calls: 15510

We can add additional code to suppress layouts until we are finished adding all children:

var stackingContainer = new ContainerRuntime();

GraphicalUiElement.IsAllLayoutSuspended = true;// <---------New
stackingContainer.Width = 200;
stackingContainer.ChildrenLayout = Gum.Managers.ChildrenLayout.LeftToRightStack;
stackingContainer.StackSpacing = 3;
stackingContainer.WrapsChildren = true;
stackingContainer.Y = 10;
stackingContainer.Height = 10;
stackingContainer.HeightUnits = Gum.DataTypes.DimensionUnitType.RelativeToChildren;

for (int i = 0; i < 70; i++)
{
    var rectangle = new ColoredRectangleRuntime();
    stackingContainer.Children.Add(rectangle);
    rectangle.Width = 7;
    rectangle.Height = 7;
}

Root.Children.Add(stackingContainer);
GraphicalUiElement.IsAllLayoutSuspended = false; // <---------New
container.UpdateLayout(); // <---------New
var layoutCountAfter = GraphicalUiElement.UpdateLayoutCallCount;
System.Diagnostics.Debug.WriteLine($"Number of layout calls: {layoutCountAfter - layoutCountBefore}");

This results in far fewer layout calls:

Number of layout calls: 174
PreviousGetFrameworkElementByNameNextParent

Last updated 4 months ago

Was this helpful?