gdml
gdml copied to clipboard
Godot Markup Language
GDML (Godot Markup Language)
An HTML-inspired markup language for Godot UIs.
GDML parses an xml file and generates a corresponding tree of Godot Nodes to be added to the SceneTree. Anonymous, inline scripts are allowed along with loading scripts from a context path.
Quickstart
- Copy the
./addons/gdml/directory to your project'saddonsdirectory - Load
.addons/gdml/gdml.gdand instance it. A context path (the directory containing thexmlfiles + resources) must be provided - Call the
generatemethod. A file name must be provided relative to the context path- e.g.
var my_output: Control = gdml.generate("my_file.xml")
- e.g.
- Add the output to the
SceneTree
Example
my_gdml_file.xml
- Create a
CanvasLayeron layer -1 and a blackColorRectto act as the background. - Creates a
gdmlcontainer node that holds an anonymous script. - A
VBoxContaineris created inside thegdmlnode that contains aLabeland aButton. - The
Buttonis hooked up to the anonymous script to print "hello" when the element is pressed.
<canvas_layer gdml_props="layer: -1">
<color_rect gdml_name="Background" gdml_style="anchor: full_rect; color: (colorN) Black"/>
</canvas_layer>
<gdml gdml_style="anchor: full_rect; margin_top: 10; margin_left: 10">
<gdml_script>
func say_hello():
print("hello")
</gdml_script>
<v_box_container gdml_style="anchor: full_rect">
<label>Hello label!</label>
<button pressed="say_hello">click me</button>
</v_box_container>
</gdml>
my_scene.gd
- Load in
gdml.gdand create a new instance. A path to the directory containing validgdmlxmlfiles should be provided gdml.generate(...)is called, specifying the main entrypoint for the output- The output is added as a child
extends Node
func _ready():
var gdml = load("path_to_gdml_gd").new("path_to_folder_containing_my_gdml_file")
var gui = gdml.generate("my_gdml_file.xml")
add_child(gui)
Design Decisions
- GDML-specific properties are prepended with
gdml_in order to namespace them - There is an implicit, global
gdmlnode that wraps eachxmlfile- This is needed since scripts can be placed at the root level
gdml_propsis an alias ofgdml_styleas they work in the same way (aka styles for GodotControls are just properties)- Context paths are used instead of
res://paths, as the library is meant to be used for runtime loaded UIs. Because of this, context paths will generally point outside of the project
3rd Party Libraries
- godot-css-theme
- Modified to namespace the classes