layout

package
v0.1.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BreakpointCompact is the threshold for compact mode (< 40 cols)
	BreakpointCompact = 40
	// BreakpointBasic is the threshold for basic mode (40-80 cols)
	BreakpointBasic = 80
	// BreakpointFull is the threshold for full mode (80-100 cols)
	BreakpointFull = 100
	// BreakpointExtended is the threshold for extended mode (100+ cols)
	BreakpointExtended = 100
)

Breakpoint constants from statusbar.go (preserved from existing implementation)

Variables

This section is empty.

Functions

func IsBasicMode

func IsBasicMode(width int) bool

IsBasicMode returns true if width is in basic mode

func IsCompactMode

func IsCompactMode(width int) bool

IsCompactMode returns true if width is in compact mode

func IsExtendedMode

func IsExtendedMode(width int) bool

IsExtendedMode returns true if width is in extended mode

func IsFullMode

func IsFullMode(width int) bool

IsFullMode returns true if width is in full mode

Types

type BoxLayout

type BoxLayout struct {
	// contains filtered or unexported fields
}

BoxLayout arranges components in a single direction (vertical or horizontal)

func NewBoxLayout

func NewBoxLayout(orientation Orientation) *BoxLayout

NewBoxLayout creates a new box layout with the specified orientation

func NewBoxLayoutWithSpacing

func NewBoxLayoutWithSpacing(orientation Orientation, spacing int) *BoxLayout

NewBoxLayoutWithSpacing creates a new box layout with custom spacing

func (*BoxLayout) Calculate

func (b *BoxLayout) Calculate(available Rectangle, components []ComponentInfo) map[string]Rectangle

Calculate computes component bounds based on box layout algorithm

func (*BoxLayout) GetOrientation

func (b *BoxLayout) GetOrientation() Orientation

GetOrientation returns the current layout orientation

func (*BoxLayout) GetSpacing

func (b *BoxLayout) GetSpacing() int

GetSpacing returns the current spacing between components

func (*BoxLayout) SetOrientation

func (b *BoxLayout) SetOrientation(orientation Orientation)

SetOrientation changes the layout orientation

func (*BoxLayout) SetSpacing

func (b *BoxLayout) SetSpacing(spacing int)

SetSpacing updates the spacing between components

type BreakpointConfig

type BreakpointConfig struct {
	MinWidth int    // Minimum width for this breakpoint
	Layout   Layout // Layout to use at this breakpoint
}

BreakpointConfig defines a layout configuration for a specific breakpoint

type ComponentInfo

type ComponentInfo struct {
	ID          string
	Constraints Constraints
	Order       int // Registration order for stable sorting
}

ComponentInfo holds component metadata for layout calculation

type Constraints

type Constraints struct {
	MinWidth  int  // Minimum width (0 = no minimum)
	MinHeight int  // Minimum height (0 = no minimum)
	MaxWidth  int  // Maximum width (0 = unlimited)
	MaxHeight int  // Maximum height (0 = unlimited)
	Grow      bool // Whether the component can grow to fill available space
	Shrink    bool // Whether the component can shrink below its preferred size
	Weight    int  // Flex weight for distributing extra space (higher = more space)
}

Constraints define size requirements and flexibility for a component

func DefaultConstraints

func DefaultConstraints() Constraints

DefaultConstraints returns constraints with sensible defaults

func FixedConstraints

func FixedConstraints(width, height int) Constraints

FixedConstraints creates constraints for a fixed-size component

func FlexConstraints

func FlexConstraints(minHeight, weight int) Constraints

FlexConstraints creates constraints for a flexible component

type Layout

type Layout interface {
	// Calculate computes component bounds based on available space and constraints
	Calculate(available Rectangle, components []ComponentInfo) map[string]Rectangle
}

Layout defines how components are arranged within a container

type LayoutManager

