You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Components property contains a list of all components, so you can also access components by name or other property. For example, the First method can be used to find a component by name as shown in the following code:
@@ -25,8 +27,8 @@ The Components property contains a list of all components, so you can also acces
// the componentRuntime can be modified here, and added to the desired container
30
32
```
31
33
32
34
Note that the name passed to the First method should match the name given in Gum. For example, in this case the code searches for a component named ColoredRectangleComponent.
@@ -37,21 +39,6 @@ If a component is in a folder, then use the qualified name relative to the Compo
37
39
38
40
<figure><imgsrc="../../.gitbook/assets/image (42).png"alt=""><figcaption><p>StandardButton component in the Buttons folder in Gum</p></figcaption></figure>
39
41
40
-
The ToGraphicalUiElement method can automatically add the component to the root for rendering, or alternatively it can be added to an existing container. If adding to an existing container, then the ToGraphicalUiElement's addToManagers parameter should be false as shown in the following code:
// the newMessageBoxRuntime needs to be removed from ModalRoot later
100
84
```
@@ -105,23 +89,23 @@ To destroy the component, remove it from its parent, or set its parent to null:
105
89
newMessageBoxRuntime.Parent=null;
106
90
```
107
91
108
-
### Adding to Managers
92
+
### Adding to GumService Root
109
93
110
-
Components can be added directly to managers. Usually items are only added directly to managers in the following situations:
94
+
Components can be added directly to the GumService Root. Usually items are only added directly to GumService Root in the following situations:
111
95
112
-
* If they are the root runtime. Usually this is a Screen, but it can be a component if your project is not using screens.
96
+
* If they are a Screen, or will not be contained by any other object, such as if your project is not using screens.
113
97
* For testing/debugging.
114
98
* If your game has multiple roots, you can add instances to a list of GraphicalUiElements which are passed to Update. This is considered an advanced scenario.
Copy file name to clipboardExpand all lines: docs/code/gum-code-reference/elementsave/tographicaluielement.md
+3-37
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
ToGraphicalUiElement creates a new GraphicalUiElement (visual Gum object) from the calling ElementSave. This method is typically used to create new Screen or Component instances from a Gum project.
6
6
7
-
The conversion of a GraphicalUiElement can optionally add the resulting GraphicalUiElement to managers. This value should be true if the object is not going to be added as a child of any other GraphicalUiElement.
7
+
The conversion of a GraphicalUiElement can optionally add the resulting GraphicalUiElement to manager, but this is considered an advance approach. Almost all cases should use the no-argument version of ToGraphicalUiElement.
8
8
9
9
## Code Example
10
10
@@ -15,40 +15,6 @@ The following code can be used to convert a Screen named "MainMenu" to a Graphic
The `addToManagers` parameter determined whether the GraphicalUiElement is automatically added to managers so that it is directly drawn. This can be called after the element is created, so the following code shows two ways of adding the element to managers:
All GraphicalUiElements need to either be added to managers directly or indirectly. Elements added directly to managers are drawn by `GumService.Default.Draw();` . Any item that is added to managers automatically draws its children, so only root-most objects should be added to managers. 
36
-
37
-
Let's look at common scenarios and and discuss when to set `addToManagers` to true.
38
-
39
-
#### Setting addToManagers to true
40
-
41
-
Elements should have `addToManagers` set to `true` if any of the following are true:
42
-
43
-
1. The GraphicalUiElement serves as the root for all other elements. Typically this would be when a Gum project is loaded, the Screen is obtained from the Gum project's `Screens` property and its `ToGraphicalUiElement` method is called.
44
-
2. You are performing simple tests such as adding a Gum component to screen for testing, you may want to set addToManagers to true so that it shows up on screen. Note that if this is an object with events (such as a Gum Forms object), it must either be passed to the `GumService.Default.Update` call or it will not respond to the mouse, keyboard, or gamepads.
45
-
46
-
The most common case for setting AddToManagers to true is if you are creating a Gum screen from a loaded Gum project.
47
-
48
-
#### Setting addToManagers to false
49
-
50
-
Elements should have `addToManagers` set to `false` if any of the following are true:
51
-
52
-
1. If the GraphicalUiElement is being added as a child of another element which has already been added to managers. For example, if a new element is being created and added to an existing Screen or one of its children.
53
-
2. If the GraphicalUiElement is being added as a child to existing _root_ containers, such as `FrameworkElement.PopupRoot` or `FrameworkElement.ModalRoot` .
54
-
3. If the GraphicalUiElement is being added to managers on a dedicated layer. For example, a Screen could be created and added to a dedicated UI layer to control sorting of all elements in the Screen relative to other manually-created GraphicalUiElements.
Copy file name to clipboardExpand all lines: docs/code/gum-code-reference/graphicaluielement/removefrommanagers.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Introduction
4
4
5
-
RemoveFromManagers removes the calling GraphicalUiElement from the SystemManagers. This method should be called on GraphicalUiElements which need to be destroyed but do not have parents. To remove a GraphicalUiElement which has parents, remove it from its Parent's Children.
5
+
RemoveFromManagers removes the calling GraphicalUiElement from the SystemManagers. This method is typically not called, and instead RemoveFromRoot should be called in most cases.
6
6
7
7
## Code Example
8
8
@@ -11,8 +11,10 @@ The following code shows how to add and remove a GraphicalUiElement.
11
11
```csharp
12
12
// You can create a GrahicalUiElement from an ElementSave.
13
13
// Assume elementSave is valid, such as a Screen obtained from a Gum project
Copy file name to clipboardExpand all lines: docs/code/monogame/gum-forms/controls/frameworkelement/modalroot-and-popuproot.md
+4-12
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
The static ModalRoot and PopupRoot properties provide an InteractiveGue which serve as the root for any element which should appear on top of other elements. These properties have the following characteristics:
6
6
7
-
* Automatically created by `FormsUtilities.InitializeDefaults`
7
+
* Automatically created by `Gum.Initialize`
8
8
* Automatically resized to fit the entire screen, including if the `GraphicalUiElement.CanvasHeight` and `GraphicalUiElement.CanvasWidth` change.
9
9
* Both Remains on top of all other elements for its given layer. ModalRoot appears on top of PopupRoot.
Once a Gum project is loaded, all of its screens and components can be accessed through the object returned from the Initialize method. The code above stores the project in a variable called `gumProject`. Any screen or component can be converted to a GraphicalUiElement, which is the visual object that displays in game.
98
97
99
-
The code in the previous section creates a `GraphicalUiElement` from the first screen in the project. Note that the `ToGraphicalUiElement` method has an `addToManagers` parameter which determines whether the GraphicalUiElement is added to managers. This is almost always set to false since we add the created screen to the root container, which in turn has already been added to managers.
98
+
The code in the previous section creates a `GraphicalUiElement` from the first screen in the project.
100
99
101
100
For an example of a Game1.cs file which loads a project file, see the MonoGameGumFromFile: [https://github.com/vchelaru/Gum/blob/0e266942560e585359f019ac090a6c1010621c0b/Samples/MonoGameGumFromFile/MonoGameGumFromFile/Game1.cs#L76-L82](https://github.com/vchelaru/Gum/blob/0e266942560e585359f019ac090a6c1010621c0b/Samples/MonoGameGumFromFile/MonoGameGumFromFile/Game1.cs#L76-L82)
102
101
@@ -106,9 +105,7 @@ You can get a reference to elements within the screen by calling `GetGraphicalUi
0 commit comments