core/popover/tooltip.go

Functions Structs

Functions

func Children

Children returns nil; tooltip overlay is a leaf widget.

func (to *tooltipOverlay) Children() []widget.Widget {
	return nil
}

func Children

Children returns the trigger widget as the sole child.

func (t *Tooltip) Children() []widget.Widget {
	if t.cfg.trigger == nil {
		return nil
	}
	return []widget.Widget{t.cfg.trigger}
}

func Draw

Draw renders the tooltip background and text.

func (to *tooltipOverlay) Draw(_ widget.Context, canvas widget.Canvas) {
	if canvas == nil {
		return
	}

	to.painter.PaintTooltip(canvas, &TooltipPaintState{
		Bounds:		to.Bounds(),
		Text:		to.text,
		Placement:	to.placement,
	})
}

func Draw

Draw renders the trigger widget. The tooltip content is drawn by the

overlay stack.

func (t *Tooltip) Draw(ctx widget.Context, canvas widget.Canvas) {
	if canvas == nil {
		return
	}
	if t.cfg.trigger != nil {
		t.cfg.trigger.Draw(ctx, canvas)
	}
}

func Event

Event handles input events, primarily mouse enter/leave on the trigger.

func (t *Tooltip) Event(ctx widget.Context, e event.Event) bool {
	if t.cfg.ResolvedDisabled() {
		return false
	}

	// Delegate to trigger first.
	if t.cfg.trigger != nil && t.cfg.trigger.Event(ctx, e) {
		return true
	}

	me, ok := e.(*event.MouseEvent)
	if !ok {
		return false
	}

	return t.handleMouseEvent(ctx, me)
}

func Event

Event returns false; tooltips do not consume events.

func (to *tooltipOverlay) Event(_ widget.Context, _ event.Event) bool {
	return false
}

func IsOpen

IsOpen returns true if the tooltip is currently visible.

func (t *Tooltip) IsOpen() bool {
	return t.visible
}

func Layout

Layout returns the pre-calculated tooltip size.

func (to *tooltipOverlay) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size {
	return constraints.Constrain(to.size)
}

func Layout

Layout calculates the tooltip's size. The tooltip itself takes the size

of its trigger widget.

func (t *Tooltip) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size {
	// Check if delay has elapsed and tooltip should appear.
	if t.hovered && !t.visible && !t.hoverStart.IsZero() {
		if ctx.Now().Sub(t.hoverStart) >= t.cfg.delay {
			t.show(ctx)
		}
	}

	if t.cfg.trigger != nil {
		return t.cfg.trigger.Layout(ctx, constraints)
	}
	return constraints.Constrain(geometry.Sz(0, 0))
}

func Mount

Mount creates signal bindings for push-based invalidation.

func (t *Tooltip) Mount(ctx widget.Context) {
	sched := ctx.Scheduler()
	if sched == nil {
		return
	}
	if t.cfg.visibleSignal != nil {
		b := state.BindToScheduler(t.cfg.visibleSignal, t, sched)
		t.AddBinding(b)
	}
}

func NewTooltip

NewTooltip creates a new Tooltip with the given options.

 

The tooltip is initially hidden and appears on hover after the configured delay.

func NewTooltip(opts ...Option) *Tooltip {
	t := &Tooltip{
		painter: DefaultPainter{},
	}
	t.cfg = defaultConfig()
	t.SetVisible(true)
	t.SetEnabled(true)

	for _, opt := range opts {
		opt(&t.cfg)
	}

	if t.cfg.painter != nil {
		t.painter = t.cfg.painter
	}

	// ADR-028: parent chain for upward dirty propagation.
	// Flutter: RenderObject.adoptChild sets parent on each child.
	if t.cfg.trigger != nil {
		type parentSetter interface{ SetParent(widget.Widget) }
		if ps, ok := t.cfg.trigger.(parentSetter); ok {
			ps.SetParent(t)
		}
	}

	return t
}

func Text

Text returns the tooltip text.

func (t *Tooltip) Text() string {
	return t.cfg.tooltipText
}

func Unmount

Unmount is called when the tooltip is removed from the widget tree.

func (t *Tooltip) Unmount() {
	// Bindings are cleaned up automatically by WidgetBase.CleanupBindings().
}

Structs

type Tooltip struct

Tooltip is a hover-triggered floating label anchored to a trigger widget.

It appears after a configurable delay when the mouse enters the trigger,

and disappears when the mouse leaves.

 

Create with [NewTooltip] using functional options.

type Tooltip struct {
	widget.WidgetBase

	cfg	config
	painter	Painter
	visible	bool
	hovered	bool

	// hoverStart tracks when the mouse entered the trigger for delay timing.
	hoverStart	time.Time

	// overlayWidget is the tooltip overlay pushed to the stack.
	overlayWidget	*tooltipOverlay
}