type LayoutManager interface {
	// RegisterComponent registers a component with its constraints
	RegisterComponent(id string, constraints Constraints) error
	// UnregisterComponent removes a component from management
	UnregisterComponent(id string) error
	// SetAvailableSize sets the container size available for layout
	SetAvailableSize(width, height int)
	// GetComponentBounds returns the calculated bounds for a component
	GetComponentBounds(id string) Rectangle
	// RecalculateLayout recalculates all component positions
	RecalculateLayout() error
	// IsDirty returns whether the layout needs recalculation
	IsDirty() bool
}

LayoutManager manages component positioning within a container

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the default implementation of LayoutManager

func NewManager

func NewManager(layout Layout) *Manager

NewManager creates a new layout manager with the specified layout algorithm

func (*Manager) Clear

func (m *Manager) Clear()

Clear removes all components and resets the manager

func (*Manager) GetComponentBounds

func (m *Manager) GetComponentBounds(id string) Rectangle

GetComponentBounds returns the calculated bounds for a component

func (*Manager) GetComponentCount

func (m *Manager) GetComponentCount() int

GetComponentCount returns the number of registered components

func (*Manager) IsDirty

func (m *Manager) IsDirty() bool

IsDirty returns whether the layout needs recalculation

func (*Manager) RecalculateLayout

func (m *Manager) RecalculateLayout() error

RecalculateLayout recalculates all component positions using the layout algorithm

func (*Manager) RegisterComponent

func (m *Manager) RegisterComponent(id string, constraints Constraints) error

RegisterComponent registers a component with its layout constraints

func (*Manager) SetAvailableSize

func (m *Manager) SetAvailableSize(width, height int)

SetAvailableSize updates the container size and marks layout as dirty

func (*Manager) SetLayout

func (m *Manager) SetLayout(layout Layout)

SetLayout changes the layout algorithm and marks as dirty

func (*Manager) UnregisterComponent

func (m *Manager) UnregisterComponent(id string) error

UnregisterComponent removes a component from layout management

type Orientation

type Orientation int

Orientation defines the direction of layout flow

const (
	// Vertical orientation stacks components top to bottom
	Vertical Orientation = iota
	// Horizontal orientation arranges components left to right
	Horizontal
)

type Rectangle

type Rectangle struct {
	X      int // X position (left edge)
	Y      int // Y position (top edge)
	Width  int // Width in characters
	Height int // Height in lines
}

Rectangle represents a positioned area in the UI

type ResponsiveLayout

type ResponsiveLayout struct {
	// contains filtered or unexported fields
}

ResponsiveLayout switches between different layouts based on container width

func NewResponsiveLayout

func NewResponsiveLayout(defaultLayout Layout) *ResponsiveLayout

NewResponsiveLayout creates a new responsive layout with a default layout

func (*ResponsiveLayout) AddBreakpoint

func (r *ResponsiveLayout) AddBreakpoint(minWidth int, layout Layout)

AddBreakpoint adds a layout configuration for a specific width breakpoint

func (*ResponsiveLayout) Calculate

func (r *ResponsiveLayout) Calculate(available Rectangle, components []ComponentInfo) map[string]Rectangle

Calculate selects the appropriate layout based on width and calculates component bounds

func (*ResponsiveLayout) ClearBreakpoints

func (r *ResponsiveLayout) ClearBreakpoints()

ClearBreakpoints removes all breakpoint configurations

func (*ResponsiveLayout) GetBreakpointCount

func (r *ResponsiveLayout) GetBreakpointCount() int

GetBreakpointCount returns the number of configured breakpoints

func (*ResponsiveLayout) GetCurrentBreakpoint

func (r *ResponsiveLayout) GetCurrentBreakpoint(width int) string

GetCurrentBreakpoint returns the name of the current breakpoint for the given width

func (*ResponsiveLayout) SetDefaultLayout

func (r *ResponsiveLayout) SetDefaultLayout(layout Layout)

SetDefaultLayout changes the default layout

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL