StackLayout
StackLayout is a container that implements the ViewsContainer interface.All child Views are stacked on top of each other and each takes up the entire container space.Only one child View (current) is available at a time.
To create a StackLayout, use the function
func NewStackLayout(session Session, params Params) StackLayout
In addition to the Append, Insert, RemoveView properties and the "content" property of the ViewsContainer,the StackLayout container has two other interface functions for manipulating child Views: Push and Pop.
Push(view View, animation int, onPushFinished func())
This function adds a new View to the container and makes it current.It is similar to Append, but the addition is done using an animation effect.The animation type is specified by the second argument and can take the following values:
Value | Constant | Animation |
---|---|---|
0 | DefaultAnimation | Default animation. For the Push function it is EndToStartAnimation, for Pop - StartToEndAnimation |
1 | StartToEndAnimation | Animation from beginning to end. The beginning and the end are determined by the direction of the text output |
2 | EndToStartAnimation | End-to-Beginning animation. |
3 | TopDownAnimation | Top-down animation. |
4 | BottomUpAnimation | Bottom up animation. |
The third argument onPushFinished is the function to be called when the animation ends. It may be nil.
Pop(animation int, onPopFinished func(View)) bool
This function removes the current View from the container using animation.The second argument onPopFinished is the function to be called when the animation ends. It may be nil.The function will return false if the StackLayout is empty and true if the current item has been removed.
You can get the current (visible) View using the interface function
Peek() View
You can also get the current View using its index. The "current" property (constant Current) is used to get the index.Example
func peek(layout rui.StackLayout) { views := layout.Views() if index := rui.GetCurrent(layout); index >= 0 && index < len(views) { return views[index] } return nil }
Of course, this is less convenient than the Peek function. However, the "current" property can be used to track changes to the current View:
layout.SetChangeListener(rui.Current, func(view rui.View, tag string) { // current view changed })
In order to make any child View current (visible), the interface functions are used:
MoveToFront(view View) bool MoveToFrontByID(viewID string) bool
This function will return true if successful and false if the child View orView with id does not exist and an error message will be written to the log.
You can also use the "current" property to make any child View current (visible).