Documentation
¶
Overview ¶
Package layout defines the various layouts available to Bellui apps.
Index ¶
- Variables
- func MirrorChildren(objects []core.CanvasObject, totalWidth float32)
- func NewAdaptiveGridLayout(rowcols int) core.Layout
- func NewBorderLayout(top, bottom, left, right core.CanvasObject) core.Layout
- func NewCenterLayout() core.Layout
- func NewCustomPaddedHBoxLayout(padding float32) core.Layout
- func NewCustomPaddedLayout(padTop, padBottom, padLeft, padRight float32) core.Layout
- func NewCustomPaddedVBoxLayout(padding float32) core.Layout
- func NewFormLayout() core.Layout
- func NewGridLayout(cols int) core.Layout
- func NewGridLayoutWithColumns(cols int) core.Layout
- func NewGridLayoutWithRows(rows int) core.Layout
- func NewGridWrapLayout(size geo.Size) core.Layout
- func NewHBoxLayout() core.Layout
- func NewPaddedLayout() core.Layout
- func NewResponsiveLayout(objects ...core.CanvasObject) *bellui.Container
- func NewRowWrapLayout() core.Layout
- func NewRowWrapLayoutWithCustomPadding(horizontal, vertical float32) core.Layout
- func NewShrinkLayout() core.Layout
- func NewSpacer() core.CanvasObject
- func NewStackLayout() core.Layout
- func NewVBoxLayout() core.Layout
- func Responsive(object core.CanvasObject, ratios ...float32) core.CanvasObject
- type CustomPaddedLayout
- type FlexHBoxLayout
- type FlexVBoxLayout
- type ResponsiveLayout
- type Spacer
- func (s *Spacer) ExpandHorizontal() bool
- func (s *Spacer) ExpandVertical() bool
- func (s *Spacer) Hide()
- func (s *Spacer) MinSize() geo.Size
- func (s *Spacer) Move(pos geo.Position)
- func (s *Spacer) Position() geo.Position
- func (s *Spacer) Refresh()
- func (s *Spacer) Resize(size geo.Size)
- func (s *Spacer) Show()
- func (s *Spacer) Size() geo.Size
- func (s *Spacer) Visible() bool
- type SpacerObject
Constants ¶
This section is empty.
Variables ¶
var DefaultResponsiveBreakpoints = []float32{600, 840, 1200, 1600}
DefaultResponsiveBreakpoints are the Material Design 3 window size class boundaries, in dp: compact <600, medium <840, expanded <1200, large <1600, extra-large >=1600. Each value is the exclusive upper bound of one size class; widths at or beyond the last bound fall in the final class. Assign a custom ascending table to ResponsiveLayout.Breakpoints to use different classes — e.g. Bootstrap's 576, 768, 992, 1200.
Functions ¶
func MirrorChildren ¶
func MirrorChildren(objects []core.CanvasObject, totalWidth float32)
MirrorChildren reflects every visible child horizontally within totalWidth so that a left-to-right arrangement becomes its right-to-left mirror. A child occupying [x, x+width) on the left is moved to the equivalent span measured from the right edge; vertical positions and all sizes are preserved. Full-width children (such as VBox rows or Border top/bottom bars) map onto themselves, so the reflection is a no-op for them.
It is applied as a post-pass after a layout has positioned its children, keeping the original (left-to-right) positioning code untouched. The standard layouts call it directly; custom-renderer widgets reach it via the widget package's mirrorIfRTL helper.
func NewAdaptiveGridLayout ¶
NewAdaptiveGridLayout returns a new grid layout which uses columns when horizontal but rows when vertical.
func NewBorderLayout ¶
func NewBorderLayout(top, bottom, left, right core.CanvasObject) core.Layout
NewBorderLayout creates a new BorderLayout instance with top, bottom, left and right objects set. All other items in the container will fill the remaining space in the middle. Multiple extra items will be stacked in the specified order as a Stack container.
func NewCenterLayout ¶
NewCenterLayout creates a new CenterLayout instance
func NewCustomPaddedHBoxLayout ¶
NewCustomPaddedHBoxLayout returns a layout similar to HBoxLayout that uses a custom amount of padding in between objects instead of the theme.Padding value.
Since: 1.0
func NewCustomPaddedLayout ¶
NewCustomPaddedLayout creates a new CustomPaddedLayout instance with the specified paddings.
Since: 1.0
func NewCustomPaddedVBoxLayout ¶
NewCustomPaddedVBoxLayout returns a layout similar to VBoxLayout that uses a custom amount of padding in between objects instead of the theme.Padding value.
Since: 1.0
func NewFormLayout ¶
NewFormLayout returns a new FormLayout instance
func NewGridLayout ¶
NewGridLayout returns a grid layout arranged in a specified number of columns. The number of rows will depend on how many children are in the container that uses this layout.
func NewGridLayoutWithColumns ¶
NewGridLayoutWithColumns returns a new grid layout that specifies a column count and wrap to new rows when needed.
func NewGridLayoutWithRows ¶
NewGridLayoutWithRows returns a new grid layout that specifies a row count that creates new rows as required.
func NewGridWrapLayout ¶
NewGridWrapLayout returns a new GridWrapLayout instance
func NewHBoxLayout ¶
NewHBoxLayout returns a horizontal box layout for stacking a number of child canvas objects or widgets left to right. The objects are always displayed at their horizontal MinSize. Use a different layout if the objects are intended to be larger than their horizontal MinSize.
func NewResponsiveLayout ¶
func NewResponsiveLayout(objects ...core.CanvasObject) *bellui.Container
NewResponsiveLayout returns a container with a ResponsiveLayout using the MD3 window size classes. Each object may declare per-class width ratios by being wrapped with Responsive; a plain object occupies a full row in every class.
Example:
container := layout.NewResponsiveLayout(
layout.Responsive(label, 1, .5, .25), // full width when compact, half when medium, quarter beyond
layout.Responsive(button, 1, .5, .25),
label2, // full row in every class
)
Since: 1.0
func NewRowWrapLayout ¶
NewRowWrapLayout returns a layout that dynamically arranges objects of similar height in rows and wraps them dynamically. Objects are separated with horizontal and vertical padding.
Since: 1.0
func NewRowWrapLayoutWithCustomPadding ¶
NewRowWrapLayoutWithCustomPadding returns a new RowWrapLayout instance with custom horizontal and inner padding.
Since: 1.0
func NewShrinkLayout ¶
NewShrinkLayout creates a layout that reports MinSize (0, 0) and positions every child at position (0, 0) with the full container size. This is useful when a resizable parent (Split, Scroll, AppTabs) must be able to shrink below the natural minimum size of its content.
Since: 1.0
func NewSpacer ¶
func NewSpacer() core.CanvasObject
NewSpacer returns a spacer object which can fill vertical and horizontal space. This is primarily used with a box layout.
func NewStackLayout ¶
NewStackLayout returns a new StackLayout instance. Objects are stacked on top of each other with later objects on top of those before. Having only a single object has no impact as CanvasObjects will fill the available space even without a Stack.
Since: 1.0
func NewVBoxLayout ¶
NewVBoxLayout returns a vertical box layout for stacking a number of child canvas objects or widgets top to bottom. The objects are always displayed at their vertical MinSize. Use a different layout if the objects are intended to be larger than their vertical MinSize.
func Responsive ¶
func Responsive(object core.CanvasObject, ratios ...float32) core.CanvasObject
Responsive wraps the given object with a responsive width configuration for use inside NewResponsiveLayout. The optional ratios must satisfy 0 < ratio <= 1 (out-of-range values are logged and treated as 1) and apply to the size classes in ascending order:
Responsive(object, compact, medium, expanded, large, extraLarge)
A class without a ratio inherits the previous one, or 1.0 when none was given at all.
Since: 1.0
Types ¶
type CustomPaddedLayout ¶
type CustomPaddedLayout struct {
TopPadding float32
BottomPadding float32
LeftPadding float32
RightPadding float32
}
CustomPaddedLayout is a layout similar to PaddedLayout, but uses custom values for padding on each side, rather than the theme padding value.
Since: 1.0
func (CustomPaddedLayout) Layout ¶
func (c CustomPaddedLayout) Layout(objects []core.CanvasObject, size geo.Size)
Layout is called to pack all child objects into a specified size. For CustomPaddedLayout this sets all children to the full size passed minus the given paddings all around.
func (CustomPaddedLayout) MinSize ¶
func (c CustomPaddedLayout) MinSize(objects []core.CanvasObject) (min geo.Size)
MinSize finds the smallest size that satisfies all the child objects. For CustomPaddedLayout this is determined simply as the MinSize of the largest child plus the given paddings all around.
type FlexHBoxLayout ¶
type FlexHBoxLayout struct {
Flex []float32 // flex grow factor per child (0 = fixed size)
MinWidth []float32 // minimum width per child (0 = use MinSize)
MaxWidth []float32 // maximum width per child (0 = no limit)
MinHeight []float32 // cross-axis minimum height per child (0 = unset); Since: 1.0
MaxHeight []float32 // cross-axis maximum height per child (0 = no limit, full stretch); Since: 1.0
Padding float32 // spacing between children (0 = theme default)
}
FlexHBoxLayout is a horizontal layout where children can have flex grow factors and min/max width constraints. Children with flex=0 get their natural MinSize. Remaining space is distributed proportionally among children with flex>0.
The main axis is horizontal: Flex/MinWidth/MaxWidth constrain width. The cross axis is vertical and children are stretched to the container height by default; the optional MinHeight/MaxHeight arrays clamp a child's height instead (start/top-aligned within the freed space).
Since: 1.0
func NewFlexHBoxLayout ¶
func NewFlexHBoxLayout(flex []float32) *FlexHBoxLayout
NewFlexHBoxLayout creates a horizontal flex layout with the given per-child grow factors. Children with flex=0 use their natural MinSize; remaining space is split proportionally among children with flex>0.
func (*FlexHBoxLayout) Layout ¶
func (l *FlexHBoxLayout) Layout(objects []core.CanvasObject, size geo.Size)
func (*FlexHBoxLayout) MinSize ¶
func (l *FlexHBoxLayout) MinSize(objects []core.CanvasObject) geo.Size
type FlexVBoxLayout ¶
type FlexVBoxLayout struct {
Flex []float32 // flex grow factor per child
MinHeight []float32 // minimum height per child
MaxHeight []float32 // maximum height per child
MinWidth []float32 // cross-axis minimum width per child (0 = unset); Since: 1.0
MaxWidth []float32 // cross-axis maximum width per child (0 = no limit, full stretch); Since: 1.0
Padding float32 // spacing between children (0 = theme default)
}
FlexVBoxLayout is the vertical equivalent of FlexHBoxLayout. Children with flex>0 share remaining vertical space proportionally.
The main axis is vertical: Flex/MinHeight/MaxHeight constrain height. The cross axis is horizontal and children are stretched to the container width by default; the optional MinWidth/MaxWidth arrays clamp a child's width instead (start/left-aligned within the freed space).
Since: 1.0
func NewFlexVBoxLayout ¶
func NewFlexVBoxLayout(flex []float32) *FlexVBoxLayout
NewFlexVBoxLayout creates a vertical flex layout with the given per-child grow factors.
func (*FlexVBoxLayout) Layout ¶
func (l *FlexVBoxLayout) Layout(objects []core.CanvasObject, size geo.Size)
func (*FlexVBoxLayout) MinSize ¶
func (l *FlexVBoxLayout) MinSize(objects []core.CanvasObject) geo.Size
type ResponsiveLayout ¶
type ResponsiveLayout struct {
// Breakpoints are the ascending, exclusive upper bounds (in dp) of each
// size class except the last. When nil, [DefaultResponsiveBreakpoints]
// (the MD3 window size classes) apply. A ratio configuration always
// holds five entries; with a shorter table the trailing entries are
// unused, with a longer one the last entry repeats.
Breakpoints []float32
// contains filtered or unexported fields
}
ResponsiveLayout lays out objects in rows, giving each object a width that is its configured ratio of the container width for the active size class (see Responsive) and wrapping to a new row when a row's ratios would exceed the full width. Rows are as tall as their tallest member and mirror under a right-to-left layout direction.
Since: 1.0
func (*ResponsiveLayout) Layout ¶
func (r *ResponsiveLayout) Layout(objects []core.CanvasObject, containerSize geo.Size)
Layout is called to pack all child objects into a specified size.
Implements: core.Layout
func (*ResponsiveLayout) MinSize ¶
func (r *ResponsiveLayout) MinSize(objects []core.CanvasObject) geo.Size
MinSize returns the smallest size this layout needs: the widest child's minimum width (rows reflow, so no row is forced wider than one child) and the height of the current arrangement. Before the first layout pass it estimates a single-column stack.
Implements: core.Layout
type Spacer ¶
type Spacer struct {
FixHorizontal bool
FixVertical bool
// contains filtered or unexported fields
}
Spacer is any simple object that can be used in a box layout to space out child objects
func (*Spacer) ExpandHorizontal ¶
ExpandHorizontal returns whether or not this spacer expands on the horizontal axis
func (*Spacer) ExpandVertical ¶
ExpandVertical returns whether or not this spacer expands on the vertical axis
func (*Spacer) Refresh ¶
func (s *Spacer) Refresh()
Refresh does nothing for a spacer but is part of the CanvasObject definition
type SpacerObject ¶
SpacerObject is any object that can be used to space out child objects