mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
ui/layout: document List, Stack
Tweak Flex documentation. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -30,8 +30,7 @@ type Flex struct {
|
|||||||
maxBaseline int
|
maxBaseline int
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlexChild is the layout result of a call to Rigid or
|
// FlexChild is the layout result of a call End.
|
||||||
// Flexible.
|
|
||||||
type FlexChild struct {
|
type FlexChild struct {
|
||||||
macro ui.MacroOp
|
macro ui.MacroOp
|
||||||
dims Dimens
|
dims Dimens
|
||||||
@@ -67,6 +66,7 @@ const (
|
|||||||
modeFlex
|
modeFlex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Init must be called before Rigid or Flexible.
|
||||||
func (f *Flex) Init(ops *ui.Ops, cs Constraints) *Flex {
|
func (f *Flex) Init(ops *ui.Ops, cs Constraints) *Flex {
|
||||||
if f.mode > modeBegun {
|
if f.mode > modeBegun {
|
||||||
panic("must End the current child before calling Init again")
|
panic("must End the current child before calling Init again")
|
||||||
|
|||||||
+7
-2
@@ -17,9 +17,14 @@ type scrollChild struct {
|
|||||||
macro ui.MacroOp
|
macro ui.MacroOp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List displays a subsection of a potentially infinitely
|
||||||
|
// large underlying list. List accepts user input to scroll
|
||||||
|
// the subsection.
|
||||||
type List struct {
|
type List struct {
|
||||||
Axis Axis
|
Axis Axis
|
||||||
Invert bool
|
// Invert inverts a List so it is anchored from its end.
|
||||||
|
Invert bool
|
||||||
|
// Alignment is the cross axis alignment.
|
||||||
Alignment Alignment
|
Alignment Alignment
|
||||||
|
|
||||||
// The distance scrolled since last call to Init.
|
// The distance scrolled since last call to Init.
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ import (
|
|||||||
"gioui.org/ui"
|
"gioui.org/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Stack lays out child elements on top of each other,
|
||||||
|
// according to an alignment direction.
|
||||||
type Stack struct {
|
type Stack struct {
|
||||||
|
// Alignment is the direction to align children
|
||||||
|
// smaller than the available space.
|
||||||
Alignment Direction
|
Alignment Direction
|
||||||
|
|
||||||
macro ui.MacroOp
|
macro ui.MacroOp
|
||||||
@@ -20,11 +24,13 @@ type Stack struct {
|
|||||||
baseline int
|
baseline int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StackChild is the layout result of a call to End.
|
||||||
type StackChild struct {
|
type StackChild struct {
|
||||||
macro ui.MacroOp
|
macro ui.MacroOp
|
||||||
dims Dimens
|
dims Dimens
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init a stack before calling Rigid or Expand.
|
||||||
func (s *Stack) Init(ops *ui.Ops, cs Constraints) *Stack {
|
func (s *Stack) Init(ops *ui.Ops, cs Constraints) *Stack {
|
||||||
s.ops = ops
|
s.ops = ops
|
||||||
s.cs = cs
|
s.cs = cs
|
||||||
@@ -45,11 +51,15 @@ func (s *Stack) begin() {
|
|||||||
s.macro.Record(s.ops)
|
s.macro.Record(s.ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rigid begins a child with the same constraints that were
|
||||||
|
// passed to Init.
|
||||||
func (s *Stack) Rigid() Constraints {
|
func (s *Stack) Rigid() Constraints {
|
||||||
s.begin()
|
s.begin()
|
||||||
return s.cs
|
return s.cs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expand begins a child with constraints that exactly match
|
||||||
|
// the biggest child previously added.
|
||||||
func (s *Stack) Expand() Constraints {
|
func (s *Stack) Expand() Constraints {
|
||||||
s.begin()
|
s.begin()
|
||||||
return Constraints{
|
return Constraints{
|
||||||
@@ -58,6 +68,7 @@ func (s *Stack) Expand() Constraints {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// End a child by specifying its dimensions.
|
||||||
func (s *Stack) End(dims Dimens) StackChild {
|
func (s *Stack) End(dims Dimens) StackChild {
|
||||||
s.macro.Stop()
|
s.macro.Stop()
|
||||||
s.begun = false
|
s.begun = false
|
||||||
@@ -75,6 +86,8 @@ func (s *Stack) End(dims Dimens) StackChild {
|
|||||||
return StackChild{s.macro, dims}
|
return StackChild{s.macro, dims}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Layout a list of children. The order of the children determines their laid
|
||||||
|
// out order.
|
||||||
func (s *Stack) Layout(children ...StackChild) Dimens {
|
func (s *Stack) Layout(children ...StackChild) Dimens {
|
||||||
for _, ch := range children {
|
for _, ch := range children {
|
||||||
sz := ch.dims.Size
|
sz := ch.dims.Size
|
||||||
|
|||||||
Reference in New Issue
Block a user