### Creating the Simplest GMUI Page - XML
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This snippet demonstrates how to create the most basic GMUI page by defining an empty `.gmui` file. Running the project with this file will display a blank page, highlighting GMUI's minimal setup requirement where no additional code is needed to start a UI.
```XML
```
--------------------------------
### Navigating Between Pages with jump_to - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example illustrates how to implement page navigation in GMUI. It shows a button that, when pressed, uses the 'self.jump_to' method to transition to another GMUI page specified by its file path.
```XML
```
```GDScript
func _mounted():
gmui.refs['btn'].rnode.pressed.connect(
func():
self.jump_to('res://pages/page2.gmui')
)
```
--------------------------------
### Navigating Between Pages
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Shows how to perform page navigation using the `jump_to` method. The example demonstrates connecting a button's `pressed` signal to a function that calls `self.jump_to` with the target .gmui file path, enabling seamless page transitions.
```XML
```
--------------------------------
### Building a Registration/Login UI with GMUI
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Illustrates how to construct a basic registration and login interface using GMUI's built-in components like Row, Column, Label, LineEdit, and Button. This example showcases the declarative UI definition using an XML-like syntax.
```XML
```
--------------------------------
### Navigating Between Pages in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example illustrates how to implement page navigation in GMUI. A button's `pressed` signal is connected to a function that calls `self.jump_to`, directing the application to a specified `.gmui` file path within the pages directory.
```XML
```
--------------------------------
### Simple Two-Way Data Binding for LineEdit
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
A concise example demonstrating two-way data binding for a LineEdit component using the 'g-model' directive and a reactive data variable defined in the script.
```XML
```
```GDScript
@onready var data = await reactive({'text': 'new text'})
```
--------------------------------
### Accessing Component Instances by Reference in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example shows how to declare a `ref` on a custom component (`UsernameInput`) and then access its internal virtual nodes by chaining `refs` calls. It requires importing the custom component definition.
```XML
```
--------------------------------
### List Rendering with g-for on Components - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example extends list rendering to custom components. It uses 'g-for' to iterate over a reactive array ('arr') and instantiate a 'Component' for each item, passing the item as a property.
```XML
```
```GDScript
@import('Component', 'res://components/component.gmui')
@onready var data = await reactive({'arr': [1,2,3,4]})
```
--------------------------------
### Using Named Slots in Components - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example illustrates how to use components with multiple named slots. The '' syntax is used to specify which content belongs to which named slot defined in the component.
```XML
```
```GDScript
@import('Component', 'res://components/component.gmui')
```
--------------------------------
### Rendering Lists of Custom Components with g-for in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example shows how to use the `g-for` directive to render a list of custom components. It iterates over an array, passing each item as a property to the `Component`, and requires importing the component definition.
```XML
```
--------------------------------
### Implementing Conditional Rendering with g-if/g-else-if/g-else in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example demonstrates how to use `g-if`, `g-else-if`, and `g-else` directives to conditionally display different UI elements based on the value of a reactive data property (`flag`).
```XML
```
--------------------------------
### Applying Bidirectional Binding to Components (XML)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Shows a simple example of applying bidirectional data binding (g-model) to a LineEdit component, indicating that the mechanism works directly on individual UI elements.
```XML
```
--------------------------------
### Accessing Component Instances and Nested References
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Demonstrates how to get a GMUI instance of a component when `ref` is declared on it. It also shows how to access nested references within the component's instance, allowing for granular control over sub-components.
```XML
```
--------------------------------
### Rendering Lists with `g-for` Directive
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Explains how to render a list of items dynamically using the `g-for` directive on a UI element. The example iterates over a reactive array and displays each item's text in a `Label`, simplifying list generation.
```XML
```
--------------------------------
### Passing Parameters to Slots in GMUI Components (Usage)
Source: https://github.com/godothub/gmui/blob/master/README.md
This example demonstrates how a parent component can receive data passed from a slot using `#default="props"`. The received data is then accessed via `props.propertyName` to display dynamic content.
```XML
```
--------------------------------
### Using Named Slots in GMUI Components
Source: https://github.com/godothub/gmui/blob/master/README.md
This example demonstrates how to provide content for specific named slots within a component using ``. This allows for multiple distinct content injection points within a single component.
```XML
```
--------------------------------
### Accessing Component Instances with ref - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example shows how to declare a 'ref' on a custom GMUI component. In GDScript, it demonstrates how to obtain the GMUI instance of that component and then access its internal 'refs' to interact with its sub-elements.
```XML
```
```XML
```
```GDScript
@import('UsernameInput', 'res://components/username_input.gmui')
func _mounted():
var component = gmui.refs['component'].refs['text1']
```
--------------------------------
### Implementing Bidirectional Data Binding and Event Handling in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example illustrates how to achieve two-way data binding using `g-model` for input fields and how to handle button press events within the `Script` block. It shows how to access and print the bound reactive data upon user interaction.
```XML
```
--------------------------------
### Declaring `ref` on a Component (XML)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Illustrates how to declare a `ref` attribute on a custom component (Text in this case) within a GMUI file. This snippet is part of a larger example demonstrating how to access a component's VM instance.
```XML
```
--------------------------------
### Using Default Slots in Components - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example shows how to use a component that defines a default slot. Content placed directly inside the component tags in the parent will be rendered where the '' tag is defined in the component's template.
```XML
```
```GDScript
@import('Component', 'res://components/component.gmui')
```
--------------------------------
### Passing Parameters to Slots (Usage) - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example demonstrates how a parent component can receive parameters from a slot. By using '#default="props"' on the component, the parent can access variables exposed by the slot within its template.
```XML
```
```GDScript
@import('Component', 'res://components/component.gmui')
```
--------------------------------
### Watching Reactive Data Properties
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Explains how to use the `watch` function to observe changes in reactive data properties. The example demonstrates setting up a watcher for the `text` property, which triggers a callback function with the new and old values upon change, useful for side effects.
```XML
```
--------------------------------
### Conditional Compilation with #ifndef in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example shows how to use `#ifndef [Platform]` directives to include UI elements (XML) or GDScript code only if the specified platform is *not* the target, allowing for platform-specific exclusions.
```XML
#ifndef [Windows]
#endif
```
--------------------------------
### Bidirectional Binding for Custom Components in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example illustrates how to apply bidirectional data binding to a custom component using `g-model:property`. It shows how to import a custom component and bind its internal properties to reactive data, with changes reflecting in other bound elements.
```XML
```
--------------------------------
### Conditional Compilation with #ifndef - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example illustrates the use of '#ifndef' directives for conditional compilation. It ensures that specific UI elements (Labels) and GDScript code are included in the build only if a particular platform (e.g., Windows) is NOT defined.
```XML
#ifndef [Windows]
#endif
```
```GDScript
#ifndef [Windows]
var platform = 'Not Windows'
#endif
```
--------------------------------
### Two-Way Data Binding for Input Fields
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Demonstrates a simple two-way data binding example for a `LineEdit` component, linking its value to a reactive data property. Changes in the UI update the data, and vice-versa, showcasing the `g-model` directive.
```XML
```
--------------------------------
### Implementing Bidirectional Data Binding for Login - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example demonstrates bidirectional data binding using 'g-model' for input fields and handling button presses. It shows how to bind LineEdit values to reactive data and how to access and modify that data in GDScript upon button clicks.
```XML
```
```GDScript
@onready var data = await reactive({'username': 'name', 'password': '123'})
func _mounted():
gmui.refs['loginBtn'].rnode.pressed.connect(
func():
print('username:', data.rget('username'))
print('password:', data.rget('password'))
)
gmui.refs['resetBtn'].rnode.pressed.connect(
func():
data.rset('username', '')
data.rset('password', '')
)
func _updated():
print('username:', data.rget('username'))
print('password:', data.rget('password'))
```
--------------------------------
### Accessing Nested Nodes within a GMUI Component Instance - XML & GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This example demonstrates how to access a GMUI component instance using `ref` and then navigate its internal structure to reach a nested node. The first XML defines a component with a `Label` having a `ref`. The second XML uses this component, and the GDScript imports it, then retrieves the nested `Label`'s virtual node from the component instance.
```XML
```
```XML
```
```GDScript
```
--------------------------------
### Defining and Using Computing Properties - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example shows how to create and utilize computed properties in GMUI. The 'fullName' computed property derives its value from 'firstName' and 'lastName' reactive data, automatically updating when its dependencies change, and is displayed in a Label.
```XML
```
```GDScript
var data = await reactive({'firstName': 'White', 'lastName': 'Red'})
func fullName():
return data.rget('firstName') + data.rget('lastName')
func _ready():
computed(fullName)
func _mounted():
gmui.refs['btn'].rnode.pressed.connect(
func():
data.rset('firstName', 'Green')
)
```
--------------------------------
### Accessing Virtual Nodes via References
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Explains how to obtain a virtual node reference using the `ref` attribute on a standard Godot node. The example shows accessing the `rnode` property of the virtual node in GDScript to interact with the underlying Godot node.
```XML
```
--------------------------------
### Bidirectional Data Binding with Custom Components - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This example shows how to achieve bidirectional data binding with custom components using 'g-model:property'. It demonstrates importing a custom component and binding its 'text' property to a reactive variable, with a Label reflecting the bound value.
```XML
```
```GDScript
@import('Component', 'res://components/component.gmui')
@onready var data = gmui.reactive({'text': 'my text'})
```
--------------------------------
### Applying Bidirectional Data Binding to a Single Component - XML & GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This example illustrates a simpler case of bidirectional data binding, applying `g-model` to a single `LineEdit` component. The GDScript initializes a reactive data object with a 'text' property, which will automatically synchronize with the `LineEdit`'s content.
```XML
```
```GDScript
```
--------------------------------
### Creating Computed Properties in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This example illustrates how to define a `computed` property (`fullName`) that automatically updates based on changes to its dependent reactive data properties (`firstName`, `lastName`). A button press triggers a change in `firstName`, demonstrating the computed property's reactivity.
```XML
```
--------------------------------
### Creating a Basic GMUI Page
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Demonstrates how to create the simplest possible GMUI page by creating an empty .gmui file. No code is required to run a basic GMUI project, highlighting GMUI's focus on simplicity and minimal boilerplate.
```XML
```
--------------------------------
### Building a Basic Registration/Login UI with GMUI
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
Illustrates how to construct a simple registration and login interface using GMUI's built-in components like Row, Column, Label, LineEdit, and Button. It demonstrates the basic layout capabilities of the framework.
```XML
```
--------------------------------
### Creating a Basic Login Interface in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet demonstrates how to construct a simple login interface using GMUI's XML-like syntax, leveraging built-in Godot nodes such as Row, Column, Text, LineEdit, and Button to define the layout and elements.
```XML
```
--------------------------------
### Creating a Simple GMUI Page - XML
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This snippet demonstrates the minimal XML required to create a blank page in GMUI. Running a project with this file will display an empty page, highlighting GMUI's simplicity without requiring additional code.
```XML
```
--------------------------------
### Building a Login Interface with GMUI (XML)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Illustrates how to construct a basic login interface using GMUI's XML-like syntax and Godot's built-in nodes. It showcases the use of Row, Column, Text, LineEdit, and Button components for UI layout.
```XML
```
--------------------------------
### Navigating Between GMUI Pages
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
Demonstrates how to implement page navigation within a GMUI application using the 'jump_to' method. This method is typically triggered by a user interaction, such as a button press, and takes the path to the target .gmui file.
```XML
```
```GDScript
func _mounted():
gmui.refs['btn'].rnode.pressed.connect(
func():
self.jump_to('res://pages/page2.gmui')
)
```
--------------------------------
### Navigating Between Pages in GMUI (XML, GDScript)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Illustrates how to implement page redirection using the `jump_to` method. It shows connecting a button's pressed signal to a function that calls self.jump_to with the path to the target .gmui file.
```XML
```
--------------------------------
### Building a Login Interface - XML
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This XML snippet illustrates how to construct a basic login interface using GMUI's component system, which reuses Godot's built-in nodes like Row, Column, Text, LineEdit, and Button. It showcases the declarative UI structure.
```XML
```
--------------------------------
### Defining a Basic Login UI - XML
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This XML snippet illustrates how to construct a simple login interface using GMUI's built-in components like `Row`, `Column`, `Text`, `LineEdit`, and `Button`. It showcases the declarative UI definition approach, arranging elements for username, password, login, and reset actions.
```XML
```
--------------------------------
### Implementing Two-Way Data Binding and Event Handling
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Shows how to achieve two-way data binding using `g-model` for input fields and how to handle button click events. It demonstrates reactive data management with `reactive` and accessing component references (`refs`) to connect signals and update data.
```XML
```
--------------------------------
### Defining a Basic Scene in GMUI XML
Source: https://github.com/godothub/gmui/blob/master/docs/preview/README.md
This XML snippet demonstrates the basic structure for defining a new scene in GMUI. It uses a `Node2D` as the root element, named 'MainScene'. This file should be placed in the `layouts` directory and uses GMUI's custom nodes like `GNode2D`.
```XML
```
--------------------------------
### Defining a Simple Component for List Items
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Provides the definition for a basic component that displays text, intended for use within a `g-for` loop. It shows how a component can accept a property (e.g., `text`) to display dynamic content.
```XML
```
--------------------------------
### Executing Node Methods with `exec_func`
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Illustrates the recommended way to modify a real node's state by calling its methods using `exec_func`. This method takes the function name and an array of arguments, ensuring proper state management within GMUI's virtual node system.
```XML
```
--------------------------------
### Executing Methods on Nodes in GMUI (XML, GDScript)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Shows how to use the `exec_func` method on a virtual node obtained via `id` to call a method (e.g., set_text) on the underlying real node, passing parameters as an array.
```XML
```
--------------------------------
### Defining a Component with a Node Reference
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Shows how to define a simple component containing a `Label` with a `ref` attribute. This `ref` can then be accessed from the parent component when this component is instantiated, allowing for interaction with its internal nodes.
```XML
```
--------------------------------
### Resulting Structure of Default Slot Usage in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet demonstrates the effective UI structure after a default slot has been utilized. The content passed into the slot is integrated directly into the component's layout, as if it were written inline.
```XML
```
--------------------------------
### Accessing a Component's VM Instance via `ref` (XML, GDScript)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Demonstrates how to declare a `ref` on a custom Widget component and then access its internal VM instance, including its own `refs`, from the parent script's _mounted function.
```XML
```
--------------------------------
### Structuring UI Code with Template Tag (XML, GDScript)
Source: https://github.com/godothub/gmui/blob/master/docs/1.0/README.md
Explains an alternative way to structure GMUI code by encapsulating all UI elements within a tag, separating it from the
```
--------------------------------
### Using Components with Default Slots
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Shows how to use a component that defines a default slot. Content placed directly inside the component's tags will be rendered in the `Slot` tag defined within the component, enabling content projection.
```XML
```
--------------------------------
### Iterating Over Components with `g-for`
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Demonstrates using the `g-for` directive to render a list of custom components. It shows how to pass individual items from a reactive array as properties to each component instance, enabling reusable list items.
```XML
```
--------------------------------
### Executing Methods on Virtual Nodes in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet demonstrates how to call a method on a virtual node using the `exec_func` method. It shows how to modify a `Label`'s text by calling its `set_text` method with an array of arguments, emphasizing indirect state modification.
```XML
```
--------------------------------
### Rendering Component Lists with 'g-for'
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
Demonstrates using the 'g-for' directive on a custom component ('Component') to render a list of components. Each component instance receives individual array items as properties, requiring the component to be imported.
```XML
```
```GDScript
@import('Component', 'res://components/component.gmui')
@onready var data = await reactive({'arr': [1,2,3,4]})
```
--------------------------------
### Accessing Virtual Nodes by Reference in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet demonstrates how to declare a `ref` on a standard UI node (e.g., `Label`) and then access its underlying Godot node (`rnode`) and properties (e.g., `text`) from the GDScript `_mounted` lifecycle hook.
```XML
```
--------------------------------
### Defining a Simple Component for List Rendering in GMUI
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet provides the definition for a basic GMUI component that can be used within `g-for` loops. It consists of a `Row` containing a `Label` whose text is bound to a property, demonstrating a reusable UI element.
```XML
```
--------------------------------
### Executing Methods on Virtual Nodes
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
Explains how to call methods on the underlying real Godot node of a virtual node using the 'exec_func' method. This method takes the function name as a string and an array of arguments to pass to the function.
```XML
```
```GDScript
func _mounted():
gmui.refs['label'].exec_func('set_text', ['new text'])
```
--------------------------------
### Executing Methods on Nodes with exec_func - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This snippet demonstrates the recommended way to modify a node's state or execute its methods in GMUI. It uses 'exec_func' on a virtual node, passing the method name and an array of arguments, ensuring proper state management.
```XML
```
```GDScript
func _mounted():
gmui.refs['label'].exec_func('set_text', ['new text'])
```
--------------------------------
### Implementing Two-Way Data Binding and Event Handling
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
Shows how to use 'g-model' for two-way data binding between UI elements (LineEdit) and reactive data. It also demonstrates connecting button 'pressed' signals to GDScript functions to print input values and reset fields, showcasing event handling and data manipulation.
```XML
```
```GDScript
@onready var data = await reactive({'username': 'name', 'password': '123'})
func _mounted():
gmui.refs['loginBtn'].rnode.pressed.connect(
func():
print('username:', data.rget('username'))
print('password:', data.rget('password'))
)
gmui.refs['resetBtn'].rnode.pressed.connect(
func():
data.rset('username', '')
data.rset('password', '')
)
func _updated():
print('username:', data.rget('username'))
print('password:', data.rget('password'))
```
--------------------------------
### Accessing Component Instance References
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.ZH.md
Demonstrates how declaring a 'ref' on a GMUI component provides access to the component's GMUI instance. This allows for interaction with its internal elements, including other 'ref's declared within the component's own template.
```XML
```
```GDScript
@import('UsernameInput', 'res://components/username_input.gmui')
func _mounted():
var component = gmui.refs['component'].refs['text1']
```
--------------------------------
### Implementing Named Slots in Components
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Demonstrates how to use named slots to inject specific content into different areas of a component. `Template` tags with `#slotName` are used to target corresponding `Slot` tags within the component definition, enabling more complex layouts.
```XML
```
--------------------------------
### Defining a Component with a Default Slot
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Provides the definition for a component that includes a default `Slot` tag. This slot acts as a placeholder for content provided by the parent component when it uses this component, allowing for flexible component composition.
```XML
```
--------------------------------
### Passing Parameters to Child Scene in GMUI XML
Source: https://github.com/godothub/gmui/blob/master/docs/preview/README.md
This XML snippet demonstrates how to embed a child scene using the `Scene` tag and pass properties to it. The `scene_xml_path` attribute specifies the child scene's XML file, and additional attributes like `visible` are passed as parameters.
```XML
```
--------------------------------
### Using Default Slots in GMUI Components
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet illustrates how to use a custom component and inject content directly into its default slot. The content (a `Label` with 'my text') will be rendered where the `` tag is defined within the component.
```XML
```
--------------------------------
### Listening to Reactive Properties with watch - XML/GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.3/README.md
This snippet demonstrates how to use the 'watch' function to monitor changes in reactive data properties. It sets up a listener for the 'text' property, executing a callback function 'change_text' whenever 'text' changes, printing both new and old values.
```XML
```
```GDScript
var data = await reactive({'text': 'text'})
func _ready():
watch('text', change_text)
func change_text(newValue, oldValue):
print(newValue, ',', oldValue)
```
--------------------------------
### Defining Reactive Data in GMUI GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/preview/README.md
This GDScript snippet demonstrates how to define reactive data using `vm.define_reactive`. The `data` variable becomes a responsive object, allowing its properties like 'visible' and 'text' to trigger updates when changed. The `_mounted` method executes after rendering, and `_updated` executes on data changes.
```GDScript
extends "res://addons/gmui/scripts/common/g_node_2d.gd"
@onready var data = vm.define_reactive({'visible': false, 'text': 'text'})
func _mounted():
await get_tree().create_timer(5).timeout
data.rset('visible', true)
print('mounted')
func _updated():
print('updated')
```
--------------------------------
### Defining a Component with Named Slots
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Shows how to define a component that utilizes multiple named slots. Each `Slot` tag is given a unique `name` attribute, allowing parent components to target specific content areas for projection.
```XML
```
--------------------------------
### Implementing Bidirectional Data Binding and Event Handling - XML & GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This snippet demonstrates bidirectional data binding using the `g-model` directive for `LineEdit` components, linking UI input to reactive data. The accompanying GDScript block initializes reactive data, connects button `pressed` signals to print user input, and resets fields, also showing `_updated` lifecycle hook for data changes.
```XML
```
```GDScript
```
--------------------------------
### Executing Methods on Virtual Nodes using `exec_func` - XML & GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This snippet demonstrates the recommended way to modify the state of a real Godot node through its virtual node in GMUI. The XML defines a `Label` with an `id`. The GDScript then uses `gmui.refs['label'].exec_func` to call the `set_text` method on the underlying real node, passing 'new text' as an argument.
```XML
```
```GDScript
```
--------------------------------
### Defining a Default Slot in a GMUI Component
Source: https://github.com/godothub/gmui/blob/master/README.md
This snippet shows the internal definition of a component that includes a default slot. The `` tag acts as a placeholder where content provided by the parent component will be rendered.
```XML
```
--------------------------------
### Defining Slot Placeholder in Child Scene XML
Source: https://github.com/godothub/gmui/blob/master/docs/preview/README.md
This XML snippet from a child scene shows where content provided by a parent scene's `` tag will be rendered. The `` tag acts as a placeholder for dynamic content injection, similar to Vue.js slots, allowing for flexible component composition.
```XML
```
--------------------------------
### Conditional Rendering with `g-if` Directives
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Illustrates how to conditionally render UI elements based on a reactive data property using `g-if`, `g-else-if`, and `g-else` directives. This allows for dynamic display of content based on application state.
```XML
```
--------------------------------
### Defining Slot Content in Parent Scene XML
Source: https://github.com/godothub/gmui/blob/master/docs/preview/README.md
This XML snippet demonstrates how a parent scene defines content to be inserted into a child scene's slot. The content, wrapped in a `` tag, will be rendered where the `` tag is placed in the child scene's XML, enabling content projection.
```XML
```
--------------------------------
### Component-Level Two-Way Data Binding
Source: https://github.com/godothub/gmui/blob/master/docs/1.2/README.ZH.md
Illustrates how to apply two-way data binding to custom components using `g-model:property`. It also shows how to import custom components into a GMUI page using the `@import` directive.
```XML
```
--------------------------------
### Accessing Virtual Nodes via `ref` and `rnode` - XML & GDScript
Source: https://github.com/godothub/gmui/blob/master/docs/1.1/README.md
This snippet shows how to assign a `ref` to a standard Godot node (like `Label`) within GMUI's XML. The accompanying GDScript then demonstrates accessing the virtual node through `gmui.refs['name']` and subsequently its underlying real Godot node (`rnode`) to retrieve properties like `text`.
```XML
```
```GDScript
```