{"modulePath":"github.com/weakpixel/engine","version":"v0.0.0-20261205071607-94fff0387040","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package toolshell\n\nPackage toolshell is the shell the wpix-editor tools run on: a [game.Tool](/github.com/weakpixel/engine/game#Tool) on an engine with no game systems, so assets load through the engine's asset server and the content is drawn by the engine's renderer. The shell owns the viewport (pan, zoom, grid), the tool's [Panel](#Panel) and, for document tools, the document.\n\nA tool describes its panel as data ([Panel](#Panel)) and never draws widgets itself. Two renderers show the same description: the debugui renderer of package debugpanel in the native window, and the VSCode extension, which receives the panel as JSON over the tool protocol (see protocol.go) and draws HTML inputs. Document tools edit text through [Document](#Document): a file on disk with its own undo natively, the host's document in VSCode.\n\nThe package imports neither debugui nor the editor host, so the wasm build needs no go.sum entries beyond the engine's. See doc/design/tool-shell.md#tools.\n\n## Constants\n\n```go\nconst (\n\tAssetImage  = \"image\"\n\tAssetShader = \"shader\"\n)\n```\nThe kinds of an asset field.\n\n## Variables\n\n```go\nvar ErrNoDocument = errors.New(\"nothing to edit: no valid document yet\")\n```\nErrNoDocument is returned by an edit before the first valid document arrived.\n\n```go\nvar ErrReadOnly = errors.New(\"the file is shown read-only\")\n```\nErrReadOnly is returned by every edit of a file the tool shows but does not write. A tool may return its own error that wraps it (errors.Is matches).\n\n```go\nvar ErrStale = errors.New(\"the document has errors: fix it in the text editor first\")\n```\nErrStale is returned by every edit while the document cannot be parsed: the tool keeps showing the last good version and never writes over the user's broken text.\n\n## Functions\n\n```go\nfunc CoarseStep(step float32) float32\n```\nCoarseStep returns step (window pixels) times 8 as often as needed to reach 4 pixels, so a zoomed-out view (a whole world) still shows a grid: every eighth line, then every 64th, and so on. The lines stay on the multiples of the cell. A step of 0 or less is returned unchanged.\n\n```go\nfunc FrameRect(cam *render.Camera, r gfx.Rect, screen image.Point, free image.Rectangle)\n```\nFrameRect centers r in the area free of the screen (logical pixels) and zooms so that r fills most of it; an empty r only centers. An empty free is the camera's whole viewport. The panels of the native window are overlays, so the camera keeps drawing the whole viewport and free is the part between them. The zoom stays within 1/16 and 64.\n\n```go\nfunc PanTo(cam *render.Camera, prev, cur gfx.Vec2, screen image.Point)\n```\nPanTo moves cam so that the world point under the screen point prev is under cur.\n\n```go\nfunc ZoomAt(cam *render.Camera, cur gfx.Vec2, screen image.Point, steps float32)\n```\nZoomAt zooms cam at once by steps wheel notches around the screen point cur (the world point under the cursor stays under it). The zoom stays within 1/16 and 64. The wheel itself eases instead, see [camzoom](/github.com/weakpixel/engine/editor/camzoom).\n\n## Types\n\n```go\ntype Checker interface {\n\t// Check reports whether the tool can open the file at asset key key.\n\tCheck(key string) error\n}\n```\nChecker is an optional interface of a [Tool](#Tool): the native command calls Check before it opens a window, so a file the tool cannot open is an error on the command line instead of a window with a status line.\n\n```go\ntype Closer interface {\n\t// Close removes what Open spawned and releases what it loaded.\n\tClose(s *Shell)\n}\n```\nCloser is an optional interface of a [Tool](#Tool) without a document: it can switch files in place. On the host's open message the shell calls Close, then Open with the new key, and sends ready again, so the page keeps its game and needs no reload. The view settings (grid, background) stay.\n\n```go\ntype Config struct {\n\t// Name is the tool's name (\"view\"), sent in the ready message.\n\tName string\n\t// Tool is the tool to run.\n\tTool Tool\n\t// Key is the asset key of the file the tool opens.\n\tKey string\n\t// FS is the asset filesystem the engine loads from, for tools that read\n\t// a file as raw bytes (the anim tool reads its sheet's JSON). Optional.\n\tFS fs.FS\n\t// Overlay is the in-memory part of FS, when FS is an [OverlayFS]. Tools\n\t// serve generated assets through [Shell.Overlay]. Optional.\n\tOverlay *OverlayFS\n\t// Document is the backend of a [DocumentTool]'s file; nil for other\n\t// tools. A [FileDocument] is loaded into the tool on the first tick; a\n\t// [HostDocument] waits for the host's document message.\n\tDocument Document\n\t// Files lists the asset keys of every file in the asset root, for hosts\n\t// whose filesystem cannot list directories (the page build). Tools that\n\t// list assets use it when set and walk FS otherwise. Optional.\n\tFiles []string\n\t// Root is the asset root as a directory of the host's filesystem, where\n\t// [Shell.Create] writes natively. Empty in the page build, where the\n\t// host writes.\n\tRoot string\n\t// Transport carries the tool protocol to the host page; nil natively.\n\tTransport Transport\n\t// Inbox holds the host's messages; nil makes the shell create one. The\n\t// page hookup pushes into it before the shell exists.\n\tInbox *Inbox\n\t// Renderer draws the panel; nil in the VSCode build.\n\tRenderer Renderer\n\t// Now returns the time, for throttling panel updates and polling the\n\t// file; nil means time.Now. Tests set it.\n\tNow func() time.Time\n}\n```\nConfig configures a [Shell](#Shell).\n\n```go\ntype CreateFile struct {\n\tPath string\n\tData []byte\n}\n```\nCreateFile is a file [Shell.Create](#Shell.Create) writes: an asset key and its bytes.\n\n```go\ntype DocStatus struct {\n\t// Loaded says that a valid document was loaded at least once.\n\tLoaded bool\n\t// Stale is the parse error of the last text, \"\" while the shown file is\n\t// the document. The last good version stays shown.\n\tStale string\n\t// ReadOnly refuses every edit with [ErrReadOnly].\n\tReadOnly bool\n}\n```\nDocStatus is the state every document tool keeps besides its file: whether a valid version was loaded, the parse error of the last text and whether edits are refused. A tool embeds it (directly or through [Model](#Model)) so the three checks and their errors are the same everywhere.\n\n```go\nfunc (d *DocStatus) Editable() error\n```\nEditable reports why an edit is refused: [ErrReadOnly](#ErrReadOnly), [ErrStale](#ErrStale) or [ErrNoDocument](#ErrNoDocument), in that order; nil when it may go ahead.\n\n```go\nfunc (d *DocStatus) MarkStale(err error)\n```\nMarkStale keeps the shown version and notes that the document does not parse.\n\n```go\ntype Document interface {\n\t// Text returns the current text.\n\tText() []byte\n\t// Edit makes text the document's new version.\n\tEdit(text []byte) error\n}\n```\nDocument is the text document a [DocumentTool](#DocumentTool) edits. Tools hand it whole texts from the format's encoder (the shell never diffs); how the text is stored and undone depends on the backend: [FileDocument](#FileDocument) natively, [HostDocument](#HostDocument) in VSCode.\n\n```go\ntype DocumentTool interface {\n\tTool\n\t// Load takes a new document version: when the file is opened, changed\n\t// on disk, undone or redone, or sent by the host. The tool replaces its\n\t// state; it does not call [Shell.Edit] for it.\n\tLoad(text []byte) error\n}\n```\nDocumentTool is a [Tool](#Tool) whose file is a text document it edits.\n\n```go\ntype External int\n```\nExternal says what a check of the file found.\n\n```go\nconst (\n\t// ExternalNone means the file is as the document last saw it.\n\tExternalNone External = iota\n\t// ExternalReloaded means the file changed and the document had no\n\t// unsaved edits: it now holds the file's text (the undo stacks are\n\t// dropped) and the tool should load it.\n\tExternalReloaded\n\t// ExternalConflict means the file changed while the document has\n\t// unsaved edits: nothing is loaded. The shell reports it in the panel.\n\tExternalConflict\n)\n```\n\n```go\ntype Field struct {\n\t// ID is unique in the panel; [Tool.Set] receives it.\n\tID    string `json:\"id\"`\n\tLabel string `json:\"label\"`\n\t// Widget is the kind of widget.\n\tWidget Widget `json:\"widget\"`\n\t// Value is the current value (see the Widget constants); none for a\n\t// button.\n\tValue json.RawMessage `json:\"value,omitempty\"`\n\t// Min, Max and Step bound and step a number. A renderer keeps what the\n\t// user types inside the bounds that are set; with both set it shows a\n\t// slider too. One bound alone (see [Field.AtLeast]) limits the number\n\t// without a slider.\n\tMin  *float64 `json:\"min,omitempty\"`\n\tMax  *float64 `json:\"max,omitempty\"`\n\tStep *float64 `json:\"step,omitempty\"`\n\t// Digits is the decimals a number shows; 0 is an integer and Set\n\t// receives an integer.\n\tDigits int `json:\"digits,omitempty\"`\n\t// Options are the entries of a dropdown, or the candidate asset keys of\n\t// an asset field.\n\tOptions []string `json:\"options,omitempty\"`\n\t// Kind is the kind of an asset field: [AssetImage] or [AssetShader].\n\tKind string `json:\"kind,omitempty\"`\n\t// Thumbs maps an asset key to a PNG data URI for the entries of an asset\n\t// field that are not files the page can fetch (built-in sprites).\n\tThumbs map[string]string `json:\"thumbs,omitempty\"`\n\t// Readonly shows the widget but does not let the user change it.\n\tReadonly bool `json:\"readonly,omitempty\"`\n\t// Hint is a tooltip.\n\tHint string `json:\"hint,omitempty\"`\n\t// List, on a dropdown, asks a renderer to draw the options as a\n\t// scrollable list of this many rows instead of a drop-down (see\n\t// [Field.AsList]). The value and Set stay the dropdown's: the option\n\t// index. A renderer that has no list shows a dropdown.\n\tList int `json:\"list,omitempty\"`\n}\n```\nField is one widget of a [Section](#Section).\n\n```go\nfunc Asset(id, label, kind, key string, options []string) Field\n```\nAsset returns an asset field of kind ([AssetImage](#AssetImage) or [AssetShader](#AssetShader)) with the key selected, \"\" for none, and the candidate keys.\n\n```go\nfunc Button(id, label string) Field\n```\nButton returns a button. Its Set value is null.\n\n```go\nfunc Checkbox(id, label string, v bool) Field\n```\nCheckbox returns a checkbox field.\n\n```go\nfunc Color(id, label, hex string) Field\n```\nColor returns a color field; hex is \"#rrggbbaa\".\n\n```go\nfunc Dropdown(id, label string, index int, options ...string) Field\n```\nDropdown returns a dropdown field with the option at index selected.\n\n```go\nfunc Label(id, label, text string) Field\n```\nLabel returns read-only text: label on the left, text on the right.\n\n```go\nfunc Number(id, label string, v float64) Field\n```\nNumber returns a number field with value v and step 1.\n\n```go\nfunc NumberRange(id, label string, lo, hi float64) Field\n```\nNumberRange returns a range field with the value \\[lo, hi] and step 1.\n\n```go\nfunc Text(id, label, v string) Field\n```\nText returns a text field.\n\n```go\nfunc (f Field) AsList(rows int) Field\n```\nAsList returns the dropdown f presented as a list showing rows options at a time. It panics when rows is below 1 (a programmer error); [Panel.Check](#Panel.Check) rejects a list on any other widget.\n\n```go\nfunc (f Field) AsReadonly() Field\n```\nAsReadonly returns f with Readonly set.\n\n```go\nfunc (f Field) AtLeast(lo float64) Field\n```\nAtLeast returns f with only a lower bound: no slider, but a renderer does not let the value go below lo.\n\n```go\nfunc (f Field) Range(lo, hi float64) Field\n```\nRange returns f with its bounds set, which makes a renderer show a slider.\n\n```go\nfunc (f Field) WithDigits(n int) Field\n```\nWithDigits returns f with the number of decimals shown set.\n\n```go\nfunc (f Field) WithHint(hint string) Field\n```\nWithHint returns f with its tooltip set.\n\n```go\nfunc (f Field) WithStep(step float64) Field\n```\nWithStep returns f with its step set.\n\n```go\nfunc (f Field) WithThumbs(thumbs map[string]string) Field\n```\nWithThumbs returns f with the thumbnails of its entries set.\n\n```go\ntype FileDocument struct {\n\t// contains filtered or unexported fields\n}\n```\nFileDocument is a document backed by a file on disk with its own undo stack: the native backend. Edit changes the text in memory (and can be undone); Save writes it.\n\n```go\nfunc NewFileDocument(path string, text []byte) *FileDocument\n```\nNewFileDocument returns a document for a file that does not exist yet, starting with text. It is dirty until Save creates the file.\n\n```go\nfunc OpenFileDocument(path string) (*FileDocument, error)\n```\nOpenFileDocument reads the file at path.\n\n```go\nfunc (d *FileDocument) AddPending(path string, data []byte)\n```\nAddPending adds a file the first Save writes before the document: a file the new document names (the sprite a new effect uses). path is a file path, as the document's. A later Save does not write it again.\n\n```go\nfunc (d *FileDocument) CheckDisk() (External, error)\n```\nCheckDisk compares the file with what the document last read or wrote.\n\n```go\nfunc (d *FileDocument) Dirty() bool\n```\nDirty reports whether the text differs from the file's.\n\n```go\nfunc (u *FileDocument) Edit(text []byte) error\n```\nEdit makes text the current version: the old text goes on the undo stack and the redo stack is dropped. An edit that changes nothing is ignored.\n\n```go\nfunc (d *FileDocument) Path() string\n```\nPath returns the file's path.\n\n```go\nfunc (u *FileDocument) Redo() bool\n```\nRedo undoes an Undo. It reports false when there is nothing to redo.\n\n```go\nfunc (d *FileDocument) Save() error\n```\nSave writes the pending files, then the text to the file.\n\n```go\nfunc (u *FileDocument) Text() []byte\n```\nText returns the current text.\n\n```go\nfunc (u *FileDocument) Undo() bool\n```\nUndo returns to the previous text. It reports false when there is none.\n\n```go\ntype Grid struct {\n\tOn bool\n\t// Cell is the cell size in world units.\n\tCell float32\n\t// OffsetX and OffsetY shift the lines, in world units.\n\tOffsetX, OffsetY float32\n}\n```\nGrid is the grid drawn over the viewport. The lines are the multiples of Cell in world units, shifted by Offset.\n\n```go\ntype GridLine struct {\n\t// At is the line's position in window pixels along the axis.\n\tAt float32\n\t// Major is set for every eighth line, counted from the grid origin.\n\tMajor bool\n}\n```\nGridLine is one line of a grid along one axis.\n\n```go\nfunc GridLines(origin, step, length float32) []GridLine\n```\nGridLines returns the lines of a grid along one axis that fall inside 0..length (window pixels). origin is the window position of line 0 and step the distance between lines in window pixels. It returns nil when step is below 4 pixels, since a denser grid would only be noise.\n\n```go\ntype HostDocument struct {\n\t// contains filtered or unexported fields\n}\n```\nHostDocument is the document of the host page (VSCode): the extension owns the text and its undo. Edit sends an edit message; the host answers with a document message, which [HostDocument.Receive](#HostDocument.Receive) filters for the echo of the last edit.\n\n```go\nfunc NewHostDocument(t Transport) *HostDocument\n```\nNewHostDocument returns a document that sends its edits over t.\n\n```go\nfunc (d *HostDocument) Edit(text []byte) error\n```\nEdit implements [Document](#Document): it sends the text to the host.\n\n```go\nfunc (d *HostDocument) Receive(text []byte) (load bool)\n```\nReceive takes a text the host sent. It reports whether the tool should load it: false for the echo of the last Edit, which the tool made itself.\n\n```go\nfunc (d *HostDocument) Text() []byte\n```\nText implements [Document](#Document): the last text the host sent or the tool made.\n\n```go\ntype Inbox struct {\n\t// contains filtered or unexported fields\n}\n```\nInbox queues the messages from the host until the next tick. It is safe for concurrent use: a JavaScript callback pushes, the shell drains on the game goroutine.\n\n```go\nfunc (b *Inbox) Push(msg []byte)\n```\nPush queues one message. It copies msg.\n\n```go\ntype Initializer interface {\n\tInit(s *Shell)\n}\n```\nInitializer is an optional interface of a [Tool](#Tool): Init is called once, when the engine exists and before its schedule is built, so a tool can install engine packages that add systems (the voice tool installs package speech). [Shell.Engine](#Shell.Engine) is set.\n\n```go\ntype MemoryDocument struct {\n\t// contains filtered or unexported fields\n}\n```\nMemoryDocument is a document that exists only in memory: an untitled effect before Save as. It has the undo stack of a [FileDocument](#FileDocument), no file and no host, and always counts as having unsaved edits.\n\n```go\nfunc NewMemoryDocument(text []byte) *MemoryDocument\n```\nNewMemoryDocument returns a document starting with text.\n\n```go\nfunc (d *MemoryDocument) Dirty() bool\n```\nDirty reports true: an untitled document is never saved.\n\n```go\nfunc (u *MemoryDocument) Edit(text []byte) error\n```\nEdit makes text the current version: the old text goes on the undo stack and the redo stack is dropped. An edit that changes nothing is ignored.\n\n```go\nfunc (u *MemoryDocument) Redo() bool\n```\nRedo undoes an Undo. It reports false when there is nothing to redo.\n\n```go\nfunc (d *MemoryDocument) SaveAs(path string) *FileDocument\n```\nSaveAs returns the file document that continues this one at path, with the text, the undo history and the saved state of a document that was just written to disk.\n\n```go\nfunc (u *MemoryDocument) Text() []byte\n```\nText returns the current text.\n\n```go\nfunc (u *MemoryDocument) Undo() bool\n```\nUndo returns to the previous text. It reports false when there is none.\n\n```go\ntype Model[F any] struct {\n\tDocStatus\n\t// File is the decoded file, the zero F until the first valid document.\n\tFile F\n\t// Encode returns the canonical text of a file.\n\tEncode func(F) ([]byte, error)\n\t// Emit takes the text of every edit; nil drops it (tests, no document).\n\tEmit func(text []byte)\n}\n```\nModel is the model of a document tool whose state is one decoded file F, usually a pointer to the format's struct: a change is a function on File, then Encode, then one Emit (the tool passes [Shell.Edit](#Shell.Edit)), so undo, dirty state and the host's diff see the file as any other text. Decoding stays with the tool, which also loads what the file names; it calls [Model.SetFile](#Model.SetFile) or [DocStatus.MarkStale](#DocStatus.MarkStale) with the result.\n\n```go\nfunc (m *Model[F]) Do(edit func(F) error) error\n```\nDo runs edit on File when [DocStatus.Editable](#DocStatus.Editable) allows it, then encodes the file and emits the text: one document edit. An edit that returns an error must leave File as it was; nothing is emitted then.\n\n```go\nfunc (m *Model[F]) SetFile(f F)\n```\nSetFile replaces the file with a new document version and clears a stale mark.\n\n```go\ntype OverlayFS struct {\n\t// contains filtered or unexported fields\n}\n```\nOverlayFS is an asset filesystem that serves a few in-memory files over a base filesystem. Tools use it for assets that are code, not files, such as the particle editor's built-in sprites: the engine loads them like any other asset. Hand the same OverlayFS to [Config.FS](#Config.FS) and to the engine's game.Config.FS, and to [Config.Overlay](#Config.Overlay) so tools can reach it. It is safe for concurrent use: the asset workers read while the tool sets.\n\n```go\nfunc NewOverlayFS(base fs.FS) *OverlayFS\n```\nNewOverlayFS returns an overlay over base, which may be nil.\n\n```go\nfunc (o *OverlayFS) Open(name string) (fs.File, error)\n```\nOpen implements [fs.FS](/io/fs#FS): an overlay file, else the base's.\n\n```go\nfunc (o *OverlayFS) Set(name string, data []byte)\n```\nSet serves data under the slash-separated asset key name.\n\n```go\ntype Panel struct {\n\t// Title names the panel (a window title, a heading).\n\tTitle string `json:\"title\"`\n\t// Status is a line at the bottom for messages: a dirty document that\n\t// changed on disk, a failed load. The shell sets it; tools leave it\n\t// empty.\n\tStatus   string    `json:\"status,omitempty\"`\n\tSections []Section `json:\"sections\"`\n}\n```\nPanel is what a tool shows next to the viewport. It is plain data: the shell marshals it for the extension and the debugui renderer walks it.\n\n```go\nfunc (p Panel) Check() error\n```\nCheck validates the panel and returns every problem, joined: duplicate ids (sections and fields share one id space), an unknown widget or side, a missing label, a dropdown value outside its options, a value of the wrong kind.\n\n```go\nfunc (p Panel) Find(id string) (Field, bool)\n```\nFind returns the field with id.\n\n```go\ntype Renderer interface {\n\t// Update shows p and reports changed widgets through set. It reports\n\t// whether the panel has the mouse or keyboard (a hovered widget, a\n\t// focused text field), which keeps the viewport from reacting.\n\tUpdate(p Panel, set func(id string, v json.RawMessage)) (captured bool)\n\t// Draw draws the panel over the final screen.\n\tDraw(screen ebiten.FinalScreen)\n\t// Insets are the widths in window pixels the left and right panels of\n\t// the last Update cover, 0 for a panel not shown. The camera still draws\n\t// the whole window; the insets only set the free area between the\n\t// panels (see [Shell.FreeRect]).\n\tInsets() (left, right int)\n}\n```\nRenderer draws a panel in a window, as overlays over the viewport: the sections of [SideLeft](#SideLeft) on the left, the others on the right. The debugui renderer of package debugpanel is the only implementation; the VSCode build has none, since the extension draws the panel.\n\n```go\ntype Section struct {\n\t// ID is unique in the panel.\n\tID    string `json:\"id\"`\n\tLabel string `json:\"label\"`\n\t// Side is the native panel the section is drawn in: [SideLeft] or\n\t// [SideRight]; empty means right.\n\tSide Side `json:\"side,omitempty\"`\n\t// Collapsed is the initial state; a renderer keeps what the user chose.\n\tCollapsed bool    `json:\"collapsed,omitempty\"`\n\tFields    []Field `json:\"fields\"`\n}\n```\nSection is a collapsible group of fields.\n\n```go\ntype Shell struct {\n\t// contains filtered or unexported fields\n}\n```\nShell runs a [Tool](#Tool) on a paused engine. It implements [game.Tool](/github.com/weakpixel/engine/game#Tool): set it as game.Config.Tool of an engine with no game systems, and the shell handles the tool's file, the viewport camera, the grid, the panel and the host messages. Create one with [New](#New).\n\n```go\nfunc New(cfg Config) *Shell\n```\nNew returns a shell for cfg. Config.Tool is required. It panics (with a \"toolshell: \" message) when Tool is nil.\n\n```go\nfunc (s *Shell) Background() color.RGBA\n```\nBackground is the colour the view section's background dropdown selected, for a tool that draws text and must stay readable on it.\n\n```go\nfunc (s *Shell) Create(key string, text []byte, files []CreateFile) error\n```\nCreate writes a new document at asset key key with text, and the extra files (a sprite the document names). Natively the shell writes them under [Config.Root](#Config.Root); an untitled [MemoryDocument](#MemoryDocument) then continues as a [FileDocument](#FileDocument) at the new path, keeping its undo history. In the page build the shell sends a create message and the host writes the files and opens the new one. A key that is empty, absolute or leaves the asset root is an error and nothing is written. Create overwrites: a tool that wants to ask first checks [Shell.FS](#Shell.FS).\n\n```go\nfunc (s *Shell) Dirty() bool\n```\nDirty reports whether the document has unsaved edits (a [FileDocument](#FileDocument) that differs from its file, or an untitled [MemoryDocument](#MemoryDocument)).\n\n```go\nfunc (s *Shell) Down(k input.Key) bool\n```\nDown reports whether key is down.\n\n```go\nfunc (s *Shell) DrawFinal(e *game.Engine, screen ebiten.FinalScreen)\n```\nDrawFinal implements [game.Tool](/github.com/weakpixel/engine/game#Tool): grid, then the tool's overlays, then the panels (unless Tab hid them).\n\n```go\nfunc (s *Shell) Edit(text []byte)\n```\nEdit makes text the document's new version. Tools call it with the bytes of the format's encoder after they changed their state; the shell never diffs. It does nothing for a tool without a document.\n\n```go\nfunc (s *Shell) Engine() *game.Engine\n```\nEngine returns the engine the shell runs on, nil before the engine exists.\n\n```go\nfunc (s *Shell) FS() fs.FS\n```\nFS returns Config.FS: the asset filesystem, nil if the command set none.\n\n```go\nfunc (s *Shell) Files() []string\n```\nFiles returns Config.Files: the asset keys the host listed, nil if it listed none (walk [Shell.FS](#Shell.FS) then).\n\n```go\nfunc (s *Shell) FillRect(screen ebiten.FinalScreen, x, y, w, h float32, c color.RGBA)\n```\nFillRect fills a window-pixel rectangle with c, for overlays. The colour is premultiplied (color.RGBA).\n\n```go\nfunc (s *Shell) Frame(r gfx.Rect)\n```\nFrame centers the camera on r and zooms to fit it, and remembers r as the content the Fit button and the F key frame.\n\n```go\nfunc (s *Shell) FreeRect() image.Rectangle\n```\nFreeRect returns the area of the window between the left and right panels in window pixels, where a tool places what must not sit under a panel and where Fit frames the content. It is the whole window when the panels are hidden or there is no renderer (the VSCode build).\n\n```go\nfunc (s *Shell) Grid() Grid\n```\nGrid returns the grid settings.\n\n```go\nfunc (s *Shell) Init(e *game.Engine)\n```\nInit implements [game.Tool](/github.com/weakpixel/engine/game#Tool). It calls the tool's [Initializer](#Initializer).\n\n```go\nfunc (s *Shell) Input(src input.Source) input.Source\n```\nInput implements [game.Tool](/github.com/weakpixel/engine/game#Tool). The paused engine skips its input stage, so the shell polls the device itself; the game reads the same source.\n\n```go\nfunc (s *Shell) Key() string\n```\nKey returns the asset key of the document's file, \"\" while it is untitled.\n\n```go\nfunc (s *Shell) Mouse() input.MouseFrame\n```\nMouse returns this tick's mouse state, in logical pixels (which are window pixels: the shell's engine draws 1:1).\n\n```go\nfunc (s *Shell) MouseWorld() gfx.Vec2\n```\nMouseWorld returns the world position under the mouse.\n\n```go\nfunc (s *Shell) OpenFile(key string) error\n```\nOpenFile asks the host to open the file at asset key key, for example a level a previewer found. It is a request: the host decides how the file opens. In the page build it sends an open message; natively, where there is no host, the panel's status line says which file to open. A key that is not a clean relative path is an error.\n\n```go\nfunc (s *Shell) Overlay() *OverlayFS\n```\nOverlay returns Config.Overlay, nil if the command set none.\n\n```go\nfunc (s *Shell) PanHeld() bool\n```\nPanHeld reports whether Space is held, which turns the left button into a pan.\n\n```go\nfunc (s *Shell) PanelsHidden() bool\n```\nPanelsHidden reports whether Tab hid the panels of the native window.\n\n```go\nfunc (s *Shell) Pressed(k input.Key) bool\n```\nPressed reports whether key went down this tick.\n\n```go\nfunc (s *Shell) Receive(msg []byte)\n```\nReceive queues one message from the host; it is safe from any goroutine.\n\n```go\nfunc (s *Shell) ReportError(err error)\n```\nReportError shows err in the panel's status line, logs it and sends it to the host. Tools call it for failures that are not the user's input being rejected by Set (which returns the error).\n\n```go\nfunc (s *Shell) ScreenSize() image.Point\n```\nScreenSize returns the logical screen size the camera maps to.\n\n```go\nfunc (s *Shell) SetContent(r gfx.Rect)\n```\nSetContent remembers r as the content Fit and the F key frame, without moving the camera.\n\n```go\nfunc (s *Shell) SetView(id string, v json.RawMessage) (bool, error)\n```\nSetView applies a change of a widget of [Shell.ViewSection](#Shell.ViewSection). It reports whether id belongs to the view section.\n\n```go\nfunc (s *Shell) StrokeLine(screen ebiten.FinalScreen, x0, y0, x1, y1, width float32, c color.RGBA)\n```\nStrokeLine draws a line of the given width in window pixels from (x0, y0) to (x1, y1), for overlays. It is the shared white pixel stretched and rotated, so it has square ends and no anti-aliasing. The colour is premultiplied (color.RGBA).\n\n```go\nfunc (s *Shell) StrokePolyline(screen ebiten.FinalScreen, pts []gfx.Vec2, closed bool, width float32, c color.RGBA)\n```\nStrokePolyline draws the segments between consecutive points in window pixels; closed also joins the last point to the first.\n\n```go\nfunc (s *Shell) Tick(e *game.Engine) game.TickMode\n```\nTick implements [game.Tool](/github.com/weakpixel/engine/game#Tool). It always pauses the game: only the engine's own stages run.\n\n```go\nfunc (s *Shell) ViewSection() Section\n```\nViewSection returns the view controls every tool shows: grid on and off, cell size and offset, background, the zoom and the Fit and 1:1 buttons. A tool puts it in its panel; [Shell.SetView](#Shell.SetView) handles its widgets. It is on the left side.\n\n```go\nfunc (s *Shell) WindowPoint(p gfx.Vec2) gfx.Vec2\n```\nWindowPoint maps a world position to window pixels through the camera.\n\n```go\nfunc (s *Shell) WindowRect(r gfx.Rect) gfx.Rect\n```\nWindowRect maps a world rectangle to window pixels through the camera.\n\n```go\ntype Side string\n```\nSide is the panel of the native window a [Section](#Section) is drawn in.\n\n```go\nconst (\n\tSideLeft  Side = \"left\"\n\tSideRight Side = \"right\"\n)\n```\nThe sides of a section. The native window shows the view settings and the lists content is picked from on the left, the properties of the selection on the right. The extension shows one column and ignores the side.\n\n```go\ntype Syncer interface {\n\tSync(s *Shell)\n}\n```\nSyncer is an optional interface of a [Tool](#Tool): Sync is called every tick, including ticks when a panel has the mouse, after the camera moved and before the engine extracts what to draw.\n\n```go\ntype Tool interface {\n\t// Open loads what the file at asset key key needs. It is called on the\n\t// first tick, after the engine exists, and again for every host open\n\t// message of a [Closer]. An error is shown in the panel's status line and\n\t// reported to the host.\n\tOpen(s *Shell, key string) error\n\t// Update handles viewport input. It is not called while a panel has the\n\t// mouse or keyboard.\n\tUpdate(s *Shell)\n\t// Draw draws overlays in window pixels, over the grid and under the\n\t// panel.\n\tDraw(s *Shell, screen ebiten.FinalScreen)\n\t// Panel returns the panel as it is now. It is called every tick and must\n\t// be cheap; include [Shell.ViewSection] to get the shared view controls.\n\tPanel() Panel\n\t// Set applies a changed widget, from either renderer. The value is the\n\t// widget's JSON value, null for a button. [Shell.SetView] has already\n\t// taken the view section's widgets.\n\tSet(id string, v json.RawMessage) error\n}\n```\nTool is one tool of wpix-editor: it loads what its file needs, reacts to the viewport, describes its panel and takes the panel's changes. A tool never draws widgets and never reads the device for the panel.\n\nThe shell handles some input before [Tool.Update](#Tool.Update) and a tool must not bind it: F (fit), 1 (zoom 1), Tab (hide the panels), Ctrl/Cmd with Z, Shift+Z, Y and S, the wheel, the middle button, and Space with the left button (pan, see [Shell.PanHeld](#Shell.PanHeld)).\n\n```go\ntype Transport interface {\n\tSend(msg []byte)\n}\n```\nTransport sends one message to the host. It is called on the game goroutine. It is the same shape as hostlink.Transport, which hostlink.ConnectPage returns.\n\n```go\ntype Undoer interface {\n\tDocument\n\tUndo() bool\n\tRedo() bool\n}\n```\nUndoer is a document with an undo history of its own: the native backends. The shell binds Ctrl/Cmd+Z, Shift+Z and Y to it.\n\n```go\ntype Widget string\n```\nWidget is the kind of a panel [Field](#Field).\n\n```go\nconst (\n\t// WidgetNumber is a number field (a slider too when Min and Max are\n\t// both set). Its value is a JSON number.\n\tWidgetNumber Widget = \"number\"\n\t// WidgetCheckbox is a checkbox. Its value is a JSON boolean.\n\tWidgetCheckbox Widget = \"checkbox\"\n\t// WidgetDropdown picks one of Options. Its value is the option index.\n\tWidgetDropdown Widget = \"dropdown\"\n\t// WidgetText is a one-line text field; Set receives the text when the\n\t// user confirms it (Enter or blur). Its value is a JSON string.\n\tWidgetText Widget = \"text\"\n\t// WidgetButton is a button. It has no value; Set receives null.\n\tWidgetButton Widget = \"button\"\n\t// WidgetLabel is read-only text such as \"512 × 256 px\" or the mouse\n\t// position. Its value is a JSON string.\n\tWidgetLabel Widget = \"label\"\n\t// WidgetRange is a pair of numbers, low and high, that never cross. Min,\n\t// Max, Step and Digits bound and format both. Its value is the JSON array\n\t// [lo, hi].\n\tWidgetRange Widget = \"range\"\n\t// WidgetColor is a color picker with an alpha channel. Its value is the\n\t// string \"#rrggbbaa\".\n\tWidgetColor Widget = \"color\"\n\t// WidgetAsset picks an asset key from Options. Its value is the key, \"\"\n\t// for none. Kind says what the asset is and Thumbs holds the pictures of\n\t// the entries the page cannot fetch.\n\tWidgetAsset Widget = \"asset\"\n)\n```\nThe widgets of M4a. A widget exists only once a tool needs it, and then in both renderers in the same change.\n\n","path":"github.com/weakpixel/engine/editor/toolshell","name":"toolshell","synopsis":"Package toolshell is the shell the wpix-editor tools run on: a game.Tool on an engine with no game systems, so assets load through the engine's asset server and the content is drawn by the engine's renderer.","isRedistributable":true}
