camera

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package camera is a plane the user pans and zooms, such as a design canvas or a board of diagrams: the app lays its content out at its own size on the plane, and the view shows it through a camera that moves and scales it on the platform's frame clock. The view owns the camera and its gestures; what the content holds and what pressing it means stay the app's. Content receives input where the camera draws it; the app also hears presses on the plane at points of the content.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type State

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

State is a camera: it keeps where it is between mounts and moves the camera of the view showing it. Its zero value is ready to use; keep one per plane. Its methods run on the UI's goroutine; those moving the camera do nothing while no view shows it.

func (*State) Camera

func (s *State) Camera() (x, y, zoom float64)

Camera returns where the camera puts the content's origin in the view and its scale, where it is going, which a caller reading it follows while a view shows it.

func (*State) Center

func (s *State) Center(b core.Bounds)

Center pans to center a part of the content, in its coordinates, at the zoom shown, and Reveal does unless it shows whole already.

func (*State) Fit

func (s *State) Fit()

Fit shows the whole content centered, no larger than its size, and keeps it fitted as it and the view change size until the user moves the camera.

func (*State) FitBounds

func (s *State) FitBounds(b core.Bounds)

FitBounds shows a part of the content, in its coordinates, centered and no larger than its size, as the user moving there would.

func (*State) Moved

func (s *State) Moved() bool

Moved says the user moved the camera since the content was last fitted.

func (*State) Reveal

func (s *State) Reveal(b core.Bounds)

func (*State) ToContent

func (s *State) ToContent(p core.Point) core.Point

func (*State) ToView

func (s *State) ToView(p core.Point) core.Point

ToView is the point of the view showing a point of the content, where the camera is going, and ToContent the point of the content under a point of the view.

func (*State) Zoom

func (s *State) Zoom() float64

Zoom is the camera's scale, where it is going, which a caller reading it follows, such as to keep a mark's size on screen at any zoom.

func (*State) ZoomIn

func (s *State) ZoomIn()

ZoomIn and ZoomOut scale the view around its center.

func (*State) ZoomOut

func (s *State) ZoomOut()

type View

type View struct {
	Content core.Node
	// State holds the camera between mounts and moves it; nil keeps one of
	// the view's own.
	State *State
	// OnPress hears a press on the plane at a point of the content, and
	// says it took it. OnHover hears the pointer move over the plane at a
	// point of the content, unless a button is down, and over false as it
	// leaves.
	OnPress func(at core.Point, e core.PressEvent) bool
	OnHover func(at core.Point, over bool)
	// Cursor is the pointer's look over the plane while it does not pan,
	// the grab hand when nil or CursorAuto.
	Cursor func() core.Cursor
	// Children sit over the plane, unmoved by the camera, such as its
	// tools, and take the pointer before it.
	Children []core.Node
	// MinZoom and MaxZoom bound the zoom, .1 and 4 when 0; FitMargin keeps
	// what a fit shows from the view's edges, 32 points when 0.
	MinZoom, MaxZoom float64
	FitMargin        core.Points
	// Label describes the plane for assistive technology. TestID names
	// the plane, and with -pointer after it the layer taking the pointer.
	Label     string
	LabelFunc func() string
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	TestID    string
}

View is the plane: it fills what the app sizes, lays Content out at its own size with its top left corner at the plane's origin, and shows the whole of it centered, no larger than its size, until the user pans or zooms. Drag to pan, scroll with two fingers on a touchpad to pan, turn the wheel or pinch to zoom around the pointer, and double-click to zoom in, or out with Shift, where OnPress takes no press.

func (View) Render

func (spec View) Render(cx *core.Scope) core.Node

Render implements core.Node.

Jump to

Keyboard shortcuts

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