modal

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DraggableWidget

type DraggableWidget struct {
	ID     string
	Title  string
	Widget widgetapi.Widget

	X int
	Y int

	Width  int
	Height int

	ZIndex int
	Border bool

	Minimizable bool
	// contains filtered or unexported fields
}

DraggableWidget is a widget that can be repositioned with the mouse.

func NewDraggableWidget

func NewDraggableWidget(id string, widget widgetapi.Widget, x, y, width, height int, opts *Options) *DraggableWidget

NewDraggableWidget creates a draggable child widget configured for the modal.

func (*DraggableWidget) HandleMouse

func (dw *DraggableWidget) HandleMouse(event *terminalapi.Mouse, maxZIndexFunc func() int, canvasWidth, canvasHeight int, modal *Modal) bool

HandleMouse updates drag state and position for the draggable widget.

type EventHandler

type EventHandler struct {
	// contains filtered or unexported fields
}

EventHandler routes mouse and keyboard events used by the modal demo.

func NewEventHandler

func NewEventHandler(ctx context.Context, cancel context.CancelFunc, rootContainer *container.Container, modalManager *Manager) *EventHandler

NewEventHandler creates an event handler for a modal manager and root container.

func (*EventHandler) HandleKeyboard

func (eh *EventHandler) HandleKeyboard(k *terminalapi.Keyboard)

HandleKeyboard closes the active modal on Escape and quits on q, Q, or Ctrl+C.

func (*EventHandler) HandleMouse

func (eh *EventHandler) HandleMouse(event *terminalapi.Mouse)

HandleMouse intentionally ignores mouse events.

Modal widgets receive mouse input through the standard termdash widget event path, which provides coordinates relative to the modal canvas. Forwarding raw terminal mouse events from the demo would bypass that translation and make dragging inaccurate.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager tracks the currently visible modal.

func (*Manager) HandleMouse

func (mm *Manager) HandleMouse(event *terminalapi.Mouse) bool

HandleMouse forwards a mouse event to the active modal.

func (*Manager) HasActiveModal

func (mm *Manager) HasActiveModal() bool

HasActiveModal reports whether a modal is currently visible.

func (*Manager) HideModal

func (mm *Manager) HideModal(c *container.Container) error

HideModal removes the active modal from its host container.

func (*Manager) ShowModal

func (mm *Manager) ShowModal(modal *Modal, c *container.Container) error

ShowModal places the modal into the container whose ID matches modal.ID.

type Modal struct {
	// ID identifies the container that hosts the modal.
	ID string

	// DraggableItems holds the widgets drawn inside the modal.
	DraggableItems []*DraggableWidget

	// Opts holds the modal configuration.
	Opts *Options
	// contains filtered or unexported fields
}

Modal renders and manages a set of draggable child widgets.

func NewModal

func NewModal(id string, items []*DraggableWidget, opts *Options) *Modal

NewModal creates a modal widget.

func (*Modal) Draw

func (m *Modal) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw renders the draggable child widgets into the provided canvas.

func (*Modal) HandleMouse

func (m *Modal) HandleMouse(event *terminalapi.Mouse)

HandleMouse updates the top-most matching draggable widget.

func (*Modal) Keyboard

func (m *Modal) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard implements widgetapi.Widget.Keyboard.

func (*Modal) Mouse

func (m *Modal) Mouse(event *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse implements widgetapi.Widget.Mouse.

func (*Modal) Options

func (m *Modal) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*Modal) SetDirty

func (m *Modal) SetDirty(dirty bool)

SetDirty marks the modal for redraw.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures modal widget options.

func Border

func Border(border bool) Option

Border sets whether draggable items should draw rounded borders.

func DockGap

func DockGap(gap int) Option

DockGap sets the spacing used between minimized windows in the bottom dock.

func EnableLogging deprecated

func EnableLogging(enable bool) Option

EnableLogging is retained as a compatibility no-op.

Deprecated: modal logging has been removed. This option has no effect.

func LogPrefix deprecated

func LogPrefix(prefix string) Option

LogPrefix is retained as a compatibility no-op.

Deprecated: modal logging has been removed. This option has no effect.

func MinimizeGlyphs

func MinimizeGlyphs(minimize, restore rune) Option

MinimizeGlyphs sets the glyphs used for minimize and restore controls.

func MinimumSize

func MinimumSize(size image.Point) Option

MinimumSize sets the minimum canvas size requested by the modal widget.

func TitleBarCellOpts

func TitleBarCellOpts(opts ...cell.Option) Option

TitleBarCellOpts sets the cell styling used for the title bar background.

func TitleCellOpts

func TitleCellOpts(opts ...cell.Option) Option

TitleCellOpts sets the cell styling used for the window title text.

func TitleControlCellOpts

func TitleControlCellOpts(opts ...cell.Option) Option

TitleControlCellOpts sets the cell styling used for title bar control glyphs.

type Options

type Options struct {
	// Border controls whether draggable items draw a rounded border.
	Border bool

	// MinimumSize is the smallest canvas that the modal will request.
	MinimumSize image.Point

	// TitleBarCellOpts styles the draggable window title bar background.
	TitleBarCellOpts []cell.Option

	// TitleCellOpts styles the draggable window title text.
	TitleCellOpts []cell.Option

	// TitleControlCellOpts styles the title-bar control glyphs.
	TitleControlCellOpts []cell.Option

	// MinimizeGlyph is drawn in the title bar while the window is expanded.
	MinimizeGlyph rune

	// RestoreGlyph is drawn in the title bar while the window is minimized.
	RestoreGlyph rune

	// DockGap is the spacing used between minimized windows in the bottom dock.
	DockGap int
}

Options holds modal configuration.

func NewOptions

func NewOptions(opts ...Option) *Options

NewOptions creates an Options value with the provided options applied.

Directories

Path Synopsis
Binary modaldemo shows draggable widgets hosted inside a modal.
Binary modaldemo shows draggable widgets hosted inside a modal.

Jump to

Keyboard shortcuts

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