Documentation
¶
Index ¶
- type GutterClickEvent
- type GutterColors
- type GutterContext
- type GutterEvent
- type GutterHoverEvent
- type GutterProvider
- type HoverInfo
- type InteractiveGutter
- type LineHighlight
- type LineHighlighter
- type Manager
- func (m *Manager) CalculateWidth(gtx layout.Context, shaper *text.Shaper, params text.Parameters, lineCount int) int
- func (m *Manager) CollectHighlights() []LineHighlight
- func (m *Manager) GetProvider(id string) GutterProvider
- func (m *Manager) HasProviders() bool
- func (m *Manager) Layout(gtx layout.Context, ctx GutterContext) layout.Dimensions
- func (m *Manager) Providers() []GutterProvider
- func (m *Manager) Register(provider GutterProvider)
- func (m *Manager) SetGap(gap unit.Dp)
- func (m *Manager) TotalWidth() int
- func (m *Manager) Unregister(id string)
- func (m *Manager) Update(gtx layout.Context) (GutterEvent, bool)
- type Paragraph
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GutterClickEvent ¶
type GutterClickEvent struct {
// ProviderID is the ID of the provider that was clicked.
ProviderID string
// Line is the 0-based line number that was clicked.
Line int
// Source indicates the pointer source (mouse, touch, etc.).
Source pointer.Source
// NumClicks is the number of successive clicks.
NumClicks int
// Modifiers indicates which modifier keys were held.
Modifiers key.Modifiers
}
GutterClickEvent is emitted when a user clicks on a gutter area.
type GutterColors ¶
type GutterColors struct {
// Text is the default text color for gutter content.
Text gvcolor.Color
// TextHighlight is the text color for highlighted content (e.g., current line number).
TextHighlight gvcolor.Color
// Background is the background color for the gutter area.
Background gvcolor.Color
// LineHighlight is the color used to highlight the current line background.
LineHighlight gvcolor.Color
// Custom contains provider-specific colors, keyed by provider ID or custom name.
Custom map[string]gvcolor.Color
}
GutterColors defines the color scheme for gutter rendering.
type GutterContext ¶
type GutterContext struct {
// Shaper is the text shaper used for rendering text.
Shaper *text.Shaper
// TextParams contains the text parameters for shaping.
TextParams text.Parameters
// Viewport is the visible area in document coordinates.
Viewport image.Rectangle
// Paragraphs contains metadata for visible lines.
Paragraphs []Paragraph
// CurrentLine is the line number where the caret is located.
// It is -1 if the selection spans multiple lines.
CurrentLine int
// LineHeight is the calculated line height in fixed-point format.
LineHeight fixed.Int26_6
// Colors provides the color scheme for gutter rendering.
Colors *GutterColors
}
GutterContext provides the context needed for gutter providers to render their content. It includes information about the visible area, line metadata, and colors.
type GutterEvent ¶
type GutterEvent interface {
// contains filtered or unexported methods
}
GutterEvent is the base interface for all gutter-related events.
type GutterHoverEvent ¶
type GutterHoverEvent struct {
// ProviderID is the ID of the provider being hovered.
ProviderID string
// Line is the 0-based line number being hovered.
Line int
// Info contains the hover information provided by the provider.
Info *HoverInfo
}
GutterHoverEvent is emitted when a user hovers over a gutter area.
type GutterProvider ¶
type GutterProvider interface {
// ID returns a unique identifier for this provider.
ID() string
// Priority determines the rendering order. Lower values are rendered
// closer to the text area (rightmost in the gutter).
Priority() int
// Width returns the width needed by this provider for the given context.
// The lineCount parameter indicates the total number of lines in the document,
// which can be used to calculate width (e.g., for line numbers).
Width(gtx layout.Context, shaper *text.Shaper, params text.Parameters, lineCount int) unit.Dp
// Layout renders the gutter content for the visible lines.
Layout(gtx layout.Context, ctx GutterContext) layout.Dimensions
}
GutterProvider defines the interface for components that render content in the gutter area of the editor. Providers are rendered left-to-right sorted by their priority (lower priority = closer to text).
type HoverInfo ¶
type HoverInfo struct {
// Text is a simple text description to show in a tooltip.
Text string
// Widget is an optional custom widget to render for the hover effect.
// If provided, it takes precedence over Text.
Widget layout.Widget
}
HoverInfo contains information about a hover effect to display.
type InteractiveGutter ¶
type InteractiveGutter interface {
GutterProvider
// HandleClick is called when the user clicks on this provider's area.
// It receives the line number that was clicked, the pointer source (mouse/touch),
// the number of clicks, and active key modifiers.
// Returns true if the event was handled.
HandleClick(line int, source pointer.Source, numClicks int, modifiers key.Modifiers) bool
// HandleHover is called when the user hovers over this provider's area.
// It receives the line number being hovered and returns hover information,
// or nil if no hover effect should be shown.
HandleHover(line int) *HoverInfo
}
InteractiveGutter extends GutterProvider with interaction capabilities. Providers implementing this interface can respond to mouse clicks and hovers.
type LineHighlight ¶
type LineHighlight struct {
// Line is the 0-based line index to highlight.
Line int
// Color is the background color for the highlight.
Color gvcolor.Color
}
LineHighlight specifies a line to be highlighted with a background color.
type LineHighlighter ¶
type LineHighlighter interface {
// HighlightedLines returns the lines that should be highlighted.
// This is called after Layout to collect highlights from all providers.
HighlightedLines() []LineHighlight
}
LineHighlighter is an optional interface that GutterProviders can implement to specify lines that should be highlighted with a background color. The Editor will paint these highlights spanning the full editor width.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates multiple gutter providers, handling layout, event processing, and hit testing.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new gutter manager with default settings.
func (*Manager) CalculateWidth ¶
func (m *Manager) CalculateWidth(gtx layout.Context, shaper *text.Shaper, params text.Parameters, lineCount int) int
CalculateWidth calculates the total width without rendering. Useful for layout calculations before actual rendering.
func (*Manager) CollectHighlights ¶
func (m *Manager) CollectHighlights() []LineHighlight
CollectHighlights gathers line highlights from all providers that implement the LineHighlighter interface. The returned highlights should be painted as full-width backgrounds by the Editor.
func (*Manager) GetProvider ¶
func (m *Manager) GetProvider(id string) GutterProvider
GetProvider returns a provider by its ID, or nil if not found.
func (*Manager) HasProviders ¶
HasProviders returns true if there are any registered providers.
func (*Manager) Layout ¶
func (m *Manager) Layout(gtx layout.Context, ctx GutterContext) layout.Dimensions
Layout renders all gutter providers and returns the total dimensions.
func (*Manager) Providers ¶
func (m *Manager) Providers() []GutterProvider
Providers returns a slice of all registered providers.
func (*Manager) Register ¶
func (m *Manager) Register(provider GutterProvider)
Register adds a provider to the manager. Providers are automatically sorted by priority (lower priority = rendered closer to text).
func (*Manager) TotalWidth ¶
TotalWidth returns the total width of all gutter columns including gaps.
func (*Manager) Unregister ¶
Unregister removes a provider by its ID.
type Paragraph ¶
type Paragraph struct {
// StartY is the baseline Y coordinate of the first screen line in the paragraph.
StartY int
// EndY is the baseline Y coordinate of the last screen line in the paragraph.
EndY int
// Ascent is the distance from baseline to the top of glyphs.
Ascent fixed.Int26_6
// Descent is the distance from baseline to the bottom of glyphs.
Descent fixed.Int26_6
// Runes is the number of runes in this paragraph.
Runes int
// RuneOff is the rune offset of the first rune in this paragraph.
RuneOff int
// Index is the 0-based line number of this paragraph.
Index int
}
Paragraph contains metadata about a paragraph (logical line) in the document.