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 ¶
- type Button
- type ButtonPaintState
- type DefaultPainter
- type Option
- type Painter
- type Widget
- func (w *Widget) AccessibilityActions() []a11y.Action
- func (w *Widget) AccessibilityHint() string
- func (w *Widget) AccessibilityLabel() string
- func (w *Widget) AccessibilityRole() a11y.Role
- func (w *Widget) AccessibilityState() a11y.State
- func (w *Widget) AccessibilityValue() string
- func (w *Widget) ActiveButtonID() string
- func (w *Widget) BottomItemCount() int
- func (w *Widget) Children() []widget.Widget
- func (w *Widget) Draw(ctx widget.Context, canvas widget.Canvas)
- func (w *Widget) Event(ctx widget.Context, e event.Event) bool
- func (w *Widget) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size
- func (w *Widget) SetActiveID(id string)
- func (w *Widget) TopItemCount() int
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 ¶
ActiveID sets the ID of the currently active (selected) button. The active button receives distinct visual treatment from the painter.
func BottomItems ¶
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 ¶
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 ¶
PainterOpt sets the painter used to render the stripe. If not set, DefaultPainter is used.
func ShowLabels ¶
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.
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 ¶
New creates a new stripe Widget with the given options.
The returned widget is visible and enabled by default.
func (*Widget) AccessibilityActions ¶
AccessibilityActions returns nil. Actions are on individual buttons.
func (*Widget) AccessibilityHint ¶
AccessibilityHint returns an empty string.
func (*Widget) AccessibilityLabel ¶
AccessibilityLabel returns "Tool Window Strip".
func (*Widget) AccessibilityRole ¶
AccessibilityRole returns a11y.RoleToolbar.
func (*Widget) AccessibilityState ¶
AccessibilityState returns the current accessibility state.
func (*Widget) AccessibilityValue ¶
AccessibilityValue returns the active button ID.
func (*Widget) ActiveButtonID ¶
ActiveButtonID returns the ID of the currently active button.
func (*Widget) BottomItemCount ¶
BottomItemCount returns the number of bottom-group buttons.
func (*Widget) Layout ¶
Layout calculates the stripe's preferred size within the given constraints. The stripe takes its configured width and fills available height.
func (*Widget) SetActiveID ¶
SetActiveID sets the currently active button by ID.
func (*Widget) TopItemCount ¶
TopItemCount returns the number of top-group buttons.