Resource description format

Application resources (themes, views, translations) can be described as text (utf-8).This text is placed in a file with the ".rui" extension.

The root element of the resource file must be an object. It has the following format:

< object name > {
	< object data >
}

if the object name contains the following characters: '=', '{', '}', '[', ']', ',', '', '\t', '\n','\' ',' "','` ',' / 'and any spaces, then the object name must be enclosed in quotation marks.If these characters are not used, then quotation marks are optional.

You can use three types of quotation marks:

  • "…" is equivalent to the same string in the go language, i.e. inside you can use escape sequences:\n, \r, \\, \", \', \0, \t, \x00, \u0000
  • '…' is similar to the line "…"
  • `…` is equivalent to the same string in the go language, i.e. the text within this line remains as is. Insideyou cannot use the ` character.

Object data is a set of < key > = < value > pairs separated by commas.

The key is a string of text. The design rules are the same as for the object name.

Values can be of 3 types:

  • Simple value - a line of text formatted according to the same rules as the name of the object
  • An object
  • Array of values

An array of values is enclosed in square brackets. Array elements are separated by commas.Elements can be simple values or objects.

There may be comments in the text. The design rules are the same as in the go language: // and / * ... * /

Example:

GridLayout {
	id = gridLayout, width = 100%, height = 100%,
	cell-width = "150px, 1fr, 30%", cell-height = "25%, 200px, 1fr",
	content = [
		// Subviews
		TextView { row = 0, column = 0:1,
			text = "View 1", text-align = center, vertical-align = center,
			background-color = #DDFF0000, radius = 8px, padding = 32px,
			border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
		},
		TextView { row = 0:1, column = 2,
			text = "View 2", text-align = center, vertical-align = center,
			background-color = #DD00FF00, radius = 8px, padding = 32px,
			border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
		},
		TextView { row = 1:2, column = 0,
			text = "View 3", text-align = center, vertical-align = center,
			background-color = #DD0000FF, radius = 8px, padding = 32px,
			border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
		},
		TextView { row = 1, column = 1,
			text = "View 4", text-align = center, vertical-align = center,
			background-color = #DDFF00FF, radius = 8px, padding = 32px,
			border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
		},
		TextView { row = 2, column = 1:2,
			text = "View 5", text-align = center, vertical-align = center,
			background-color = #DD00FFFF, radius = 8px, padding = 32px,
			border = _{ style = solid, width = 1px, color = #FFA0A0A0 }
		},
	]
}

To work with text resources, the DataNode interface is used

type DataNode interface {
	Tag() string
	Type() int
	Text() string
	Object() DataObject
	ArraySize() int
	ArrayElement(index int) DataValue
	ArrayElements() []DataValue
}

This element describes the underlying data element.

The Tag method returns the value of the key.

The data type is returned by the Type method. It returns one of 3 values

Value Constant Data type
0 TextNode Simple value
1 ObjectNode Object
2 ArrayNode Array

The Text() method is used to get a simple value.To get an object, use the Object() method.To get the elements of an array, use the ArraySize, ArrayElement and ArrayElements methods