widgets
Package widgets provides UI components for building widget trees.
This package contains the concrete widget implementations that developers use to build user interfaces, including layout widgets (Row, Column, Stack), display widgets (Text, Icon, Image), input widgets (Button, TextField, Checkbox), and container widgets (Container, Padding, SizedBox).
Layout Widgets
Use Row and Column for horizontal and vertical layouts:
widgets.Row{Children: []core.Widget{...}}
widgets.Column{Children: []core.Widget{...}}
Helper functions provide a more concise syntax:
widgets.RowOf(alignment, crossAlignment, size, child1, child2, child3)
widgets.ColumnOf(alignment, crossAlignment, size, child1, child2, child3)
Input Widgets
Button, TextField, Checkbox, Radio, and Switch handle user input. Use the builder pattern for customization:
widgets.NewButton("Submit", onTap).WithPadding(padding).WithColor(bg, text)
Scrolling
ScrollView provides scrollable content with customizable physics:
widgets.ScrollView{Child: content, Physics: widgets.BouncingScrollPhysics{}}
func Clamp
func Clamp(value, min, max float64) float64
Clamp constrains a value between min and max bounds.
func DeviceScaleOf
func DeviceScaleOf(ctx core.BuildContext) float64
DeviceScaleOf returns the current device scale, defaulting to 1 if not found.
func HandleDropdownPointerDown
func HandleDropdownPointerDown(entries []layout.RenderObject)
HandleDropdownPointerDown dismisses open dropdowns on outside taps.
func HasActiveBallistics
func HasActiveBallistics() bool
HasActiveBallistics returns true if any scroll simulations are running.
func Ptr
func Ptr(v float64) *float64
Ptr returns a pointer to the given float64 value. This is a convenience helper for Positioned widget fields:
Positioned{Left: widgets.Ptr(8), Top: widgets.Ptr(16), ChildWidget: child}
func RegisterRestartAppFn
func RegisterRestartAppFn(fn func())
RegisterRestartAppFn registers the function to restart the app. This is called by the engine package during initialization.
func SafeAreaBottomOf
func SafeAreaBottomOf(ctx core.BuildContext) float64
SafeAreaBottomOf returns only the bottom safe area inset. Widgets calling this will only rebuild when the bottom inset changes.
func SafeAreaLeftOf
func SafeAreaLeftOf(ctx core.BuildContext) float64
SafeAreaLeftOf returns only the left safe area inset. Widgets calling this will only rebuild when the left inset changes.
func SafeAreaOf
func SafeAreaOf(ctx core.BuildContext) layout.EdgeInsets
SafeAreaOf returns the current safe area insets from context. Widgets calling this will rebuild when any inset changes.
func SafeAreaPadding
func SafeAreaPadding(ctx core.BuildContext) layout.EdgeInsets
SafeAreaPadding returns the safe area insets as EdgeInsets for use with ScrollView.Padding or other widgets. The returned EdgeInsets can be modified using chainable methods:
ScrollView{
Padding: widgets.SafeAreaPadding(ctx), // just safe area
ChildWidget: ...,
}
ScrollView{
Padding: widgets.SafeAreaPadding(ctx).Add(24), // safe area + 24px all sides
ChildWidget: ...,
}
ScrollView{
Padding: widgets.SafeAreaPadding(ctx).OnlyTop().Add(24), // only top safe area + 24px
ChildWidget: ...,
}
func SafeAreaRightOf
func SafeAreaRightOf(ctx core.BuildContext) float64
SafeAreaRightOf returns only the right safe area inset. Widgets calling this will only rebuild when the right inset changes.
func SafeAreaTopOf
func SafeAreaTopOf(ctx core.BuildContext) float64
SafeAreaTopOf returns only the top safe area inset. Widgets calling this will only rebuild when the top inset changes.
func StepBallistics
func StepBallistics()
StepBallistics advances any active scroll simulations.
type AnimatedContainer
AnimatedContainer is a Container that animates changes to its properties.
When properties like Color, Width, Height, Padding, or Alignment change, the widget automatically animates from the old value to the new value over the specified Duration using the specified Curve.
Note: Gradient is not animated; changes to Gradient will apply immediately.
Example:
widgets.AnimatedContainer{
Duration: 300 * time.Millisecond,
Curve: animation.EaseInOut,
Color: s.isActive ? colors.Primary : colors.Surface,
Width: 100,
Height: 100,
ChildWidget: child,
}
type AnimatedContainer struct {
// Duration is the length of the animation.
Duration time.Duration
// Curve transforms the animation progress. If nil, uses linear interpolation.
Curve func(float64) float64
// OnEnd is called when the animation completes.
OnEnd func()
// Container properties that will be animated when they change.
Padding layout.EdgeInsets
Width float64
Height float64
Color rendering.Color
Gradient *rendering.Gradient
Alignment layout.Alignment
ChildWidget core.Widget
}
func (AnimatedContainer) CreateElement
func (a AnimatedContainer) CreateElement() core.Element
func (AnimatedContainer) CreateState
func (a AnimatedContainer) CreateState() core.State
func (AnimatedContainer) Key
func (a AnimatedContainer) Key() any
type AnimatedOpacity
AnimatedOpacity animates changes to opacity over a duration.
When the Opacity property changes, the widget automatically animates from the old value to the new value over the specified Duration.
Example:
widgets.AnimatedOpacity{
Duration: 200 * time.Millisecond,
Curve: animation.EaseOut,
Opacity: s.isVisible ? 1.0 : 0.0,
ChildWidget: child,
}
type AnimatedOpacity struct {
// Duration is the length of the animation.
Duration time.Duration
// Curve transforms the animation progress. If nil, uses linear interpolation.
Curve func(float64) float64
// OnEnd is called when the animation completes.
OnEnd func()
// Opacity is the target opacity (0.0 to 1.0).
Opacity float64
// ChildWidget is the widget to which opacity is applied.
ChildWidget core.Widget
}
func (AnimatedOpacity) CreateElement
func (a AnimatedOpacity) CreateElement() core.Element
func (AnimatedOpacity) CreateState
func (a AnimatedOpacity) CreateState() core.State
func (AnimatedOpacity) Key
func (a AnimatedOpacity) Key() any
type Axis
Axis represents the layout direction.
type Axis int
const (
AxisHorizontal Axis = iota
AxisVertical
)
type BackdropFilter
BackdropFilter applies a blur effect to content behind this widget. The blur is applied within the widget's bounds and affects any content drawn before this widget in the compositing order.
type BackdropFilter struct {
ChildWidget core.Widget
SigmaX float64
SigmaY float64
}
func NewBackdropFilter
func NewBackdropFilter(sigma float64, child core.Widget) BackdropFilter
NewBackdropFilter creates a BackdropFilter with uniform blur in both directions.
func (BackdropFilter) Child
func (b BackdropFilter) Child() core.Widget
func (BackdropFilter) CreateElement
func (b BackdropFilter) CreateElement() core.Element
func (BackdropFilter) CreateRenderObject
func (b BackdropFilter) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (BackdropFilter) Key
func (b BackdropFilter) Key() any
func (BackdropFilter) UpdateRenderObject
func (b BackdropFilter) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type BouncingScrollPhysics
BouncingScrollPhysics adds resistance near edges.
type BouncingScrollPhysics struct{}
func (BouncingScrollPhysics) ApplyBoundaryConditions
func (BouncingScrollPhysics) ApplyBoundaryConditions(position *ScrollPosition, value float64) float64
ApplyBoundaryConditions still clamps to avoid runaway offsets.
func (BouncingScrollPhysics) ApplyPhysicsToUserOffset
func (BouncingScrollPhysics) ApplyPhysicsToUserOffset(position *ScrollPosition, offset float64) float64
ApplyPhysicsToUserOffset reduces delta when overscrolling.
type Button
Button is a tappable button widget with customizable appearance.
type Button struct {
// Label is the text displayed on the button.
Label string
// OnTap is called when the button is tapped.
OnTap func()
// Disabled disables the button when true.
Disabled bool
// Color is the background color. Defaults to primary if zero.
Color rendering.Color
// Gradient is the optional background gradient.
Gradient *rendering.Gradient
// TextColor is the label color. Defaults to onPrimary if zero.
TextColor rendering.Color
// FontSize is the label font size. Defaults to 16 if zero.
FontSize float64
// Padding is the button padding. Defaults to symmetric(24, 14) if zero.
Padding layout.EdgeInsets
// BorderRadius is the corner radius. Defaults to 8 if zero.
BorderRadius float64
// Haptic enables haptic feedback on tap. Defaults to true.
Haptic bool
}
Example:
This example shows how to create a basic button with a tap handler.
package main
import (
"fmt"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
button := widgets.NewButton("Click Me", func() {
fmt.Println("Button tapped!")
})
_ = button
}
Example (With Styles):
This example shows how to customize a button's appearance.
package main
import (
"fmt"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
button := widgets.NewButton("Submit", func() {
fmt.Println("Submitted!")
}).
WithColor(rendering.RGB(33, 150, 243), rendering.ColorWhite).
WithFontSize(18).
WithPadding(layout.EdgeInsetsSymmetric(32, 16)).
WithHaptic(true)
_ = button
}
func NewButton
func NewButton(label string, onTap func()) Button
NewButton creates a button with the given label and tap handler. Uses sensible defaults for styling.
func (Button) Build
func (b Button) Build(ctx core.BuildContext) core.Widget
func (Button) CreateElement
func (b Button) CreateElement() core.Element
func (Button) Key
func (b Button) Key() any
func (Button) WithBorderRadius
func (b Button) WithBorderRadius(radius float64) Button
WithBorderRadius sets the corner radius.
func (Button) WithColor
func (b Button) WithColor(bg, text rendering.Color) Button
WithColor sets the background and text colors.
func (Button) WithDisabled
func (b Button) WithDisabled(disabled bool) Button
WithDisabled sets the disabled state.
func (Button) WithFontSize
func (b Button) WithFontSize(size float64) Button
WithFontSize sets the label font size.
func (Button) WithGradient
func (b Button) WithGradient(gradient *rendering.Gradient) Button
WithGradient sets the background gradient.
func (Button) WithHaptic
func (b Button) WithHaptic(enabled bool) Button
WithHaptic enables or disables haptic feedback.
func (Button) WithPadding
func (b Button) WithPadding(padding layout.EdgeInsets) Button
WithPadding sets the button padding.
type Center
Center centers its child within the available space.
type Center struct {
ChildWidget core.Widget
}
func Centered
func Centered(child core.Widget) Center
Centered wraps a child in a Center widget.
func (Center) Child
func (c Center) Child() core.Widget
func (Center) CreateElement
func (c Center) CreateElement() core.Element
func (Center) CreateRenderObject
func (c Center) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Center) Key
func (c Center) Key() any
func (Center) UpdateRenderObject
func (c Center) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Checkbox
Checkbox displays a toggleable check control.
type Checkbox struct {
// Value indicates whether the checkbox is checked.
Value bool
// OnChanged is called when the checkbox is toggled.
OnChanged func(bool)
// Disabled disables interaction when true.
Disabled bool
// Size controls the checkbox square size.
Size float64
// BorderRadius controls the checkbox corner radius.
BorderRadius float64
// ActiveColor is the fill color when checked.
ActiveColor rendering.Color
// CheckColor is the checkmark color.
CheckColor rendering.Color
// BorderColor is the outline color when unchecked.
BorderColor rendering.Color
// BackgroundColor is the fill color when unchecked.
BackgroundColor rendering.Color
}
Example:
This example shows how to create a checkbox form control.
package main
import (
"fmt"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
var isChecked bool
checkbox := widgets.Checkbox{
Value: isChecked,
OnChanged: func(value bool) {
isChecked = value
fmt.Printf("Checkbox is now: %v\n", isChecked)
},
Size: 24,
BorderRadius: 4,
}
_ = checkbox
}
func (Checkbox) Build
func (c Checkbox) Build(ctx core.BuildContext) core.Widget
func (Checkbox) CreateElement
func (c Checkbox) CreateElement() core.Element
func (Checkbox) Key
func (c Checkbox) Key() any
type ClampingScrollPhysics
ClampingScrollPhysics clamps at edges (Android default).
type ClampingScrollPhysics struct{}
func (ClampingScrollPhysics) ApplyBoundaryConditions
func (ClampingScrollPhysics) ApplyBoundaryConditions(position *ScrollPosition, value float64) float64
ApplyBoundaryConditions clamps at the min/max extents.
func (ClampingScrollPhysics) ApplyPhysicsToUserOffset
func (ClampingScrollPhysics) ApplyPhysicsToUserOffset(_ *ScrollPosition, offset float64) float64
ApplyPhysicsToUserOffset returns the raw delta for clamping physics.
type ClipRRect
ClipRRect clips its child using rounded corners.
type ClipRRect struct {
ChildWidget core.Widget
Radius float64
}
func (ClipRRect) Child
func (c ClipRRect) Child() core.Widget
func (ClipRRect) CreateElement
func (c ClipRRect) CreateElement() core.Element
func (ClipRRect) CreateRenderObject
func (c ClipRRect) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (ClipRRect) Key
func (c ClipRRect) Key() any
func (ClipRRect) UpdateRenderObject
func (c ClipRRect) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Column
Column lays out children vertically.
type Column struct {
ChildrenWidgets []core.Widget
MainAxisAlignment MainAxisAlignment
CrossAxisAlignment CrossAxisAlignment
MainAxisSize MainAxisSize
}
Example:
This example shows how to create a vertical layout with Column.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
column := widgets.Column{
ChildrenWidgets: []core.Widget{
widgets.Text{Content: "First"},
widgets.Text{Content: "Second"},
widgets.Text{Content: "Third"},
},
MainAxisAlignment: widgets.MainAxisAlignmentStart,
CrossAxisAlignment: widgets.CrossAxisAlignmentStretch,
}
_ = column
}
func ColumnOf
func ColumnOf(alignment MainAxisAlignment, crossAlignment CrossAxisAlignment, size MainAxisSize, children ...core.Widget) Column
ColumnOf creates a vertical layout with the specified alignments and sizing behavior.
Example:
This example shows the helper function for creating columns.
package main
import (
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
column := widgets.ColumnOf(
widgets.MainAxisAlignmentCenter,
widgets.CrossAxisAlignmentCenter,
widgets.MainAxisSizeMin,
widgets.Text{Content: "Hello"},
widgets.VSpace(16),
widgets.Text{Content: "World"},
)
_ = column
}
func (Column) Children
func (c Column) Children() []core.Widget
func (Column) CreateElement
func (c Column) CreateElement() core.Element
func (Column) CreateRenderObject
func (c Column) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Column) Key
func (c Column) Key() any
func (Column) UpdateRenderObject
func (c Column) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Container
Container is a convenience widget for common decorations.
type Container struct {
ChildWidget core.Widget
Padding layout.EdgeInsets
Width float64
Height float64
Color rendering.Color
Gradient *rendering.Gradient
Alignment layout.Alignment
Shadow *rendering.BoxShadow
}
Example:
This example shows how to create a styled container.
package main
import (
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
container := widgets.Container{
Padding: layout.EdgeInsetsAll(16),
Color: rendering.RGB(245, 245, 245),
Width: 200,
Height: 100,
ChildWidget: widgets.Text{
Content: "Centered content",
},
Alignment: layout.AlignmentCenter,
}
_ = container
}
func Box
func Box(child core.Widget, padding layout.EdgeInsets, color rendering.Color, alignment layout.Alignment) Container
Box creates a container with padding, background color, and alignment.
func (Container) Child
func (c Container) Child() core.Widget
func (Container) CreateElement
func (c Container) CreateElement() core.Element
func (Container) CreateRenderObject
func (c Container) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Container) Key
func (c Container) Key() any
func (Container) UpdateRenderObject
func (c Container) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type ContainerBuilder
ContainerBuilder provides a fluent API for building Container widgets.
type ContainerBuilder struct {
// contains filtered or unexported fields
}
func NewContainer
func NewContainer(child core.Widget) *ContainerBuilder
NewContainer creates a new ContainerBuilder with the given child.
func (*ContainerBuilder) Build
func (b *ContainerBuilder) Build() Container
Build returns the configured Container.
func (*ContainerBuilder) WithAlignment
func (b *ContainerBuilder) WithAlignment(alignment layout.Alignment) *ContainerBuilder
WithAlignment sets the child alignment.
func (*ContainerBuilder) WithColor
func (b *ContainerBuilder) WithColor(color rendering.Color) *ContainerBuilder
WithColor sets the background color.
func (*ContainerBuilder) WithGradient
func (b *ContainerBuilder) WithGradient(gradient *rendering.Gradient) *ContainerBuilder
WithGradient sets the background gradient.
func (*ContainerBuilder) WithPadding
func (b *ContainerBuilder) WithPadding(padding layout.EdgeInsets) *ContainerBuilder
WithPadding sets the padding.
func (*ContainerBuilder) WithPaddingAll
func (b *ContainerBuilder) WithPaddingAll(value float64) *ContainerBuilder
WithPaddingAll sets uniform padding on all sides.
func (*ContainerBuilder) WithSize
func (b *ContainerBuilder) WithSize(width, height float64) *ContainerBuilder
WithSize sets the width and height.
type CrossAxisAlignment
CrossAxisAlignment controls placement along the cross axis.
type CrossAxisAlignment int
const (
CrossAxisAlignmentStart CrossAxisAlignment = iota
CrossAxisAlignmentEnd
CrossAxisAlignmentCenter
CrossAxisAlignmentStretch
)
type DecoratedBox
DecoratedBox paints a background and border behind its child.
type DecoratedBox struct {
ChildWidget core.Widget
Color rendering.Color
Gradient *rendering.Gradient
BorderColor rendering.Color
BorderWidth float64
BorderRadius float64
Shadow *rendering.BoxShadow
}
func (DecoratedBox) Child
func (d DecoratedBox) Child() core.Widget
func (DecoratedBox) CreateElement
func (d DecoratedBox) CreateElement() core.Element
func (DecoratedBox) CreateRenderObject
func (d DecoratedBox) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (DecoratedBox) Key
func (d DecoratedBox) Key() any
func (DecoratedBox) UpdateRenderObject
func (d DecoratedBox) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type DeviceScale
DeviceScale provides the current device pixel scale factor to descendants.
type DeviceScale struct {
Scale float64
ChildWidget core.Widget
}
func (DeviceScale) Child
func (d DeviceScale) Child() core.Widget
func (DeviceScale) CreateElement
func (d DeviceScale) CreateElement() core.Element
func (DeviceScale) Key
func (d DeviceScale) Key() any
func (DeviceScale) UpdateShouldNotify
func (d DeviceScale) UpdateShouldNotify(oldWidget core.InheritedWidget) bool
func (DeviceScale) UpdateShouldNotifyDependent
func (d DeviceScale) UpdateShouldNotifyDependent(oldWidget core.InheritedWidget, aspects map[any]struct{}) bool
UpdateShouldNotifyDependent returns true for any aspects since DeviceScale doesn't support granular aspect tracking yet.
type DragEndDetails
DragEndDetails describes the end of a drag.
type DragEndDetails = gestures.DragEndDetails
type DragStartDetails
DragStartDetails describes the start of a drag.
type DragStartDetails = gestures.DragStartDetails
type DragUpdateDetails
DragUpdateDetails describes a drag update.
type DragUpdateDetails = gestures.DragUpdateDetails
type Dropdown
Dropdown displays a menu of selectable items.
type Dropdown[T any] struct {
// Value is the current selected value.
Value T
// Items are the available selections.
Items []DropdownItem[T]
// OnChanged is called when a new value is selected.
OnChanged func(T)
// Hint is shown when no selection matches.
Hint string
// Disabled disables the dropdown when true.
Disabled bool
// Width sets a fixed width (0 uses layout constraints).
Width float64
// Height sets a fixed height (0 uses default).
Height float64
// BorderRadius sets the corner radius.
BorderRadius float64
// BackgroundColor sets the trigger background.
BackgroundColor rendering.Color
// BorderColor sets the trigger border color.
BorderColor rendering.Color
// MenuBackgroundColor sets the menu background.
MenuBackgroundColor rendering.Color
// MenuBorderColor sets the menu border color.
MenuBorderColor rendering.Color
// TextStyle sets the text style for labels.
TextStyle rendering.TextStyle
// ItemPadding sets padding for each menu item.
ItemPadding layout.EdgeInsets
}
func (Dropdown[T]) CreateElement
func (d Dropdown[T]) CreateElement() core.Element
func (Dropdown[T]) CreateState
func (d Dropdown[T]) CreateState() core.State
func (Dropdown[T]) Key
func (d Dropdown[T]) Key() any
type DropdownItem
DropdownItem represents a selectable value for a dropdown.
type DropdownItem[T any] struct {
// Value is the item value.
Value T
// Label is the text shown for the item.
Label string
// Child overrides the label when provided.
Child core.Widget
// Disabled disables selection when true.
Disabled bool
}
type ErrorBoundary
ErrorBoundary catches build errors from descendant widgets and displays a fallback widget instead of crashing the app. This provides scoped error handling for subtrees of the widget tree.
Example:
ErrorBoundary{
OnError: func(err *errors.BuildError) {
log.Printf("Widget error: %v", err)
},
FallbackBuilder: func(err *errors.BuildError) core.Widget {
return widgets.Text{Content: "Failed to load"}
},
ChildWidget: RiskyContent{},
}
type ErrorBoundary struct {
// ChildWidget is the widget tree to wrap with error handling.
ChildWidget core.Widget
// FallbackBuilder creates a widget to show when an error is caught.
// If nil, uses the default ErrorWidget.
FallbackBuilder core.ErrorWidgetBuilder
// OnError is called when an error is caught. Use for logging/analytics.
OnError func(*errors.BuildError)
// WidgetKey is an optional key for the widget. Changing the key forces
// the ErrorBoundary to recreate its state, clearing any captured error.
WidgetKey any
}
func (ErrorBoundary) CreateElement
func (e ErrorBoundary) CreateElement() core.Element
func (ErrorBoundary) CreateState
func (e ErrorBoundary) CreateState() core.State
func (ErrorBoundary) Key
func (e ErrorBoundary) Key() any
type ErrorWidget
ErrorWidget displays error information when a widget build fails. It shows a red background with error details in debug mode, or a minimal error indicator in release mode.
type ErrorWidget struct {
// Error is the build error that occurred.
Error *errors.BuildError
// Verbose overrides DebugMode for this widget instance.
// If not explicitly set, defaults to core.DebugMode.
Verbose *bool
}
func (ErrorWidget) Build
func (e ErrorWidget) Build(ctx core.BuildContext) core.Widget
func (ErrorWidget) CreateElement
func (e ErrorWidget) CreateElement() core.Element
func (ErrorWidget) Key
func (e ErrorWidget) Key() any
type ExcludeSemantics
ExcludeSemantics is a widget that excludes its child from the semantics tree. Use this to hide decorative elements from accessibility services.
type ExcludeSemantics struct {
// ChildWidget is the child widget to exclude.
ChildWidget core.Widget
// Excluding controls whether to exclude the child from semantics.
// Set to true to exclude, false to include. Defaults to false (Go zero value).
// For the common case of excluding, use: ExcludeSemantics{Excluding: true, ChildWidget: child}
Excluding bool
}
func Decorative
func Decorative(child core.Widget) ExcludeSemantics
Decorative marks a widget as decorative, hiding it from screen readers. Use this for purely visual elements that don't convey information.
Example:
Decorative(dividerLine)
func NewExcludeSemantics
func NewExcludeSemantics(child core.Widget) ExcludeSemantics
NewExcludeSemantics creates an ExcludeSemantics widget that excludes the child from accessibility.
func (ExcludeSemantics) Child
func (e ExcludeSemantics) Child() core.Widget
Child returns the child widget.
func (ExcludeSemantics) CreateElement
func (e ExcludeSemantics) CreateElement() core.Element
func (ExcludeSemantics) CreateRenderObject
func (e ExcludeSemantics) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (ExcludeSemantics) Key
func (e ExcludeSemantics) Key() any
func (ExcludeSemantics) UpdateRenderObject
func (e ExcludeSemantics) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Expanded
Expanded expands to fill all available space in the parent constraints. When placed inside Row or Column, it consumes remaining space based on Flex.
type Expanded struct {
ChildWidget core.Widget
Flex int
}
func (Expanded) Child
func (e Expanded) Child() core.Widget
Child returns the child widget.
func (Expanded) CreateElement
func (e Expanded) CreateElement() core.Element
CreateElement returns a RenderObjectElement for this Expanded.
func (Expanded) CreateRenderObject
func (e Expanded) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
CreateRenderObject creates the renderExpanded.
func (Expanded) Key
func (e Expanded) Key() any
Key returns nil (no key).
func (Expanded) UpdateRenderObject
func (e Expanded) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
UpdateRenderObject updates the renderExpanded.
type FlexFactor
FlexFactor reports the flex value for a render box.
type FlexFactor interface {
FlexFactor() int
}
type Form
Form groups form fields and provides validation helpers.
type Form struct {
// ChildWidget is the form content.
ChildWidget core.Widget
// Autovalidate runs validators when fields change.
Autovalidate bool
// OnChanged is called when any field changes.
OnChanged func()
}
func (Form) CreateElement
func (f Form) CreateElement() core.Element
func (Form) CreateState
func (f Form) CreateState() core.State
func (Form) Key
func (f Form) Key() any
type FormField
FormField builds a field that integrates with a Form.
type FormField[T any] struct {
// InitialValue is the field's starting value.
InitialValue T
// Builder renders the field using its state.
Builder func(*FormFieldState[T]) core.Widget
// OnSaved is called when the form is saved.
OnSaved func(T)
// Validator returns an error message or empty string.
Validator func(T) string
// OnChanged is called when the field value changes.
OnChanged func(T)
// Disabled controls whether the field participates in validation.
Disabled bool
// Autovalidate enables validation when the value changes.
Autovalidate bool
}
func (FormField[T]) CreateElement
func (f FormField[T]) CreateElement() core.Element
func (FormField[T]) CreateState
func (f FormField[T]) CreateState() core.State
func (FormField[T]) Key
func (f FormField[T]) Key() any
type FormFieldState
FormFieldState stores mutable state for a FormField.
type FormFieldState[T any] struct {
// contains filtered or unexported fields
}
func (*FormFieldState[T]) Build
func (s *FormFieldState[T]) Build(ctx core.BuildContext) core.Widget
Build renders the field by calling Builder.
func (*FormFieldState[T]) DidChange
func (s *FormFieldState[T]) DidChange(value T)
DidChange updates the value and triggers validation/notifications.
func (*FormFieldState[T]) DidChangeDependencies
func (s *FormFieldState[T]) DidChangeDependencies()
DidChangeDependencies is a no-op for FormFieldState.
func (*FormFieldState[T]) DidUpdateWidget
func (s *FormFieldState[T]) DidUpdateWidget(oldWidget core.StatefulWidget)
DidUpdateWidget updates value if the initial value changed before interaction.
func (*FormFieldState[T]) Dispose
func (s *FormFieldState[T]) Dispose()
Dispose unregisters the field from the form.
func (*FormFieldState[T]) ErrorText
func (s *FormFieldState[T]) ErrorText() string
ErrorText returns the current error message.
func (*FormFieldState[T]) HasError
func (s *FormFieldState[T]) HasError() bool
HasError reports whether the field has an error.
func (*FormFieldState[T]) InitState
func (s *FormFieldState[T]) InitState()
InitState initializes the field value from the widget.
func (*FormFieldState[T]) Reset
func (s *FormFieldState[T]) Reset()
Reset returns the field to its initial value.
func (*FormFieldState[T]) Save
func (s *FormFieldState[T]) Save()
Save triggers the OnSaved callback.
func (*FormFieldState[T]) SetElement
func (s *FormFieldState[T]) SetElement(element *core.StatefulElement)
SetElement stores the element for rebuilds.
func (*FormFieldState[T]) SetState
func (s *FormFieldState[T]) SetState(fn func())
SetState executes fn and schedules rebuild.
func (*FormFieldState[T]) Validate
func (s *FormFieldState[T]) Validate() bool
Validate runs the field validator.
func (*FormFieldState[T]) Value
func (s *FormFieldState[T]) Value() T
Value returns the current value.
type FormState
FormState manages the state of a Form widget.
type FormState struct {
// contains filtered or unexported fields
}
func FormOf
func FormOf(ctx core.BuildContext) *FormState
FormOf returns the closest FormState in the widget tree.
func (*FormState) Build
func (s *FormState) Build(ctx core.BuildContext) core.Widget
Build renders the form scope.
func (*FormState) DidChangeDependencies
func (s *FormState) DidChangeDependencies()
DidChangeDependencies is a no-op for FormState.
func (*FormState) DidUpdateWidget
func (s *FormState) DidUpdateWidget(oldWidget core.StatefulWidget)
DidUpdateWidget is a no-op for FormState.
func (*FormState) Dispose
func (s *FormState) Dispose()
Dispose clears registrations.
func (*FormState) InitState
func (s *FormState) InitState()
InitState initializes the form state.
func (*FormState) NotifyChanged
func (s *FormState) NotifyChanged()
NotifyChanged informs listeners that a field changed.
func (*FormState) RegisterField
func (s *FormState) RegisterField(field formFieldState)
RegisterField registers a field with this form.
func (*FormState) Reset
func (s *FormState) Reset()
Reset resets all fields to their initial values.
func (*FormState) Save
func (s *FormState) Save()
Save calls OnSaved for all fields.
func (*FormState) SetElement
func (s *FormState) SetElement(element *core.StatefulElement)
SetElement stores the element for rebuilds.
func (*FormState) SetState
func (s *FormState) SetState(fn func())
SetState executes fn and schedules rebuild.
func (*FormState) UnregisterField
func (s *FormState) UnregisterField(field formFieldState)
UnregisterField unregisters a field from this form.
func (*FormState) Validate
func (s *FormState) Validate() bool
Validate runs validators on all fields.
type GestureDetector
GestureDetector wraps a child with tap handling.
type GestureDetector struct {
ChildWidget core.Widget
OnTap func()
OnPanStart func(DragStartDetails)
OnPanUpdate func(DragUpdateDetails)
OnPanEnd func(DragEndDetails)
OnPanCancel func()
OnHorizontalDragStart func(DragStartDetails)
OnHorizontalDragUpdate func(DragUpdateDetails)
OnHorizontalDragEnd func(DragEndDetails)
OnHorizontalDragCancel func()
OnVerticalDragStart func(DragStartDetails)
OnVerticalDragUpdate func(DragUpdateDetails)
OnVerticalDragEnd func(DragEndDetails)
OnVerticalDragCancel func()
}
Example:
This example shows how to handle tap gestures.
package main
import (
"fmt"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
detector := widgets.GestureDetector{
OnTap: func() {
fmt.Println("Tapped!")
},
ChildWidget: widgets.Container{
Color: rendering.RGB(200, 200, 200),
Padding: layout.EdgeInsetsAll(20),
ChildWidget: widgets.Text{
Content: "Tap me",
},
},
}
_ = detector
}
func Drag
func Drag(onUpdate func(DragUpdateDetails), child core.Widget) GestureDetector
Drag wraps a child with pan (omnidirectional) drag handlers.
func HorizontalDrag
func HorizontalDrag(onUpdate func(DragUpdateDetails), child core.Widget) GestureDetector
HorizontalDrag wraps a child with horizontal-only drag handlers.
func Tap
func Tap(onTap func(), child core.Widget) GestureDetector
Tap wraps a child with a tap handler.
func VerticalDrag
func VerticalDrag(onUpdate func(DragUpdateDetails), child core.Widget) GestureDetector
VerticalDrag wraps a child with vertical-only drag handlers.
func (GestureDetector) Child
func (g GestureDetector) Child() core.Widget
func (GestureDetector) CreateElement
func (g GestureDetector) CreateElement() core.Element
func (GestureDetector) CreateRenderObject
func (g GestureDetector) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (GestureDetector) Key
func (g GestureDetector) Key() any
func (GestureDetector) UpdateRenderObject
func (g GestureDetector) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Icon
Icon renders a single glyph with icon-friendly defaults.
type Icon struct {
// Glyph is the text glyph to render.
Glyph string
// Size is the font size for the icon. Uses theme defaults if zero.
Size float64
// Color is the icon color. Uses theme defaults if zero.
Color rendering.Color
// Weight sets the font weight if non-zero.
Weight rendering.FontWeight
}
func (Icon) Build
func (i Icon) Build(ctx core.BuildContext) core.Widget
func (Icon) CreateElement
func (i Icon) CreateElement() core.Element
func (Icon) Key
func (i Icon) Key() any
type Image
Image renders a bitmap image onto the canvas.
type Image struct {
// Source is the image to render.
Source image.Image
// Width overrides the image width if non-zero.
Width float64
// Height overrides the image height if non-zero.
Height float64
// Fit controls how the image is scaled within its bounds.
Fit ImageFit
// Alignment positions the image within its bounds.
Alignment layout.Alignment
// SemanticLabel provides an accessibility description of the image.
SemanticLabel string
// ExcludeFromSemantics excludes the image from the semantics tree when true.
// Use this for decorative images that don't convey meaningful content.
ExcludeFromSemantics bool
}
func (Image) CreateElement
func (i Image) CreateElement() core.Element
func (Image) CreateRenderObject
func (i Image) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Image) Key
func (i Image) Key() any
func (Image) UpdateRenderObject
func (i Image) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type ImageFit
ImageFit controls how an image is scaled within its box.
type ImageFit int
const (
// ImageFitFill stretches the image to fill its bounds.
ImageFitFill ImageFit = iota
// ImageFitContain scales the image to fit within its bounds.
ImageFitContain
// ImageFitCover scales the image to cover its bounds.
ImageFitCover
// ImageFitNone leaves the image at its intrinsic size.
ImageFitNone
// ImageFitScaleDown fits the image if needed, otherwise keeps intrinsic size.
ImageFitScaleDown
)
type IndexedStack
IndexedStack lays out all children but only paints the active index.
type IndexedStack struct {
ChildrenWidgets []core.Widget
Alignment layout.Alignment
Fit StackFit
Index int
}
func (IndexedStack) Children
func (s IndexedStack) Children() []core.Widget
func (IndexedStack) CreateElement
func (s IndexedStack) CreateElement() core.Element
func (IndexedStack) CreateRenderObject
func (s IndexedStack) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (IndexedStack) Key
func (s IndexedStack) Key() any
func (IndexedStack) UpdateRenderObject
func (s IndexedStack) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type ListView
ListView displays a scrollable list of widgets.
type ListView struct {
// ChildrenWidgets are the widgets to display in the list.
ChildrenWidgets []core.Widget
// ScrollDirection is the axis along which the list scrolls. Defaults to vertical.
ScrollDirection *Axis
// Controller manages scroll position and provides scroll notifications.
Controller *ScrollController
// Physics determines how the scroll view responds to user input.
Physics ScrollPhysics
// Padding is applied around the list content.
Padding layout.EdgeInsets
// MainAxisAlignment controls how children are positioned along the scroll axis.
MainAxisAlignment MainAxisAlignment
// MainAxisSize determines how much space the list takes along the scroll axis.
MainAxisSize MainAxisSize
}
func (ListView) Build
func (l ListView) Build(ctx core.BuildContext) core.Widget
func (ListView) CreateElement
func (l ListView) CreateElement() core.Element
func (ListView) Key
func (l ListView) Key() any
type ListViewBuilder
ListViewBuilder builds children on demand for the list.
type ListViewBuilder struct {
// ItemCount is the total number of items in the list.
ItemCount int
// ItemBuilder creates widgets for visible items. Called with the build context and item index.
ItemBuilder func(ctx core.BuildContext, index int) core.Widget
// ItemExtent is the fixed extent of each item along the scroll axis. Required for virtualization.
ItemExtent float64
// CacheExtent is the number of pixels to render beyond the visible area.
CacheExtent float64
// ScrollDirection is the axis along which the list scrolls. Defaults to vertical.
ScrollDirection *Axis
// Controller manages scroll position and provides scroll notifications.
Controller *ScrollController
// Physics determines how the scroll view responds to user input.
Physics ScrollPhysics
// Padding is applied around the list content.
Padding layout.EdgeInsets
// MainAxisAlignment controls how children are positioned along the scroll axis.
MainAxisAlignment MainAxisAlignment
// MainAxisSize determines how much space the list takes along the scroll axis.
MainAxisSize MainAxisSize
}
Example:
This example shows how to create a dynamic list with ListViewBuilder.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
items := []string{"Apple", "Banana", "Cherry", "Date", "Elderberry"}
listView := widgets.ListViewBuilder{
ItemCount: len(items),
ItemExtent: 48,
ItemBuilder: func(ctx core.BuildContext, index int) core.Widget {
return widgets.Container{
Padding: layout.EdgeInsetsSymmetric(16, 12),
ChildWidget: widgets.Text{Content: items[index]},
}
},
Padding: layout.EdgeInsetsAll(8),
}
_ = listView
}
func (ListViewBuilder) CreateElement
func (l ListViewBuilder) CreateElement() core.Element
func (ListViewBuilder) CreateState
func (l ListViewBuilder) CreateState() core.State
func (ListViewBuilder) Key
func (l ListViewBuilder) Key() any
type MainAxisAlignment
MainAxisAlignment controls spacing along the main axis.
type MainAxisAlignment int
const (
MainAxisAlignmentStart MainAxisAlignment = iota
MainAxisAlignmentEnd
MainAxisAlignmentCenter
MainAxisAlignmentSpaceBetween
MainAxisAlignmentSpaceAround
MainAxisAlignmentSpaceEvenly
)
type MainAxisSize
MainAxisSize controls the size along the main axis.
type MainAxisSize int
const (
MainAxisSizeMin MainAxisSize = iota
MainAxisSizeMax
)
type MergeSemantics
MergeSemantics is a widget that merges the semantics of its descendants.
type MergeSemantics struct {
// ChildWidget is the child widget whose semantics will be merged.
ChildWidget core.Widget
}
func (MergeSemantics) Child
func (m MergeSemantics) Child() core.Widget
Child returns the child widget.
func (MergeSemantics) CreateElement
func (m MergeSemantics) CreateElement() core.Element
func (MergeSemantics) CreateRenderObject
func (m MergeSemantics) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (MergeSemantics) Key
func (m MergeSemantics) Key() any
func (MergeSemantics) UpdateRenderObject
func (m MergeSemantics) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type NativeTextField
NativeTextField embeds a native text input field.
type NativeTextField struct {
// Controller manages the text content and selection.
Controller *platform.TextEditingController
// Style for the text.
Style rendering.TextStyle
// Placeholder text shown when empty.
Placeholder string
// KeyboardType specifies the keyboard to show.
KeyboardType platform.KeyboardType
// InputAction specifies the keyboard action button.
InputAction platform.TextInputAction
// Obscure hides the text (for passwords).
Obscure bool
// Autocorrect enables auto-correction.
Autocorrect bool
// OnChanged is called when the text changes.
OnChanged func(string)
// OnSubmitted is called when the user submits (presses done/return).
OnSubmitted func(string)
// OnEditingComplete is called when editing is complete.
OnEditingComplete func()
// Disabled controls whether the field rejects input.
Disabled bool
// Width of the text field (0 = expand to fill).
Width float64
// Height of the text field.
Height float64
// Padding inside the text field.
Padding layout.EdgeInsets
// BackgroundColor of the text field.
BackgroundColor rendering.Color
// BorderColor of the text field.
BorderColor rendering.Color
// FocusColor of the text field outline.
FocusColor rendering.Color
// BorderRadius for rounded corners.
BorderRadius float64
// PlaceholderColor is the color for placeholder text.
PlaceholderColor rendering.Color
}
func (NativeTextField) CreateElement
func (n NativeTextField) CreateElement() core.Element
CreateElement creates the element for the stateful widget.
func (NativeTextField) CreateState
func (n NativeTextField) CreateState() core.State
CreateState creates the state for this widget.
func (NativeTextField) Key
func (n NativeTextField) Key() any
Key returns the widget key.
type NativeWebView
NativeWebView embeds a native web browser view.
type NativeWebView struct {
// InitialURL is the URL to load when the view is created.
InitialURL string
// Controller provides programmatic control over the web view.
Controller *WebViewController
// OnPageStarted is called when a page starts loading.
OnPageStarted func(url string)
// OnPageFinished is called when a page finishes loading.
OnPageFinished func(url string)
// OnError is called when a loading error occurs.
OnError func(err error)
// Width of the web view (0 = expand to fill).
Width float64
// Height of the web view.
Height float64
}
func (NativeWebView) CreateElement
func (n NativeWebView) CreateElement() core.Element
CreateElement creates the element for the stateful widget.
func (NativeWebView) CreateState
func (n NativeWebView) CreateState() core.State
CreateState creates the state for this widget.
func (NativeWebView) Key
func (n NativeWebView) Key() any
Key returns the widget key.
type Opacity
Opacity applies transparency to its child widget.
The Opacity value should be between 0.0 (fully transparent) and 1.0 (fully opaque). When Opacity is 0.0, the child is not painted at all. When Opacity is 1.0, the child is painted normally without any performance overhead. Intermediate values use SaveLayerAlpha for proper alpha compositing.
Note: The layer bounds are based on this widget's size. Children that paint outside their bounds (e.g., via transforms or overflow) may be clipped.
type Opacity struct {
// Opacity is the transparency value (0.0 to 1.0).
Opacity float64
// ChildWidget is the widget to which opacity is applied.
ChildWidget core.Widget
}
func (Opacity) Child
func (o Opacity) Child() core.Widget
func (Opacity) CreateElement
func (o Opacity) CreateElement() core.Element
func (Opacity) CreateRenderObject
func (o Opacity) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Opacity) Key
func (o Opacity) Key() any
func (Opacity) UpdateRenderObject
func (o Opacity) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Padding
Padding adds padding around a child.
type Padding struct {
Padding layout.EdgeInsets
ChildWidget core.Widget
}
func Padded
func Padded(padding layout.EdgeInsets, child core.Widget) Padding
Padded wraps a child with the specified padding.
func PaddingAll
func PaddingAll(value float64, child core.Widget) Padding
PaddingAll wraps a child with uniform padding on all sides.
func PaddingOnly
func PaddingOnly(left, top, right, bottom float64, child core.Widget) Padding
PaddingOnly wraps a child with specific padding on each side.
func PaddingSym
func PaddingSym(horizontal, vertical float64, child core.Widget) Padding
PaddingSym wraps a child with symmetric horizontal and vertical padding.
func (Padding) Child
func (p Padding) Child() core.Widget
func (Padding) CreateElement
func (p Padding) CreateElement() core.Element
func (Padding) CreateRenderObject
func (p Padding) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Padding) Key
func (p Padding) Key() any
func (Padding) UpdateRenderObject
func (p Padding) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Positioned
Positioned positions a child within a Stack using absolute positioning.
Coordinate System
The coordinate system has its origin at the top-left of the Stack:
- Left/Right: Distance from the left/right edge of the Stack
- Top/Bottom: Distance from the top/bottom edge of the Stack
Constraint Combinations
Use pointer fields (nil = unset) to control positioning. The Ptr helper creates float64 pointers conveniently:
// Pin to top-left corner with 8pt margins
Positioned{Left: Ptr(8), Top: Ptr(8), ChildWidget: icon}
// Pin to bottom-right corner
Positioned{Right: Ptr(16), Bottom: Ptr(16), ChildWidget: fab}
// Stretch horizontally with fixed vertical position
Positioned{Left: Ptr(0), Right: Ptr(0), Top: Ptr(100), ChildWidget: divider}
// Fixed size at specific position
Positioned{Left: Ptr(20), Top: Ptr(20), Width: Ptr(100), Height: Ptr(50), ChildWidget: box}
// Position only vertically - horizontal uses Stack.Alignment
Positioned{Top: Ptr(20), ChildWidget: header}
When both Left and Right are set (or Top and Bottom), the child stretches to fill that dimension. Width/Height override the stretching behavior.
For axes where no position is set (neither Left nor Right, or neither Top nor Bottom), the child uses the Stack's Alignment for that axis.
type Positioned struct {
// ChildWidget is the widget to position.
ChildWidget core.Widget
// Left is the distance from the left edge of the Stack (nil = unset).
Left *float64
// Top is the distance from the top edge of the Stack (nil = unset).
Top *float64
// Right is the distance from the right edge of the Stack (nil = unset).
Right *float64
// Bottom is the distance from the bottom edge of the Stack (nil = unset).
Bottom *float64
// Width overrides the child's width (nil = use child's intrinsic width).
Width *float64
// Height overrides the child's height (nil = use child's intrinsic height).
Height *float64
}
Example:
This example shows how to use Positioned for absolute positioning within a Stack.
package main
import (
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
// Pin to top-left corner with margins
topLeft := widgets.Positioned{
Left: widgets.Ptr(8),
Top: widgets.Ptr(8),
ChildWidget: widgets.Text{
Content: "Top Left",
},
}
// Pin to bottom-right corner
bottomRight := widgets.Positioned{
Right: widgets.Ptr(16),
Bottom: widgets.Ptr(16),
ChildWidget: widgets.Text{
Content: "Bottom Right",
},
}
// Fixed size at specific position
fixedBox := widgets.Positioned{
Left: widgets.Ptr(50),
Top: widgets.Ptr(50),
Width: widgets.Ptr(100),
Height: widgets.Ptr(60),
ChildWidget: widgets.Container{
Color: rendering.RGB(100, 149, 237),
},
}
_ = topLeft
_ = bottomRight
_ = fixedBox
}
Example (Partial Alignment):
This example shows partial positioning where unset axes use Stack.Alignment.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
// Position only vertically at top - horizontal position uses Stack.Alignment.
// With AlignmentCenter, this centers the header horizontally.
stack := widgets.Stack{
Alignment: layout.AlignmentCenter,
ChildrenWidgets: []core.Widget{
widgets.Container{Width: 300, Height: 200},
// Only Top is set, so X position comes from Stack.Alignment (centered)
widgets.Positioned{
Top: widgets.Ptr(16),
ChildWidget: widgets.Text{
Content: "Centered Header",
},
},
// Only Left is set, so Y position comes from Stack.Alignment (centered)
widgets.Positioned{
Left: widgets.Ptr(8),
ChildWidget: widgets.Text{
Content: "Left Sidebar",
},
},
},
}
_ = stack
}
Example (Stretch):
This example shows how Positioned can stretch children by setting opposite edges.
package main
import (
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
// Stretch horizontally (left + right set, no width)
horizontalStretch := widgets.Positioned{
Left: widgets.Ptr(16),
Right: widgets.Ptr(16),
Top: widgets.Ptr(100),
ChildWidget: widgets.Container{
Color: rendering.RGB(200, 200, 200),
Height: 2, // Divider line
},
}
// Stretch vertically (top + bottom set, no height)
verticalStretch := widgets.Positioned{
Top: widgets.Ptr(50),
Bottom: widgets.Ptr(50),
Left: widgets.Ptr(0),
ChildWidget: widgets.Container{
Color: rendering.RGB(100, 100, 100),
Width: 4, // Vertical bar
},
}
// Stretch both ways (all four edges set)
fillWithMargins := widgets.Positioned{
Left: widgets.Ptr(20),
Top: widgets.Ptr(20),
Right: widgets.Ptr(20),
Bottom: widgets.Ptr(20),
ChildWidget: widgets.Container{
Color: rendering.RGBA(0, 0, 0, 128), // Semi-transparent overlay
},
}
_ = horizontalStretch
_ = verticalStretch
_ = fillWithMargins
}
func (Positioned) Child
func (p Positioned) Child() core.Widget
Child returns the child widget.
func (Positioned) CreateElement
func (p Positioned) CreateElement() core.Element
CreateElement returns a RenderObjectElement for this Positioned.
func (Positioned) CreateRenderObject
func (p Positioned) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
CreateRenderObject creates the RenderPositioned.
func (Positioned) Key
func (p Positioned) Key() any
Key returns nil (no key).
func (Positioned) UpdateRenderObject
func (p Positioned) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
UpdateRenderObject updates the RenderPositioned.
type Radio
Radio renders a single radio button in a group.
type Radio[T any] struct {
// Value is the value for this radio.
Value T
// GroupValue is the current group selection.
GroupValue T
// OnChanged is called when this radio is selected.
OnChanged func(T)
// Disabled disables interaction when true.
Disabled bool
// Size controls the radio diameter.
Size float64
// ActiveColor is the selected fill color.
ActiveColor rendering.Color
// InactiveColor is the unselected border color.
InactiveColor rendering.Color
// BackgroundColor is the fill color when unselected.
BackgroundColor rendering.Color
}
func (Radio[T]) Build
func (r Radio[T]) Build(ctx core.BuildContext) core.Widget
func (Radio[T]) CreateElement
func (r Radio[T]) CreateElement() core.Element
func (Radio[T]) Key
func (r Radio[T]) Key() any
type RepaintBoundary
RepaintBoundary isolates its subtree into a separate paint layer. This allows the subtree to be cached and reused when it doesn't change, which can significantly improve performance for static content next to frequently animating content.
type RepaintBoundary struct {
ChildWidget core.Widget
}
func (RepaintBoundary) Child
func (r RepaintBoundary) Child() core.Widget
func (RepaintBoundary) CreateElement
func (r RepaintBoundary) CreateElement() core.Element
func (RepaintBoundary) CreateRenderObject
func (r RepaintBoundary) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (RepaintBoundary) Key
func (r RepaintBoundary) Key() any
func (RepaintBoundary) UpdateRenderObject
func (r RepaintBoundary) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Row
Row lays out children horizontally.
type Row struct {
ChildrenWidgets []core.Widget
MainAxisAlignment MainAxisAlignment
CrossAxisAlignment CrossAxisAlignment
MainAxisSize MainAxisSize
}
Example:
This example shows how to create a horizontal layout with Row.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
row := widgets.Row{
ChildrenWidgets: []core.Widget{
widgets.Text{Content: "Left"},
widgets.Text{Content: "Center"},
widgets.Text{Content: "Right"},
},
MainAxisAlignment: widgets.MainAxisAlignmentSpaceBetween,
CrossAxisAlignment: widgets.CrossAxisAlignmentCenter,
}
_ = row
}
func RowOf
func RowOf(alignment MainAxisAlignment, crossAlignment CrossAxisAlignment, size MainAxisSize, children ...core.Widget) Row
RowOf creates a horizontal layout with the specified alignments and sizing behavior.
func (Row) Children
func (r Row) Children() []core.Widget
func (Row) CreateElement
func (r Row) CreateElement() core.Element
func (Row) CreateRenderObject
func (r Row) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Row) Key
func (r Row) Key() any
func (Row) UpdateRenderObject
func (r Row) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type SVGIcon
SVGIcon renders an SVG icon from a file or loaded icon.
type SVGIcon struct {
// Icon is the pre-loaded SVG icon to render.
Icon *svg.Icon
// Size is the desired size (width and height) for the icon.
// If zero, uses the SVG's intrinsic viewBox size.
Size float64
// Color overrides the SVG's fill colors with a tint color.
// If zero (transparent), uses the SVG's original colors.
Color rendering.Color
// SemanticLabel provides an accessibility description of the icon.
SemanticLabel string
// ExcludeFromSemantics excludes the icon from the semantics tree when true.
ExcludeFromSemantics bool
}
func (SVGIcon) Child
func (s SVGIcon) Child() core.Widget
func (SVGIcon) CreateElement
func (s SVGIcon) CreateElement() core.Element
func (SVGIcon) CreateRenderObject
func (s SVGIcon) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (SVGIcon) Key
func (s SVGIcon) Key() any
func (SVGIcon) UpdateRenderObject
func (s SVGIcon) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type SafeArea
SafeArea is a convenience widget that applies safe area insets as padding.
type SafeArea struct {
Top bool
Bottom bool
Left bool
Right bool
ChildWidget core.Widget
}
func (SafeArea) Build
func (s SafeArea) Build(ctx core.BuildContext) core.Widget
func (SafeArea) CreateElement
func (s SafeArea) CreateElement() core.Element
func (SafeArea) Key
func (s SafeArea) Key() any
type SafeAreaAspect
SafeAreaAspect identifies which safe area inset a widget depends on.
type SafeAreaAspect int
const (
SafeAreaAspectTop SafeAreaAspect = iota
SafeAreaAspectBottom
SafeAreaAspectLeft
SafeAreaAspectRight
)
type SafeAreaData
SafeAreaData provides safe area insets to descendants via InheritedWidget.
type SafeAreaData struct {
Insets layout.EdgeInsets
ChildWidget core.Widget
}
func (SafeAreaData) Child
func (s SafeAreaData) Child() core.Widget
func (SafeAreaData) CreateElement
func (s SafeAreaData) CreateElement() core.Element
func (SafeAreaData) Key
func (s SafeAreaData) Key() any
func (SafeAreaData) UpdateShouldNotify
func (s SafeAreaData) UpdateShouldNotify(oldWidget core.InheritedWidget) bool
func (SafeAreaData) UpdateShouldNotifyDependent
func (s SafeAreaData) UpdateShouldNotifyDependent(oldWidget core.InheritedWidget, aspects map[any]struct{}) bool
type SafeAreaProvider
SafeAreaProvider is a StatefulWidget that subscribes to platform safe area changes and provides SafeAreaData to descendants. This scopes rebuilds to only the provider and widgets that depend on safe area data, instead of rebuilding the entire tree.
type SafeAreaProvider struct {
ChildWidget core.Widget
}
func (SafeAreaProvider) CreateElement
func (s SafeAreaProvider) CreateElement() core.Element
func (SafeAreaProvider) CreateState
func (s SafeAreaProvider) CreateState() core.State
func (SafeAreaProvider) Key
func (s SafeAreaProvider) Key() any
type ScrollController
ScrollController controls scroll position.
type ScrollController struct {
InitialScrollOffset float64
// contains filtered or unexported fields
}
func (*ScrollController) AddListener
func (c *ScrollController) AddListener(listener func()) func()
AddListener registers a callback for scroll changes.
func (*ScrollController) AnimateTo
func (c *ScrollController) AnimateTo(offset float64, _ time.Duration)
AnimateTo moves to a new offset immediately (placeholder for animations).
func (*ScrollController) JumpTo
func (c *ScrollController) JumpTo(offset float64)
JumpTo moves all attached positions to a new offset.
func (*ScrollController) Offset
func (c *ScrollController) Offset() float64
Offset returns the current scroll offset.
func (*ScrollController) ViewportExtent
func (c *ScrollController) ViewportExtent() float64
ViewportExtent returns the current viewport extent.
type ScrollPhysics
ScrollPhysics determines scroll behavior.
type ScrollPhysics interface {
ApplyPhysicsToUserOffset(position *ScrollPosition, offset float64) float64
ApplyBoundaryConditions(position *ScrollPosition, value float64) float64
}
type ScrollPosition
ScrollPosition stores the current scroll offset and extents.
type ScrollPosition struct {
// contains filtered or unexported fields
}
func NewScrollPosition
func NewScrollPosition(controller *ScrollController, physics ScrollPhysics, onUpdate func()) *ScrollPosition
NewScrollPosition creates a new scroll position.
func (*ScrollPosition) ApplyUserOffset
func (p *ScrollPosition) ApplyUserOffset(delta float64)
ApplyUserOffset applies a drag delta with physics.
func (*ScrollPosition) Offset
func (p *ScrollPosition) Offset() float64
Offset returns the current scroll offset.
func (*ScrollPosition) SetExtents
func (p *ScrollPosition) SetExtents(min, max float64)
SetExtents updates the min/max scroll extents.
func (*ScrollPosition) SetOffset
func (p *ScrollPosition) SetOffset(value float64)
SetOffset updates the scroll offset.
func (*ScrollPosition) StartBallistic
func (p *ScrollPosition) StartBallistic(velocity float64)
StartBallistic begins inertial scrolling with the provided velocity.
func (*ScrollPosition) StopBallistic
func (p *ScrollPosition) StopBallistic()
StopBallistic halts any ongoing inertial scroll.
type ScrollView
ScrollView provides scrollable content. Use the Padding field to add padding inside the scroll area. For safe area handling, use SafeAreaPadding(ctx) which can be combined with additional padding:
ScrollView{
Padding: widgets.SafeAreaPadding(ctx).Add(24),
ChildWidget: ...,
}
type ScrollView struct {
ChildWidget core.Widget
ScrollDirection Axis
Controller *ScrollController
Physics ScrollPhysics
Padding layout.EdgeInsets
}
Example:
This example shows how to create scrollable content.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
scrollView := widgets.ScrollView{
ChildWidget: widgets.Column{
ChildrenWidgets: []core.Widget{
widgets.SizedBox{Height: 1000, ChildWidget: widgets.Text{Content: "Tall content"}},
},
},
ScrollDirection: widgets.AxisVertical,
Physics: widgets.BouncingScrollPhysics{},
Padding: layout.EdgeInsetsAll(16),
}
_ = scrollView
}
func (ScrollView) Build
func (s ScrollView) Build(ctx core.BuildContext) core.Widget
func (ScrollView) CreateElement
func (s ScrollView) CreateElement() core.Element
func (ScrollView) Key
func (s ScrollView) Key() any
type Semantics
Semantics is a widget that annotates the widget tree with semantics information for accessibility services.
type Semantics struct {
// ChildWidget is the child widget to annotate.
ChildWidget core.Widget
// Label is the primary accessibility label for this node.
Label string
// Value is the current value (e.g., slider position, text content).
Value string
// Hint provides guidance on the action that will occur.
Hint string
// Tooltip provides additional information shown on hover/long press.
Tooltip string
// Role defines the semantic role of the node.
Role semantics.SemanticsRole
// Flags contains boolean state flags.
Flags semantics.SemanticsFlag
// Container indicates this node creates a semantic boundary.
Container bool
// MergeDescendants merges labels from descendant nodes into this node.
// Use this when a widget contains multiple text elements that should be
// announced as a single unit (e.g., a card with title and subtitle).
MergeDescendants bool
// ExplicitChildNodes indicates whether child nodes should be explicit.
ExplicitChildNodes bool
// CurrentValue for slider-type controls.
CurrentValue *float64
// MinValue for slider-type controls.
MinValue *float64
// MaxValue for slider-type controls.
MaxValue *float64
// HeadingLevel indicates heading level (1-6, 0 for none).
HeadingLevel int
// OnTap is the handler for tap/click actions.
OnTap func()
// OnLongPress is the handler for long press actions.
OnLongPress func()
// OnScrollLeft is the handler for scroll left actions.
OnScrollLeft func()
// OnScrollRight is the handler for scroll right actions.
OnScrollRight func()
// OnScrollUp is the handler for scroll up actions.
OnScrollUp func()
// OnScrollDown is the handler for scroll down actions.
OnScrollDown func()
// OnIncrease is the handler for increase actions.
OnIncrease func()
// OnDecrease is the handler for decrease actions.
OnDecrease func()
// OnDismiss is the handler for dismiss actions.
OnDismiss func()
// CustomActions is a list of custom accessibility actions.
CustomActions []semantics.CustomSemanticsAction
// CustomActionHandlers maps custom action IDs to handlers.
CustomActionHandlers map[int64]func()
}
func SemanticGroup
func SemanticGroup(child core.Widget) Semantics
SemanticGroup groups related widgets into a single accessibility unit. The screen reader will read all children as one combined announcement.
Example:
SemanticGroup(widgets.Row{Children: []core.Widget{icon, priceText, currencyText}})
func SemanticHeading
func SemanticHeading(level int, child core.Widget) Semantics
SemanticHeading marks a widget as a heading at the specified level (1-6). Screen readers use headings for navigation.
Example:
SemanticHeading(1, widgets.Text{Content: "Welcome"})
func SemanticImage
func SemanticImage(description string, child core.Widget) Semantics
SemanticImage marks a widget as an image with the given description. Use this for meaningful images that convey information.
Example:
SemanticImage("Chart showing sales growth", chartWidget)
func SemanticLabel
func SemanticLabel(label string, child core.Widget) Semantics
SemanticLabel wraps a child with an accessibility label. Use this to provide a description for widgets that don't have built-in semantics.
Example:
SemanticLabel("Company logo", logoImage)
func SemanticLink
func SemanticLink(label string, onTap func(), child core.Widget) Semantics
SemanticLink marks a widget as a link with the given label.
Example:
SemanticLink("Visit our website", func() { openURL() }, linkText)
func SemanticLiveRegion
func SemanticLiveRegion(child core.Widget) Semantics
SemanticLiveRegion marks a widget as a live region that announces changes. Use this for content that updates dynamically (e.g., status messages, timers).
Example:
SemanticLiveRegion(statusText)
func Tappable
func Tappable(label string, onTap func(), child core.Widget) Semantics
Tappable creates an accessible tappable widget with the given label. This is the accessible version of Tap() - use this when the tappable element should be accessible to screen readers.
Example:
Tappable("Submit form", func() { submit() }, myButton)
func TappableWithHint
func TappableWithHint(label, hint string, onTap func(), child core.Widget) Semantics
TappableWithHint creates an accessible tappable widget with custom label and hint.
func (Semantics) Child
func (s Semantics) Child() core.Widget
Child returns the child widget.
func (Semantics) CreateElement
func (s Semantics) CreateElement() core.Element
func (Semantics) CreateRenderObject
func (s Semantics) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Semantics) Key
func (s Semantics) Key() any
func (Semantics) UpdateRenderObject
func (s Semantics) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type SemanticsGestureHandler
SemanticsGestureHandler wraps gestures with accessibility semantics. This is used internally by widgets to connect gestures with semantics actions.
type SemanticsGestureHandler struct {
TapHandler *gestures.TapGestureRecognizer
OnTap func()
OnLongPress func()
}
func (*SemanticsGestureHandler) BuildSemanticsActions
func (h *SemanticsGestureHandler) BuildSemanticsActions() *semantics.SemanticsActions
BuildSemanticsActions creates semantics actions from the gesture handlers.
type SizedBox
SizedBox constrains its child to a specific size.
type SizedBox struct {
Width float64
Height float64
ChildWidget core.Widget
}
func HSpace
func HSpace(width float64) SizedBox
HSpace creates a fixed-width horizontal spacer.
func Spacer
func Spacer(size float64) SizedBox
Spacer creates a fixed-size spacer (alias for VSpace).
func VSpace
func VSpace(height float64) SizedBox
VSpace creates a fixed-height vertical spacer.
func (SizedBox) Child
func (s SizedBox) Child() core.Widget
func (SizedBox) CreateElement
func (s SizedBox) CreateElement() core.Element
func (SizedBox) CreateRenderObject
func (s SizedBox) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (SizedBox) Key
func (s SizedBox) Key() any
func (SizedBox) UpdateRenderObject
func (s SizedBox) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
type Stack
Stack overlays children on top of each other.
Children are painted in order, with the first child at the bottom and the last child on top. Hit testing proceeds in reverse (topmost first).
Sizing Behavior
With StackFitLoose (default), the Stack sizes itself to fit the largest child. With StackFitExpand, children are forced to fill the available space.
Positioning Children
Non-positioned children use the Alignment to determine their position. For absolute positioning, wrap children in Positioned:
Stack{
ChildrenWidgets: []core.Widget{
// Background fills the stack
Container{Color: bgColor},
// Badge in top-right corner
Positioned{Top: Ptr(8), Right: Ptr(8), ChildWidget: badge},
},
}
type Stack struct {
// ChildrenWidgets are the widgets to overlay. First child is at the bottom,
// last child is on top.
ChildrenWidgets []core.Widget
// Alignment positions non-Positioned children within the stack.
// Defaults to top-left (AlignmentTopLeft).
Alignment layout.Alignment
// Fit controls how children are sized.
Fit StackFit
}
Example:
This example shows how to create a stack with overlapping children.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
stack := widgets.Stack{
ChildrenWidgets: []core.Widget{
// Background
widgets.Container{
Color: rendering.RGB(200, 200, 200),
Width: 200,
Height: 200,
},
// Foreground centered via Alignment
widgets.Container{
Color: rendering.RGB(100, 149, 237),
Width: 100,
Height: 100,
},
},
Alignment: layout.AlignmentCenter,
}
_ = stack
}
Example (With Positioned):
This example shows a Stack with Positioned children for absolute positioning.
package main
import (
"github.com/go-drift/drift/pkg/core"
"github.com/go-drift/drift/pkg/layout"
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
stack := widgets.Stack{
ChildrenWidgets: []core.Widget{
// Background fills the stack
widgets.Container{
Color: rendering.RGB(240, 240, 240),
Width: 300,
Height: 200,
},
// Badge in top-right corner
widgets.Positioned{
Top: widgets.Ptr(8),
Right: widgets.Ptr(8),
ChildWidget: widgets.Container{
Color: rendering.RGB(255, 0, 0),
Width: 20,
Height: 20,
Padding: layout.EdgeInsetsAll(4),
},
},
// Bottom toolbar stretching horizontally
widgets.Positioned{
Left: widgets.Ptr(0),
Right: widgets.Ptr(0),
Bottom: widgets.Ptr(0),
ChildWidget: widgets.Container{
Color: rendering.RGB(33, 33, 33),
Height: 48,
},
},
},
}
_ = stack
}
func (Stack) Children
func (s Stack) Children() []core.Widget
Children returns the child widgets.
func (Stack) CreateElement
func (s Stack) CreateElement() core.Element
CreateElement returns a RenderObjectElement for this Stack.
func (Stack) CreateRenderObject
func (s Stack) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
CreateRenderObject creates the RenderStack.
func (Stack) Key
func (s Stack) Key() any
Key returns nil (no key).
func (Stack) UpdateRenderObject
func (s Stack) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
UpdateRenderObject updates the RenderStack.
type StackFit
StackFit determines how children are sized within a Stack.
type StackFit int
const (
// StackFitLoose allows children to size themselves.
StackFitLoose StackFit = iota
// StackFitExpand forces children to fill the stack.
StackFitExpand
)
type Switch
Switch toggles between on/off states.
type Switch struct {
// Value indicates the current on/off state.
Value bool
// OnChanged is called when the switch toggles.
OnChanged func(bool)
// Disabled disables interaction when true.
Disabled bool
// Width controls the overall width.
Width float64
// Height controls the overall height.
Height float64
// ActiveColor is the track color when on.
ActiveColor rendering.Color
// InactiveColor is the track color when off.
InactiveColor rendering.Color
// ThumbColor is the thumb fill color.
ThumbColor rendering.Color
}
func (Switch) Build
func (s Switch) Build(ctx core.BuildContext) core.Widget
func (Switch) CreateElement
func (s Switch) CreateElement() core.Element
func (Switch) Key
func (s Switch) Key() any
type TabBar
TabBar displays a row of tabs.
type TabBar struct {
Items []TabItem
CurrentIndex int
OnTap func(index int)
BackgroundColor rendering.Color
ActiveColor rendering.Color
InactiveColor rendering.Color
IndicatorColor rendering.Color
IndicatorHeight float64
Padding layout.EdgeInsets
Height float64
}
func (TabBar) Build
func (t TabBar) Build(ctx core.BuildContext) core.Widget
func (TabBar) CreateElement
func (t TabBar) CreateElement() core.Element
func (TabBar) Key
func (t TabBar) Key() any
type TabItem
TabItem describes a single tab entry.
type TabItem struct {
Label string
Icon core.Widget
}
type Text
Text displays a string with a single style.
Text Wrapping and Line Limits
The Wrap and MaxLines fields control how text flows and truncates:
-
Wrap=false (default): Text renders on a single line, extending beyond the constraint width. Use for labels, buttons, and short text.
-
Wrap=true: Text wraps at the constraint width, creating multiple lines. Use for paragraphs, descriptions, and content that should fit a container.
-
MaxLines: Limits the number of visible lines. When Wrap=true and text exceeds MaxLines, it truncates. When MaxLines=0 (default), no limit applies.
Common patterns:
// Single line, may overflow
Text{Content: "Label", Wrap: false}
// Wrapping paragraph
Text{Content: longText, Wrap: true}
// Preview text limited to 2 lines
Text{Content: description, Wrap: true, MaxLines: 2}
type Text struct {
// Content is the text string to display.
Content string
// Style controls the font, size, color, and other text properties.
Style rendering.TextStyle
// MaxLines limits the number of visible lines (0 = unlimited).
// Lines beyond this limit are not rendered.
MaxLines int
// Wrap enables text wrapping at the constraint width.
// When false, text renders on a single line.
Wrap bool
}
Example:
This example shows how to display styled text.
package main
import (
"github.com/go-drift/drift/pkg/rendering"
"github.com/go-drift/drift/pkg/widgets"
)
func main() {
text := widgets.Text{
Content: "Hello, Drift!",
Style: rendering.TextStyle{
FontSize: 24,
Color: rendering.RGB(33, 33, 33),
},
Wrap: true,
MaxLines: 2,
}
_ = text
}
func TextOf
func TextOf(content string, style rendering.TextStyle) Text
TextOf creates a styled text widget.
func (Text) CreateElement
func (t Text) CreateElement() core.Element
func (Text) CreateRenderObject
func (t Text) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
func (Text) Key
func (t Text) Key() any
func (Text) UpdateRenderObject
func (t Text) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
func (Text) WithWrap
func (t Text) WithWrap(wrap bool) Text
type TextField
TextField is a styled text input built on the native text input connection.
type TextField struct {
// Controller manages the text content and selection.
Controller *platform.TextEditingController
// Label is shown above the field.
Label string
// Placeholder text shown when empty.
Placeholder string
// HelperText is shown below the field when no error.
HelperText string
// ErrorText is shown below the field when non-empty.
ErrorText string
// KeyboardType specifies the keyboard to show.
KeyboardType platform.KeyboardType
// InputAction specifies the keyboard action button.
InputAction platform.TextInputAction
// Obscure hides the text (for passwords).
Obscure bool
// Autocorrect enables auto-correction.
Autocorrect bool
// OnChanged is called when the text changes.
OnChanged func(string)
// OnSubmitted is called when the user submits.
OnSubmitted func(string)
// OnEditingComplete is called when editing is complete.
OnEditingComplete func()
// Disabled controls whether the field rejects input.
Disabled bool
// Width of the text field (0 = expand to fill).
Width float64
// Height of the text field.
Height float64
// Padding inside the text field.
Padding layout.EdgeInsets
// BackgroundColor of the text field.
BackgroundColor rendering.Color
// BorderColor of the text field.
BorderColor rendering.Color
// FocusColor of the text field outline.
FocusColor rendering.Color
// BorderRadius for rounded corners.
BorderRadius float64
// Style for the text.
Style rendering.TextStyle
// PlaceholderColor for the placeholder text.
PlaceholderColor rendering.Color
}
func (TextField) Build
func (t TextField) Build(ctx core.BuildContext) core.Widget
func (TextField) CreateElement
func (t TextField) CreateElement() core.Element
func (TextField) Key
func (t TextField) Key() any
type View
View is the root widget that hosts the render tree.
type View struct {
ChildWidget core.Widget
}
func Root
func Root(child core.Widget) View
Root creates a top-level view widget with the given child.
func (View) Child
func (v View) Child() core.Widget
Child returns the single child for render object wiring.
func (View) CreateElement
func (v View) CreateElement() core.Element
func (View) CreateRenderObject
func (v View) CreateRenderObject(ctx core.BuildContext) layout.RenderObject
CreateRenderObject builds the root render view.
func (View) Key
func (v View) Key() any
func (View) UpdateRenderObject
func (v View) UpdateRenderObject(ctx core.BuildContext, renderObject layout.RenderObject)
UpdateRenderObject updates the root render view.
type WebViewController
WebViewController provides control over a NativeWebView.
type WebViewController struct {
// contains filtered or unexported fields
}
func (*WebViewController) GoBack
func (c *WebViewController) GoBack() error
GoBack navigates back in history.
func (*WebViewController) GoForward
func (c *WebViewController) GoForward() error
GoForward navigates forward in history.
func (*WebViewController) LoadURL
func (c *WebViewController) LoadURL(url string) error
LoadURL loads the specified URL.
func (*WebViewController) Reload
func (c *WebViewController) Reload() error
Reload reloads the current page.
Generated by gomarkdoc