core/stripe/widget.go

Functions Structs

Functions

func AccessibilityActions

AccessibilityActions returns nil. Actions are on individual buttons.

func (w *Widget) AccessibilityActions() []a11y.Action {
	return nil
}

func AccessibilityHint

AccessibilityHint returns an empty string.

func (w *Widget) AccessibilityHint() string {
	return ""
}

func AccessibilityLabel

AccessibilityLabel returns "Tool Window Strip".

func (w *Widget) AccessibilityLabel() string {
	return a11yLabel
}

func AccessibilityRole

AccessibilityRole returns [a11y.RoleToolbar].

func (w *Widget) AccessibilityRole() a11y.Role {
	return a11y.RoleToolbar
}

func AccessibilityState

AccessibilityState returns the current accessibility state.

func (w *Widget) AccessibilityState() a11y.State {
	return a11y.State{
		Disabled:	!w.IsEnabled(),
		Hidden:		!w.IsVisible(),
	}
}

func AccessibilityValue

AccessibilityValue returns the active button ID.

func (w *Widget) AccessibilityValue() string {
	return w.activeID
}

func ActiveButtonID

ActiveButtonID returns the ID of the currently active button.

func (w *Widget) ActiveButtonID() string {
	return w.activeID
}

func BottomItemCount

BottomItemCount returns the number of bottom-group buttons.

func (w *Widget) BottomItemCount() int {
	return len(w.cfg.bottomItems)
}

func Children

Children returns nil. Stripe buttons are not child widgets.

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

func Draw

Draw renders the stripe background and all buttons.

func (w *Widget) Draw(ctx widget.Context, canvas widget.Canvas) {
	if !w.IsVisible() {
		return
	}

	bounds := w.Bounds()

	// Draw background at screen position.
	w.painter.PaintBackground(canvas, bounds)

	// Draw buttons in local coordinates.
	canvas.PushTransform(bounds.Min)

	for i := range w.cfg.topItems {
		w.painter.PaintButton(canvas, ButtonPaintState{
			Bounds:		w.topStates[i].bounds,
			Icon:		w.cfg.topItems[i].Icon,
			Label:		w.cfg.topItems[i].Label,
			Active:		w.cfg.topItems[i].ID == w.activeID,
			Hovered:	w.topStates[i].interaction == stateHover,
			Pressed:	w.topStates[i].interaction == statePressed,
			ShowLabel:	w.cfg.showLabels,
		})
	}

	for i := range w.cfg.bottomItems {
		w.painter.PaintButton(canvas, ButtonPaintState{
			Bounds:		w.bottomStates[i].bounds,
			Icon:		w.cfg.bottomItems[i].Icon,
			Label:		w.cfg.bottomItems[i].Label,
			Active:		w.cfg.bottomItems[i].ID == w.activeID,
			Hovered:	w.bottomStates[i].interaction == stateHover,
			Pressed:	w.bottomStates[i].interaction == statePressed,
			ShowLabel:	w.cfg.showLabels,
		})
	}

	canvas.PopTransform()
}

func Event

Event handles input events for the stripe.

func (w *Widget) Event(ctx widget.Context, e event.Event) bool {
	if !w.IsVisible() || !w.IsEnabled() {
		return false
	}

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

func Layout

Layout calculates the stripe's preferred size within the given constraints.

The stripe takes its configured width and fills available height.

func (w *Widget) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size {
	stripW := w.resolvedWidth()
	preferred := geometry.Sz(stripW, constraints.MaxHeight)
	size := constraints.Constrain(preferred)

	w.layoutButtons(size)
	w.SetBounds(geometry.FromPointSize(w.Position(), size))
	return size
}

func New

New creates a new stripe Widget with the given options.

 

The returned widget is visible and enabled by default.

func New(opts ...Option) *Widget {
	w := &Widget{
		painter:	DefaultPainter{},
		hoveredIdx:	noHover,
	}
	w.SetVisible(true)
	w.SetEnabled(true)

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

	w.activeID = w.cfg.activeID

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

	w.topStates = make([]buttonState, len(w.cfg.topItems))
	w.bottomStates = make([]buttonState, len(w.cfg.bottomItems))
	return w
}

func SetActiveID

SetActiveID sets the currently active button by ID.

func (w *Widget) SetActiveID(id string) {
	w.activeID = id
}

func TopItemCount

TopItemCount returns the number of top-group buttons.

func (w *Widget) TopItemCount() int {
	return len(w.cfg.topItems)
}

Structs

type Widget struct

Widget implements a vertical tool window sidebar strip with icon buttons.

 

A stripe is created with [New] using functional options:

 

s := stripe.New(

stripe.TopItems(

stripe.Button{ID: "project", Label: "Project", Icon: icon.FolderClosed},

),

stripe.BottomItems(

stripe.Button{ID: "terminal", Label: "Terminal", Icon: icon.Terminal},

),

stripe.ActiveID("terminal"),

stripe.ShowLabels(true),

)

type Widget struct {
	widget.WidgetBase

	cfg		config
	painter		Painter
	activeID	string

	topStates	[]buttonState
	bottomStates	[]buttonState
	hoveredIdx	int	// index into allButtons() or noHover
}