primitives/expanded.go
Functions
func AccessibilityActions
func (e *ExpandedWidget) AccessibilityActions() []a11y.Action {
if acc, ok := e.child.(a11y.Accessible); ok {
return acc.AccessibilityActions()
}
return nil
}
func AccessibilityHint
AccessibilityHint delegates to the child if it implements [a11y.Accessible].
func (e *ExpandedWidget) AccessibilityHint() string {
if acc, ok := e.child.(a11y.Accessible); ok {
return acc.AccessibilityHint()
}
return ""
}
func AccessibilityLabel
AccessibilityLabel delegates to the child if it implements [a11y.Accessible].
func (e *ExpandedWidget) AccessibilityLabel() string {
if acc, ok := e.child.(a11y.Accessible); ok {
return acc.AccessibilityLabel()
}
return ""
}
func AccessibilityRole
AccessibilityRole delegates to the child if it implements [a11y.Accessible],
otherwise returns [a11y.RoleNone].
func (e *ExpandedWidget) AccessibilityRole() a11y.Role {
if acc, ok := e.child.(a11y.Accessible); ok {
return acc.AccessibilityRole()
}
return a11y.RoleUnknown
}
func AccessibilityState
AccessibilityState delegates to the child if it implements [a11y.Accessible].
func (e *ExpandedWidget) AccessibilityState() a11y.State {
if acc, ok := e.child.(a11y.Accessible); ok {
return acc.AccessibilityState()
}
return a11y.State{
Disabled: !e.IsEnabled(),
Hidden: !e.IsVisible(),
}
}
func AccessibilityValue
AccessibilityValue delegates to the child if it implements [a11y.Accessible].
func (e *ExpandedWidget) AccessibilityValue() string {
if acc, ok := e.child.(a11y.Accessible); ok {
return acc.AccessibilityValue()
}
return ""
}
func Child
Child returns the wrapped widget.
func (e *ExpandedWidget) Child() widget.Widget { return e.child }
func Children
Children returns the wrapped child as a single-element slice.
func (e *ExpandedWidget) Children() []widget.Widget {
if e.child == nil {
return nil
}
return []widget.Widget{e.child}
}
func Draw
Draw delegates to the wrapped child, applying a transform for positioning.
func (e *ExpandedWidget) Draw(ctx widget.Context, canvas widget.Canvas) {
if !e.IsVisible() {
return
}
bounds := e.Bounds()
canvas.PushTransform(bounds.Min)
widget.StampScreenOrigin(e.child, canvas)
e.child.Draw(ctx, canvas)
canvas.PopTransform()
}
func Event
Event delegates to the wrapped child with coordinate translation for mouse
and wheel events.
func (e *ExpandedWidget) Event(ctx widget.Context, ev event.Event) bool {
if !e.IsVisible() || !e.IsEnabled() {
return false
}
// Translate mouse events to local coordinates.
if me, ok := ev.(*event.MouseEvent); ok {
local := *me
local.Position = me.Position.Sub(e.Bounds().Min)
return e.child.Event(ctx, &local)
}
// Translate wheel events to local coordinates.
if we, ok := ev.(*event.WheelEvent); ok {
local := *we
local.Position = we.Position.Sub(e.Bounds().Min)
return e.child.Event(ctx, &local)
}
return e.child.Event(ctx, ev)
}
func Expanded
Expanded wraps a widget to mark it as filling remaining space in a BoxWidget.
The child must not be nil.
func Expanded(child widget.Widget) *ExpandedWidget {
e := &ExpandedWidget{child: child}
e.SetVisible(true)
e.SetEnabled(true)
// ADR-028: parent chain for upward dirty propagation.
if child != nil {
type parentSetter interface{ SetParent(widget.Widget) }
if ps, ok := child.(parentSetter); ok {
ps.SetParent(e)
}
}
return e
}
func IsExpanded
IsExpanded returns true. Public API for querying expanded state.
func (e *ExpandedWidget) IsExpanded() bool { return true }
func Layout
Layout delegates to the wrapped child and stores the resulting bounds.
func (e *ExpandedWidget) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size {
size := e.child.Layout(ctx, constraints)
e.child.(interface{ SetBounds(geometry.Rect) }).SetBounds(
geometry.FromPointSize(geometry.Point{}, size),
)
e.SetBounds(geometry.FromPointSize(e.Position(), size))
return size
}
Structs
type ExpandedWidget struct
ExpandedWidget wraps a widget to indicate it should fill all remaining space
in a [BoxWidget] layout (HBox/VBox). Without Expanded, children take only
their intrinsic size. With Expanded, the child receives all space left
after fixed-size siblings are measured.
ExpandedWidget is transparent: it delegates Layout, Draw, Event, and Children
entirely to its wrapped child. It serves only as a marker for the parent
BoxWidget's two-pass layout algorithm.
Usage:
primitives.HBox(
leftPanel.Width(56), // fixed 56px
primitives.Expanded(editor), // fills remaining
rightPanel.Width(40), // fixed 40px
)
Multiple Expanded children in the same BoxWidget split the remaining space
equally:
primitives.HBox(
primitives.Expanded(left), // 50% of remaining
primitives.Expanded(right), // 50% of remaining
)
type ExpandedWidget struct {
widget.WidgetBase
child widget.Widget
}
AccessibilityActions delegates to the child if it implements [a11y.Accessible].