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 ¶
- type State
- func (s *State) Camera() (x, y, zoom float64)
- func (s *State) Center(b core.Bounds)
- func (s *State) Fit()
- func (s *State) FitBounds(b core.Bounds)
- func (s *State) Moved() bool
- func (s *State) Reveal(b core.Bounds)
- func (s *State) ToContent(p core.Point) core.Point
- func (s *State) ToView(p core.Point) core.Point
- func (s *State) Zoom() float64
- func (s *State) ZoomIn()
- func (s *State) ZoomOut()
- type View
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 ¶
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 ¶
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 ¶
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) ToView ¶
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 ¶
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.
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.