stripe

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package stripe provides a vertical tool window sidebar widget.

A stripe displays a vertical column of icon buttons with optional text labels, split into top and bottom groups. It is commonly used at the edges of an IDE window to provide quick access to tool windows (Project, Terminal, Git, etc.), following the JetBrains IDE ToolWindowToolbar pattern.

Construction uses functional options:

s := stripe.New(
    stripe.TopItems(
        stripe.Button{ID: "project", Label: "Project", Icon: icon.FolderClosed, OnClick: fn},
        stripe.Button{ID: "commit", Label: "Commit", Icon: icon.Check, OnClick: fn},
    ),
    stripe.BottomItems(
        stripe.Button{ID: "terminal", Label: "Terminal", Icon: icon.Terminal, OnClick: fn},
    ),
    stripe.ActiveID("terminal"),
    stripe.ShowLabels(true),
    stripe.Width(64),
    stripe.PainterOpt(devtoolsPainter),
)

Layout

Buttons are stacked vertically. Top items are gravity-aligned to the top edge and bottom items to the bottom edge. Each button spans the full strip width.

Visual Style

The visual rendering is provided by a Painter implementation. Each design system can supply its own painter. If no painter is set, DefaultPainter is used.

Interaction

Buttons respond to mouse hover, press, and click. Clicking a button fires its OnClick handler and sets it as the active button. The active button receives a distinct visual treatment from the painter.

Accessibility

The stripe has the a11y.RoleToolbar role. Individual buttons announce their label to screen readers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// ID uniquely identifies this button within the stripe.
	// Used to set and query the active button via [ActiveID].
	ID string

	// Label is the human-readable text displayed below the icon.
	// Also used for accessibility announcements.
	Label string

	// Icon is the vector icon data rendered in the button center.
	Icon icon.IconData

	// OnClick is the callback invoked when the button is activated
	// by mouse click. May be nil.
	OnClick func()
}

Button represents a single tool window button in the stripe.

Each button has a unique ID for identification, a human-readable Label displayed below the icon (when labels are enabled), an Icon for the visual indicator, and an OnClick callback fired when the button is activated.

type ButtonPaintState

type ButtonPaintState struct {
	// Bounds is the button's rectangle in local coordinates.
	Bounds geometry.Rect

	// Icon is the vector icon data for the button.
	Icon icon.IconData

	// Label is the button's text label.
	Label string

	// Active indicates this button is the currently selected tool window.
	Active bool

	// Hovered indicates the mouse cursor is over this button.
	Hovered bool

	// Pressed indicates the mouse button is held down on this button.
	Pressed bool

	// ShowLabel controls whether the text label is rendered below the icon.
	ShowLabel bool
}

ButtonPaintState provides the current button state to the painter.

type DefaultPainter

type DefaultPainter struct{}

DefaultPainter provides a minimal fallback painter with no design system styling. It draws simple gray buttons suitable for testing and prototyping.

func (DefaultPainter) PaintBackground

func (p DefaultPainter) PaintBackground(canvas widget.Canvas, bounds geometry.Rect)

PaintBackground renders a light gray background for the stripe.

func (DefaultPainter) PaintButton

func (p DefaultPainter) PaintButton(canvas widget.Canvas, state ButtonPaintState)

PaintButton renders a button with icon and optional text label.

type Option

type Option func(*config)

Option configures a stripe widget during construction.

func ActiveID

func ActiveID(id string) Option

ActiveID sets the ID of the currently active (selected) button. The active button receives distinct visual treatment from the painter.

func BottomItems

func BottomItems(items ...Button) Option

BottomItems sets the buttons displayed in the bottom group of the stripe. Bottom items are gravity-aligned to the bottom edge of the strip.

func OnSelect

func OnSelect(fn func(id string)) Option

OnSelect sets a callback invoked when any button is clicked. The callback receives the ID of the clicked button. This is called in addition to the button's own OnClick handler.

func PainterOpt

func PainterOpt(p Painter) Option

PainterOpt sets the painter used to render the stripe. If not set, DefaultPainter is used.

func ShowLabels

func ShowLabels(show bool) Option

ShowLabels controls whether text labels are displayed below button icons. When true, buttons are taller to accommodate the label text and the strip defaults to a wider width (64px). When false, buttons show icons only and the strip defaults to 40px width.

func TopItems

func TopItems(items ...Button) Option

TopItems sets the buttons displayed in the top group of the stripe. Top items are gravity-aligned to the top edge of the strip.

func Width

func Width(w float32) Option

Width sets the stripe width in logical pixels. Default is 64px with labels or 40px without labels.

type Painter

type Painter interface {
	// PaintBackground renders the stripe background and optional border.
	PaintBackground(canvas widget.Canvas, bounds geometry.Rect)

	// PaintButton renders a single button within the stripe.
	PaintButton(canvas widget.Canvas, state ButtonPaintState)
}

Painter draws the visual representation of a stripe toolbar. Each design system (DevTools, Material 3, Fluent) provides its own Painter implementation to render the stripe in its visual style.

If no Painter is set, the stripe uses DefaultPainter.

type Widget

type Widget struct {
	widget.WidgetBase
	// contains filtered or unexported fields
}

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),
)

func New

func New(opts ...Option) *Widget

New creates a new stripe Widget with the given options.

The returned widget is visible and enabled by default.

func (*Widget) AccessibilityActions

func (w *Widget) AccessibilityActions() []a11y.Action

AccessibilityActions returns nil. Actions are on individual buttons.

func (*Widget) AccessibilityHint

func (w *Widget) AccessibilityHint() string

AccessibilityHint returns an empty string.

func (*Widget) AccessibilityLabel

func (w *Widget) AccessibilityLabel() string

AccessibilityLabel returns "Tool Window Strip".

func (*Widget) AccessibilityRole

func (w *Widget) AccessibilityRole() a11y.Role

AccessibilityRole returns a11y.RoleToolbar.

func (*Widget) AccessibilityState

func (w *Widget) AccessibilityState() a11y.State

AccessibilityState returns the current accessibility state.

func (*Widget) AccessibilityValue

func (w *Widget) AccessibilityValue() string

AccessibilityValue returns the active button ID.

func (*Widget) ActiveButtonID

func (w *Widget) ActiveButtonID() string

ActiveButtonID returns the ID of the currently active button.

func (*Widget) BottomItemCount

func (w *Widget) BottomItemCount() int

BottomItemCount returns the number of bottom-group buttons.

func (*Widget) Children

func (w *Widget) Children() []widget.Widget

Children returns nil. Stripe buttons are not child widgets.

func (*Widget) Draw

func (w *Widget) Draw(ctx widget.Context, canvas widget.Canvas)

Draw renders the stripe background and all buttons.

func (*Widget) Event

func (w *Widget) Event(ctx widget.Context, e event.Event) bool

Event handles input events for the stripe.

func (*Widget) Layout

func (w *Widget) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size

Layout calculates the stripe's preferred size within the given constraints. The stripe takes its configured width and fills available height.

func (*Widget) SetActiveID

func (w *Widget) SetActiveID(id string)

SetActiveID sets the currently active button by ID.

func (*Widget) TopItemCount

func (w *Widget) TopItemCount() int

TopItemCount returns the number of top-group buttons.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL