ViewsContainer

The ViewsContainer interface, which implements View, describes a container that containsseveral child interface elements (View). ViewsContainer is the base for other containers(ListLayout, GridLayout, StackLayout, etc.) and is not used on its own.

In addition to all View properties, this element has only one additional property "content"

"content" property

The "content" property (constant Content) defines an array of child Views. Interface Get functionalways returns []View for the given property.

The following 5 data types can be passed as the value of the "content" property:

  • View - converted to []View containing one element;
  • []View - nil-elements are prohibited, if the array contains nil, then the property will not be set,and the Set function will return false and an error message will be written to the log;
  • string - if the string is a text representation of the View, then the corresponding View is created,otherwise a TextView is created, to which the given string is passed as text.Next, a []View is created containing the resulting View;
  • []string - each element of the array is converted to View as described in the previous paragraph;
  • []any - this array must contain only View and string. Each string element is converted toa View as described above. If the array contains invalid values, the "content" property will not be set,and the Set function will return false and an error message will be written to the log.

You can learn the value of the "content" property using the ViewsContainer interface function

Views() []View

The following functions of the ViewsContainer interface can be used to edit the "content" property:

Append(view View)

This function adds an argument to the end of the View list.

Insert(view View, index uint)

This function inserts an argument at the specified position in the View list.If index is greater than the length of the list, then the View is added to the end of the list.If index is less than 0, then to the beginning of the list.

RemoveView(index uint) View

This function removes the View from the given position and returns it.If index points outside the bounds of the list, then nothing is removed, and the function returns nil.

ViewIndex(view View) int

This function returns the index of the child View, or -1 if there is no such View in the container.It is often used in conjunction with RemoveView if the index of the child View is unknown:

if index := container.ViewIndex(view); index >= 0 {
	container.RemoveView(index)
}