Documentation
¶
Index ¶
- Constants
- func HSLToRGB(h, s, l float64) (r, g, b float64)
- func MouseToModalCoords(screenX, screenY, overlayLeft, overlayTop int) (relX, relY int)
- func RGBToHSL(r, g, b float64) (h, s, l float64)
- type ColorCanceledMsg
- type ColorChangedMsg
- type ColorChosenMsg
- type Config
- type Focus
- type HSL
- type Model
- type Option
- type RGB
- type SwatchPicker
- func (s *SwatchPicker) Color() string
- func (s *SwatchPicker) Focused() bool
- func (s *SwatchPicker) Open() bool
- func (s *SwatchPicker) SetBounds(row, col, w, h int)
- func (s *SwatchPicker) SetColor(c string)
- func (s *SwatchPicker) SetFocused(f bool)
- func (s *SwatchPicker) SetPickerOptions(opts ...Option)
- func (s *SwatchPicker) SetZoneManager(zm *zone.Manager)
- func (s *SwatchPicker) Size() (width, height int)
- func (s *SwatchPicker) SwatchView() string
- func (s *SwatchPicker) Update(msg tea.Msg) (*SwatchPicker, tea.Cmd)
- func (s *SwatchPicker) ViewWithOverlay(mainView string, viewWidth, viewHeight int) string
Constants ¶
const ( ZoneHueBar = "picker-hue" ZoneGrid = "picker-grid" ZonePresets = "picker-presets" )
Variables ¶
This section is empty.
Functions ¶
func MouseToModalCoords ¶
MouseToModalCoords converts normalized Bubble Tea screen coords (0-based X and Y, same as overlay.CellInModal) to coordinates relative to the modal’s top-left cell, in the form the picker’s zone handlers expect (contentCol = relX-1, contentRow = relY-1 after Pos-style offsets).
Types ¶
type ColorCanceledMsg ¶
type ColorCanceledMsg struct{}
ColorCanceledMsg is sent when the user cancels (Esc).
type ColorChangedMsg ¶ added in v0.1.0
type ColorChangedMsg struct {
Color string // Hex, e.g. "#rrggbb"
Dismiss bool // When true, host should remove the picker from layout (auto-dismiss mode).
}
ColorChangedMsg is sent when the user confirms a color (Enter, or mouse release on the grid). Handle it at your root or delegated model; Dismiss is true when WithAutoDismiss(true) was used.
type ColorChosenMsg ¶
type ColorChosenMsg = ColorChangedMsg
ColorChosenMsg is a type alias for ColorChangedMsg for backward compatibility.
type Config ¶ added in v0.1.0
type Config struct {
InitialColor string
Presets []string
FrameStyle lipgloss.Style
CustomFrame bool
AutoDismiss bool
}
Config holds static options for a picker built with New.
type Focus ¶
type Focus int
Focus indicates which part of the picker is focused for keyboard input (Tab cycles).
type HSL ¶
type HSL struct {
H, S, L float64
}
HSL holds hue (0-360), saturation (0-100), lightness (0-100).
type Model ¶
Model is the color picker state. It implements tea.Model.
func New ¶
New builds a picker from functional options. With no options, behavior matches the legacy default (red, no presets, standard frame, no auto-dismiss).
func (*Model) SetZoneManager ¶
SetZoneManager sets the zone manager for zone-based mouse interaction.
type Option ¶ added in v0.1.0
type Option func(*Config)
Option configures a picker via New(opts...).
func WithAutoDismiss ¶ added in v0.1.0
WithAutoDismiss sets whether the picker marks selections with ColorChangedMsg.Dismiss so hosts can remove the picker from the layout immediately after a choice (e.g. modal).
func WithInitialColor ¶ added in v0.1.0
WithInitialColor sets the starting HSL from a hex string (e.g. "#ff0000"). Invalid or empty hex falls back to the default red.
func WithPresets ¶ added in v0.1.0
WithPresets adds a row of brand swatches above the hue bar. Each string should be a hex color; invalid entries are skipped. Users can focus the preset row (Tab), move with ←/→, and press Enter to apply a preset to the picker.
type SwatchPicker ¶
type SwatchPicker struct {
// contains filtered or unexported fields
}
SwatchPicker is a color swatch (square + optional label + hex) that opens the modal picker when clicked. Embed it in your model, set bounds, forward messages, and use ViewWithOverlay(mainView, width, height) for the view. On ColorChosenMsg, update the swatch with SetColor(msg.Color) (or store the color in your app). SetZoneManager so the picker uses zone-based mouse interaction (host must Scan the view).
func NewSwatchPicker ¶
func NewSwatchPicker(initialColor, label string) *SwatchPicker
NewSwatchPicker returns a swatch that shows color and opens the modal picker on click. initialColor is hex (e.g. "#7E00AF"); label is optional (not shown in the minimal UI).
func (*SwatchPicker) Color ¶
func (s *SwatchPicker) Color() string
Color returns the current color (hex).
func (*SwatchPicker) Focused ¶
func (s *SwatchPicker) Focused() bool
Focused returns whether the swatch is currently focused.
func (*SwatchPicker) Open ¶
func (s *SwatchPicker) Open() bool
Open returns whether the swatch's color picker modal is currently open. Use this so your app can route input only to the open swatch when a modal is active.
func (*SwatchPicker) SetBounds ¶
func (s *SwatchPicker) SetBounds(row, col, w, h int)
SetBounds sets where the swatch is drawn (0-based row, col) and its size (w, h). If w or h is 0, Size() is used for that dimension. Call this before ViewWithOverlay so the modal is centered on the swatch and clicks are detected correctly.
func (*SwatchPicker) SetColor ¶
func (s *SwatchPicker) SetColor(c string)
SetColor sets the current color (hex). Call this when you receive ColorChosenMsg.
func (*SwatchPicker) SetFocused ¶
func (s *SwatchPicker) SetFocused(f bool)
SetFocused sets whether the swatch is focused (e.g. for keyboard-only navigation). When true, the picker arrow (▼) is rendered in a brighter color.
func (*SwatchPicker) SetPickerOptions ¶ added in v0.1.1
func (s *SwatchPicker) SetPickerOptions(opts ...Option)
SetPickerOptions configures extra bubblepicker.New options used whenever the modal opens. WithInitialColor is always applied from the swatch's current color first; these append after it. Typical use: WithPresets, WithAutoDismiss.
func (*SwatchPicker) SetZoneManager ¶
func (s *SwatchPicker) SetZoneManager(zm *zone.Manager)
SetZoneManager sets the zone manager for the picker. When set, the picker uses zone-based mouse interaction (click hue bar / grid / Accept) and receives raw screen mouse events; the host must run zone.Scan() on the view that contains the overlay.
func (*SwatchPicker) Size ¶
func (s *SwatchPicker) Size() (width, height int)
Size returns the display size (width, height in cells) of the swatch: 2 wide (color + symbol), 1 high. Use this when building your layout and when calling SetBounds.
func (*SwatchPicker) SwatchView ¶
func (s *SwatchPicker) SwatchView() string
SwatchView returns the swatch as a single line: one cell of color plus the picker symbol (▼). No border. When focused (e.g. for keyboard nav), the arrow is highlighted.
func (*SwatchPicker) Update ¶
func (s *SwatchPicker) Update(msg tea.Msg) (*SwatchPicker, tea.Cmd)
Update handles messages. Forward all tea.Msg to it. When the user picks a color, you'll receive ColorChosenMsg; call SetColor(msg.Color) and assign the returned model back. When the picker is open, Update forwards to the picker with the correct mouse offset.
func (*SwatchPicker) ViewWithOverlay ¶
func (s *SwatchPicker) ViewWithOverlay(mainView string, viewWidth, viewHeight int) string
ViewWithOverlay returns the view to display. If the picker is open, it overlays the modal on mainView. It stores overlay position and dimensions on the receiver so Update can use them for mouse offset—no need to reassign the return value.
return app.swatch.ViewWithOverlay(mainView, width, height)
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
modal
command
Modal example: picker appears as an overlay on top of the main view, centered on the color box you clicked or selected.
|
Modal example: picker appears as an overlay on top of the main view, centered on the color box you clicked or selected. |
|
simple
command
Simple example: the picker is the entire app.
|
Simple example: the picker is the entire app. |
|
swatch
command
Swatch example: 2×2 grid of color swatches that open the full modal picker on click.
|
Swatch example: 2×2 grid of color swatches that open the full modal picker on click. |


