view

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package view defines vigo's base view types: View (the visual primitive) and Group (a container of views that owns event dispatch and composition). Concrete views embed *View and override the methods they need.

Index

Constants

EventMaskDefault is the default class mask: keys, primary mouse transitions, commands, and broadcasts.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	*View

	Palette vio.Palette
	// contains filtered or unexported fields
}

Group is a View that owns a list of child views, dispatches events to them in three phases (pre-process, focused, post-process), and composes their drawing onto a Surface.

Groups carry an optional palette. Setting Palette on a group makes it the resolution point for any descendant View.MapColor lookup. In practice only Application sets a palette; intermediate groups leave it nil.

func NewGroup

func NewGroup(bounds vio.Rect) *Group

NewGroup returns a Group with the given bounds and no children.

func (*Group) ChangeBounds

func (g *Group) ChangeBounds(r vio.Rect)

ChangeBounds resizes the group and propagates the change to children based on each child's GrowMode. v0.1's behavior is the minimum needed for the demo: GrowAll children resize to fill the new bounds; GrowFixed children stay put. Per-edge growth flags are respected by adjusting the relevant edge.

func (*Group) Children

func (g *Group) Children() []Viewer

Children returns the current child list. The slice is shared with the group; callers must not modify it directly.

func (*Group) Current

func (g *Group) Current() Viewer

Current returns the focused child, or nil if no child is focused.

func (*Group) Draw

func (g *Group) Draw(s *vio.Surface)

Draw composes all visible children onto s, in insertion order. A concrete subclass that needs a back-to-front Z order should override this.

func (*Group) HandleEvent

func (g *Group) HandleEvent(e *event.Event)

HandleEvent dispatches e to children in three phases (pre, focused, post) and stops at the first child that consumes the event. Tab and Shift-Tab cycle focus through the selectable children when the focused child did not already consume them.

func (*Group) Insert

func (g *Group) Insert(v Viewer)

Insert appends a child to the group. If the group has no current child yet and the new child is selectable, the new child becomes the focused one.

func (*Group) Remove

func (g *Group) Remove(v Viewer)

Remove drops v from the group. If v was the current child, focus shifts to the next selectable child, or is cleared.

func (*Group) SetCurrent

func (g *Group) SetCurrent(i int)

SetCurrent sets the focused child to the one at index i. Pass -1 to clear focus. Out-of-range indices clear focus.

type GrowMode

type GrowMode uint8

GrowMode describes how a view's bounds change when its owner is resized. It mirrors Turbo Vision's gfXxx constants.

const (
	GrowLoX GrowMode = 1 << iota
	GrowLoY
	GrowHiX
	GrowHiY
)

GrowMode flags.

const (
	GrowFixed GrowMode = 0
	GrowAll            = GrowLoX | GrowLoY | GrowHiX | GrowHiY
)

GrowAll follows the parent in all four directions; GrowFixed sticks at the original bounds.

type Options

type Options uint16

Options is a bitmask of options that affect how the framework dispatches events to a view and how the view participates in its owning group.

const (
	OptSelectable Options = 1 << iota
	OptTopSelect
	OptFirstClick
	OptFramed
	OptPreProcess
	OptPostProcess
	OptBuffered
	OptTileable
	OptCenterX
	OptCenterY
)

Options flags.

type State

type State uint16

State is a bitmask of view state flags. The set roughly matches Borland Turbo Vision's sfXxx constants.

const (
	StateVisible State = 1 << iota
	StateCursorVis
	StateCursorIns
	StateShadow
	StateActive
	StateSelected
	StateFocused
	StateDragging
	StateDisabled
	StateModal
	StateDefault
	StateExposed
)

State flags.

type View

type View struct {
	Owner *Group

	Bounds vio.Rect
	Cursor vio.Point

	State    State
	Options  Options
	GrowMode GrowMode
	HelpCtx  uint16

	EventMask event.Class

	// PaletteIndex is the 1-based offset into the Application palette
	// that this view uses for its primary fill color. Sub-classes may
	// derive other colors by adding a small offset.
	PaletteIndex byte
}

View is the embed-friendly base of every visual primitive. It holds the state shared by all views (bounds, cursor, owner, options, state, palette index) and provides default no-op implementations of the Viewer methods.

func NewView

func NewView(bounds vio.Rect) *View

NewView returns a *View with the given bounds, the visible state set, and the default event mask.

func (*View) Base

func (v *View) Base() *View

Base satisfies Viewer; concrete views embed *View, so their Base returns the embedded view by default.

func (*View) ChangeBounds

func (v *View) ChangeBounds(r vio.Rect)

ChangeBounds replaces v.Bounds. Sub-classes that need to react to a resize (re-laying out children, for example) override this.

func (*View) Draw

func (v *View) Draw(s *vio.Surface)

Draw is the default drawing routine: fill the bounds with the view's primary palette color.

func (*View) HandleEvent

func (v *View) HandleEvent(e *event.Event)

HandleEvent is the default event handler: do nothing.

func (*View) HasState

func (v *View) HasState(bits State) bool

HasState reports whether all of the given state bits are set.

func (*View) MapColor

func (v *View) MapColor(idx byte) vio.Attr

MapColor walks up the owner chain to the nearest Group that has a palette, and translates idx through it. If no palette is found (orphan view, or no Application above), it falls back to the Borland classic palette so something visible still gets drawn.

func (*View) SetState

func (v *View) SetState(bits State, on bool)

SetState sets or clears state bits.

type Viewer

type Viewer interface {
	Base() *View
	Draw(s *vio.Surface)
	HandleEvent(e *event.Event)
	ChangeBounds(r vio.Rect)
}

Viewer is the interface every view satisfies. Concrete views embed *View, which provides default implementations, and override the methods they need.

Jump to

Keyboard shortcuts

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