Documentation
¶
Overview ¶
Package transition provides widget enter/exit animations.
Transition wraps a widget and plays an animation when the widget appears (enters) or disappears (exits). Supported effect types include fade, slide, and scale.
Quick Start ¶
wrapped := transition.Wrap(myWidget,
transition.EnterEffect(transition.FadeIn()),
transition.ExitEffect(transition.FadeOut()),
transition.Duration(300 * time.Millisecond),
)
wrapped.Show() // plays enter animation, then shows widget
wrapped.Hide() // plays exit animation, then hides widget
Effects ¶
Three built-in effect types are provided:
- Fade: animate opacity from 0 to 1 (enter) or 1 to 0 (exit)
- Slide: translate the widget from/to a given direction
- Scale: scale the widget from/to a smaller size with fade
Effects can be combined by composing multiple property animations within a single Effect value.
Canvas Requirements ¶
Fade effects require the canvas to implement OpacityPusher. If the canvas does not support opacity, fade effects are silently skipped (graceful degradation). Slide effects use widget.Canvas.PushTransform. Scale effects adjust the child widget bounds around the center point.
Retained Mode ¶
During animation, the transition widget calls widget.WidgetBase.SetNeedsRedraw to request continuous redraws until the animation completes.
Index ¶
- type Direction
- type Effect
- type OpacityPusher
- type Option
- type Transition
- func (t *Transition) Child() widget.Widget
- func (t *Transition) Children() []widget.Widget
- func (t *Transition) Draw(ctx widget.Context, canvas widget.Canvas)
- func (t *Transition) Event(ctx widget.Context, e event.Event) bool
- func (t *Transition) Hide()
- func (t *Transition) IsAnimating() bool
- func (t *Transition) IsShown() bool
- func (t *Transition) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size
- func (t *Transition) Show()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Direction ¶
type Direction uint8
Direction specifies the origin or target edge for slide effects.
const ( FromTop Direction = iota // Slide in from top edge. FromBottom // Slide in from bottom edge. FromLeft // Slide in from left edge. FromRight // Slide in from right edge. ToTop // Slide out toward top edge. ToBottom // Slide out toward bottom edge. ToLeft // Slide out toward left edge. ToRight // Slide out toward right edge. )
Slide directions for enter effects (From*) and exit effects (To*).
type Effect ¶
type Effect struct {
// OpacityStart is the starting opacity. Negative means opacity is not animated.
OpacityStart float64
// OpacityEnd is the ending opacity.
OpacityEnd float64
// TranslateXFraction is the starting X offset as a fraction of widget width.
// For example, -1.0 means start one full width to the left.
TranslateXFraction float64
// TranslateYFraction is the starting Y offset as a fraction of widget height.
TranslateYFraction float64
// ScaleStart is the starting scale factor. Negative means scale is not animated.
ScaleStart float64
// ScaleEnd is the ending scale factor.
ScaleEnd float64
}
Effect describes the visual transformation applied during a transition.
Each field pair (Start/End) defines the range of animation for that property. A negative Start value means the property is not animated. Effect is a value type; create instances via the provided constructors.
func None ¶
func None() Effect
None returns an effect that performs no animation (instant transition).
func ScaleIn ¶
func ScaleIn() Effect
ScaleIn returns an effect that scales from 0.8 to 1.0 with a fade in.
func ScaleOut ¶
func ScaleOut() Effect
ScaleOut returns an effect that scales from 1.0 to 0.8 with a fade out.
func SlideIn ¶
SlideIn returns a slide-in effect from the given direction.
The widget slides from off-screen (one full dimension away) to its final position. Only From* directions are meaningful for enter effects; To* directions are treated as their From* equivalents.
type OpacityPusher ¶
type OpacityPusher interface {
// PushOpacity pushes an opacity multiplier onto the draw state stack.
// Opacity is in the range [0, 1]. Nested calls multiply.
PushOpacity(opacity float64)
// PopOpacity removes the most recently pushed opacity.
PopOpacity()
}
OpacityPusher is an optional Canvas capability for opacity effects.
If the Canvas passed to Draw implements this interface, fade effects will use PushOpacity/PopOpacity. Otherwise, fade effects are silently skipped (graceful degradation).
type Option ¶
type Option func(*transitionConfig)
Option configures a Transition widget.
func Easing ¶
Easing sets the easing function for both enter and exit effects. Defaults to animation.EaseOutCubic if not set.
func EnterEffect ¶
EnterEffect sets the effect played when the widget appears.
func ExitEffect ¶
ExitEffect sets the effect played when the widget disappears.
type Transition ¶
type Transition struct {
widget.WidgetBase
// contains filtered or unexported fields
}
Transition wraps a child widget with enter/exit animation effects.
When Show is called, the enter effect is played and the child becomes visible. When Hide is called, the exit effect is played and the child is hidden after the animation completes.
Transition implements widget.Widget.
func Wrap ¶
func Wrap(child widget.Widget, opts ...Option) *Transition
Wrap creates a new Transition that wraps the given child widget.
By default the widget starts visible with no animation effects. Use EnterEffect, ExitEffect, Duration, and Easing options to configure the transition behavior.
wrapped := transition.Wrap(myWidget,
transition.EnterEffect(transition.FadeIn()),
transition.ExitEffect(transition.FadeOut()),
transition.Duration(300 * time.Millisecond),
)
func (*Transition) Child ¶
func (t *Transition) Child() widget.Widget
Child returns the wrapped child widget.
func (*Transition) Children ¶
func (t *Transition) Children() []widget.Widget
Children returns the wrapped child as a single-element slice.
func (*Transition) Draw ¶
func (t *Transition) Draw(ctx widget.Context, canvas widget.Canvas)
Draw renders the child widget with transition effects applied.
func (*Transition) Hide ¶
func (t *Transition) Hide()
Hide hides the widget, playing the exit effect if configured.
If an enter animation is currently playing, it is replaced by the exit animation starting from the beginning.
func (*Transition) IsAnimating ¶
func (t *Transition) IsAnimating() bool
IsAnimating reports whether a transition animation is currently in progress.
func (*Transition) IsShown ¶
func (t *Transition) IsShown() bool
IsShown reports whether the widget is logically visible (enter complete or in progress). Returns false if hidden or exit animation is complete.
func (*Transition) Layout ¶
func (t *Transition) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size
Layout calculates the transition widget size by delegating to the child.
func (*Transition) Show ¶
func (t *Transition) Show()
Show makes the widget visible, playing the enter effect if configured.
If an exit animation is currently playing, it is replaced by the enter animation starting from the beginning.