Documentation
¶
Overview ¶
Package splitview provides a resizable split panel container widget with a draggable divider separating two child panels.
Construction uses functional options for immutable configuration:
split := splitview.New(
splitview.First(leftPanel),
splitview.Second(rightPanel),
splitview.OrientationOpt(splitview.Horizontal),
splitview.InitialRatio(0.3),
splitview.MinFirst(200),
)
Orientation ¶
Two orientations are available:
- Horizontal (default) -- first panel on the left, second on the right
- Vertical -- first panel on top, second on the bottom
Divider ¶
A draggable divider separates the two panels. The user can drag the divider to resize the panels. The divider width is configurable via DividerWidth. When the mouse hovers over the divider, the cursor changes to a resize cursor.
Collapse ¶
When CollapsibleOpt is enabled, double-clicking the divider collapses the first panel. Double-clicking again restores it to the previous ratio.
Constraints ¶
Minimum sizes for each panel can be set via MinFirst and MinSecond. The divider will stop at these limits during drag operations.
Visual Style ¶
The divider rendering is provided by a Painter implementation. Each design system (Material 3, Fluent, Cupertino) can supply its own painter to render the divider in the appropriate visual style.
If no painter is set, DefaultPainter is used, which draws a minimal divider suitable for testing and prototyping.
Signal Binding ¶
The split ratio can be bound to a reactive signal from the state package. When a signal value changes, the split ratio automatically reflects the new state:
- RatioSignal -- TWO-WAY binding for the split ratio
- RatioReadonlySignal -- read-only binding for the split ratio
Example:
ratio := state.NewSignal[float32](0.5)
split := splitview.New(
splitview.First(leftPanel),
splitview.Second(rightPanel),
splitview.RatioSignal(ratio),
splitview.OnRatioChange(func(r float32) {
fmt.Printf("ratio: %.2f\n", r)
}),
)
Focus ¶
SplitView does not participate in tab focus itself. Focus events are dispatched to the child panels directly.
Index ¶
- type DefaultPainter
- type DividerColorScheme
- type Option
- func CollapsibleOpt(v bool) Option
- func ColorSchemeOpt(cs DividerColorScheme) Option
- func DividerWidth(w float32) Option
- func First(w widget.Widget) Option
- func FixedFirst(px float32) Option
- func InitialRatio(r float32) Option
- func MinFirst(px float32) Option
- func MinSecond(px float32) Option
- func OnRatioChange(fn func(float32)) Option
- func OrientationOpt(o Orientation) Option
- func PainterOpt(p Painter) Option
- func RatioReadonlySignal(sig state.ReadonlySignal[float32]) Option
- func RatioSignal(sig state.Signal[float32]) Option
- func Second(w widget.Widget) Option
- type Orientation
- type PaintState
- type Painter
- type Widget
- 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) FirstPanel() widget.Widget
- func (w *Widget) IsCollapsed() bool
- func (w *Widget) Layout(ctx widget.Context, constraints geometry.Constraints) geometry.Size
- func (w *Widget) Mount(ctx widget.Context)
- func (w *Widget) Ratio() float32
- func (w *Widget) SecondPanel() widget.Widget
- func (w *Widget) Unmount()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultPainter ¶
type DefaultPainter struct{}
DefaultPainter provides a minimal fallback painter with no design system styling. It draws a simple divider line with a center handle indicator.
func (DefaultPainter) PaintDivider ¶
func (p DefaultPainter) PaintDivider(canvas widget.Canvas, ps PaintState)
PaintDivider renders a minimal divider with a center handle.
type DividerColorScheme ¶
type DividerColorScheme struct {
Divider widget.Color // divider background
DividerHover widget.Color // divider background when hovered
DividerDrag widget.Color // divider background when dragging
Handle widget.Color // center handle indicator
}
DividerColorScheme provides theme-derived colors for divider painting. Zero value means the painter should use its built-in defaults.
type Option ¶
type Option func(*config)
Option configures a split view during construction.
func CollapsibleOpt ¶
CollapsibleOpt enables double-click-to-collapse on the divider. When enabled, double-clicking the divider collapses the first panel. Double-clicking again restores it to the previous ratio.
func ColorSchemeOpt ¶
func ColorSchemeOpt(cs DividerColorScheme) Option
ColorSchemeOpt sets the theme-derived color scheme for the divider.
func DividerWidth ¶
DividerWidth sets the divider thickness in pixels. Default is 6 pixels.
func FixedFirst ¶ added in v0.1.4
FixedFirst sets a fixed pixel size for the first panel. Unlike ratio-based sizing, this keeps the first panel at a constant pixel width (horizontal) or height (vertical) regardless of window size. The second panel fills the remaining space. Set to 0 (default) to use ratio-based sizing.
func InitialRatio ¶
InitialRatio sets the initial split ratio (0.0 to 1.0). A ratio of 0.3 means the first panel takes 30% of the available space. Default is 0.5.
func OnRatioChange ¶
OnRatioChange sets the callback invoked when the split ratio changes.
func OrientationOpt ¶
func OrientationOpt(o Orientation) Option
OrientationOpt sets the split orientation. Default is Horizontal.
func PainterOpt ¶
PainterOpt sets the painter used to render the divider. Each design system provides its own painter. If not set, DefaultPainter is used.
func RatioReadonlySignal ¶
func RatioReadonlySignal(sig state.ReadonlySignal[float32]) Option
RatioReadonlySignal binds the split ratio to a read-only signal. When set, this takes highest precedence over all other ratio sources.
func RatioSignal ¶
RatioSignal binds the split ratio to a reactive signal. This is a TWO-WAY binding: the widget reads the ratio from the signal, and when the user drags the divider, the new ratio is written back.
type Orientation ¶
type Orientation uint8
Orientation controls how the two panels are arranged.
const ( // Horizontal arranges panels left (first) and right (second). Horizontal Orientation = iota // Vertical arranges panels top (first) and bottom (second). Vertical )
Orientation constants.
func (Orientation) String ¶
func (o Orientation) String() string
String returns a human-readable name for the orientation.
type PaintState ¶
type PaintState struct {
// DividerRect is the bounding rectangle of the divider area.
DividerRect geometry.Rect
// Orientation is the split orientation (Horizontal or Vertical).
Orientation Orientation
// Hovered indicates that the mouse is over the divider.
Hovered bool
// Dragging indicates that the divider is currently being dragged.
Dragging bool
// Collapsed indicates that the first panel is collapsed.
Collapsed bool
// ColorScheme provides theme-derived colors for divider painting.
// Zero value means the painter should use its built-in defaults.
ColorScheme DividerColorScheme
}
PaintState provides the current divider state to the painter.
type Painter ¶
type Painter interface {
PaintDivider(canvas widget.Canvas, state PaintState)
}
Painter draws the visual representation of the split view divider. Each design system (Material 3, Fluent, Cupertino) provides its own Painter implementation to render the divider in its visual style.
If no Painter is set, the split view uses DefaultPainter.
type Widget ¶
type Widget struct {
widget.WidgetBase
// contains filtered or unexported fields
}
Widget implements a resizable split panel container with a draggable divider.
A split view is created with New using functional options:
split := splitview.New(
splitview.First(leftPanel),
splitview.Second(rightPanel),
splitview.OrientationOpt(splitview.Horizontal),
splitview.InitialRatio(0.3),
)
func New ¶
New creates a new split view Widget with the given options.
The returned widget is visible and enabled by default. The default orientation is Horizontal with a 50/50 split.
func (*Widget) Event ¶
Event handles input events for divider dragging.
Mouse and wheel event positions are translated from parent-local space to SplitView-local space before hit-testing and child dispatch, matching the coordinate convention used by [primitives.BoxWidget].
func (*Widget) FirstPanel ¶
FirstPanel returns the first panel widget.
func (*Widget) IsCollapsed ¶
IsCollapsed reports whether the first panel is currently collapsed.
func (*Widget) Mount ¶
Mount creates signal bindings for push-based invalidation. Implements widget.Lifecycle.
func (*Widget) SecondPanel ¶
SecondPanel returns the second panel widget.
func (*Widget) Unmount ¶
func (w *Widget) Unmount()
Unmount is called when the split view is removed from the widget tree. Implements widget.Lifecycle.