StackLayout
A container that arranges its children on top of each other and each takes up the entire container space. Only one child view can be visible at a time. This container particularly useful in scenarios like navigation menus, main pages etc.
Create from source
func NewStackLayout(session Session, params Params) StackLayout
Create new stack layout object and returns its interface
Create from resource
StackLayout {
id = stackLayout,
width = 100%,
height = 100%,
content = [],
}
Interface description
Inherit methods, properties and events from ViewsContainer
MoveToFront(view View) bool
Makes the given View current. Returns true if successful, false otherwise.
MoveToFrontByID(viewID string) bool
Makes the View current by viewID. Returns true if successful, false otherwise.
Peek() View
Returns the current (visible) View. If StackLayout is empty then it returns nil.
Pop(animation int, onPopFinished func(View)) bool
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.
Push(view View, animation int, onPushFinished func())
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: * DefaultAnimation (0) - Default animation. For the Push function it is EndToStartAnimation, for Pop - StartToEndAnimation; * StartToEndAnimation (1) - Animation from beginning to end. The beginning and the end are determined by the direction of the text output; * EndToStartAnimation (2) - End-to-Beginning animation; * TopDownAnimation (3) - Top-down animation; * BottomUpAnimation (4) - Bottom up animation. The third argument onPushFinished
is the function to be called when the animation ends. It may be nil.
RemovePeek() View
Removes the current View and returns it. If StackLayout is empty then it doesn't do anything and returns nil.
Properties
"content"
An array of child views
Constant: Content
Types: View
, []View
, string
, []string
, []any
containing elements of View
, string
Internal type is []View
, other types converted to it during assignment
Conversion rules
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 a text. Then a []View
is created containing the resulting view
[]string
- each element of an array is converted to View
as described above
[]any
- this array must contain only View
and a string
. Each string
element is converted to a view as described above. If 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
Examples
StackLayout {
id = stack,
width = 100%,
height = 100%,
content = [
ListLayout {
id = page1,
width = 100%,
height = 100%,
content = "Page 1",
},
ListLayout {
id = page2,
width = 100%,
height = 100%,
content = "Page 2",
},
],
}
stack := rui.NewStackLayout(session, rui.Params{
rui.ID: "stack",
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
rui.Content: []rui.View{
rui.NewListLayout(session, rui.Params{
rui.ID: "page1",
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
rui.Content: "Page 1",
}),
rui.NewListLayout(session, rui.Params{
rui.ID: "page2",
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
rui.Content: "Page 2",
}),
},
})
stack := rui.NewStackLayout(session, rui.Params{
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
})
page1 := rui.NewListLayout(session, rui.Params{
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
rui.Content: "Page 1",
})
stack.Push(page1, rui.StartToEndAnimation, nil)
// Add another view at some point later
page2 := rui.NewListLayout(session, rui.Params{
rui.Width: rui.Percent(100),
rui.Height: rui.Percent(100),
rui.Content: "Page 2",
})
stack.Push(page2, rui.StartToEndAnimation, nil)
// Pop top most view at some point later
stack.Pop(rui.EndToStartAnimation, nil)
"current"
Set or Index of current(visible) view
Constant: Current
Types: int
, string
Values
int | string | Description |
---|---|---|
-1 |
"-1" | No visible view |
>= 0 |
>= "0" | Index of visible view |
Related global functions
func StackLayoutByID(rootView View, id string) StackLayout
Return a StackLayout
with id equal to the argument of the function or nil if there is no such View or View is not a StackLayout