toolshell

package
v0.0.0-...-8d5fc3c Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 27 Imported by: 1 module, 0 packages

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 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. The shell owns the viewport (pan, zoom, grid), the tool's Panel and, for document tools, the document.

A tool describes its panel as data (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: a file on disk with its own undo natively, the host's document in VSCode.

The 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.

Index

Constants

View Source
const (
	AssetImage  = "image"
	AssetShader = "shader"
)

The kinds of an asset field.

Variables

View Source
var ErrNoDocument = errors.New("nothing to edit: no valid document yet")

ErrNoDocument is returned by an edit before the first valid document arrived.

View Source
var ErrReadOnly = errors.New("the file is shown read-only")

ErrReadOnly 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).

View Source
var ErrStale = errors.New("the document has errors: fix it in the text editor first")

ErrStale 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.

Functions

func CoarseStep

func CoarseStep(step float32) float32

CoarseStep 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.

func FrameRect

func FrameRect(cam *render.Camera, r gfx.Rect, screen image.Point, free image.Rectangle)

FrameRect 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.

func PanTo

func PanTo(cam *render.Camera, prev, cur gfx.Vec2, screen image.Point)

PanTo moves cam so that the world point under the screen point prev is under cur.

func ZoomAt

func ZoomAt(cam *render.Camera, cur gfx.Vec2, screen image.Point, steps float32)

ZoomAt 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.

Types

type Checker

type Checker interface {
	// Check reports whether the tool can open the file at asset key key.
	Check(key string) error
}

Checker is an optional interface of a 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.

type Closer

type Closer interface {
	// Close removes what Open spawned and releases what it loaded.
	Close(s *Shell)
}

Closer is an optional interface of a 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.

type Config

type Config struct {
	// Name is the tool's name ("view"), sent in the ready message.
	Name string
	// Tool is the tool to run.
	Tool Tool
	// Key is the asset key of the file the tool opens.
	Key string
	// FS is the asset filesystem the engine loads from, for tools that read
	// a file as raw bytes (the anim tool reads its sheet's JSON). Optional.
	FS fs.FS
	// Overlay is the in-memory part of FS, when FS is an [OverlayFS]. Tools
	// serve generated assets through [Shell.Overlay]. Optional.
	Overlay *OverlayFS
	// Document is the backend of a [DocumentTool]'s file; nil for other
	// tools. A [FileDocument] is loaded into the tool on the first tick; a
	// [HostDocument] waits for the host's document message.
	Document Document
	// Files lists the asset keys of every file in the asset root, for hosts
	// whose filesystem cannot list directories (the page build). Tools that
	// list assets use it when set and walk FS otherwise. Optional.
	Files []string
	// Root is the asset root as a directory of the host's filesystem, where
	// [Shell.Create] writes natively. Empty in the page build, where the
	// host writes.
	Root string
	// Transport carries the tool protocol to the host page; nil natively.
	Transport Transport
	// Inbox holds the host's messages; nil makes the shell create one. The
	// page hookup pushes into it before the shell exists.
	Inbox *Inbox
	// Renderer draws the panel; nil in the VSCode build.
	Renderer Renderer
	// Now returns the time, for throttling panel updates and polling the
	// file; nil means time.Now. Tests set it.
	Now func() time.Time
}

Config configures a Shell.

type CreateFile

type CreateFile struct {
	Path string
	Data []byte
}

CreateFile is a file Shell.Create writes: an asset key and its bytes.

type DocStatus

type DocStatus struct {
	// Loaded says that a valid document was loaded at least once.
	Loaded bool
	// Stale is the parse error of the last text, "" while the shown file is
	// the document. The last good version stays shown.
	Stale string
	// ReadOnly refuses every edit with [ErrReadOnly].
	ReadOnly bool
}

DocStatus 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) so the three checks and their errors are the same everywhere.

func (*DocStatus) Editable

func (d *DocStatus) Editable() error

Editable reports why an edit is refused: ErrReadOnly, ErrStale or ErrNoDocument, in that order; nil when it may go ahead.

func (*DocStatus) MarkStale

func (d *DocStatus) MarkStale(err error)

MarkStale keeps the shown version and notes that the document does not parse.

type Document

type Document interface {
	// Text returns the current text.
	Text() []byte
	// Edit makes text the document's new version.
	Edit(text []byte) error
}

Document is the text document a 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 natively, HostDocument in VSCode.

type DocumentTool

type DocumentTool interface {
	Tool
	// Load takes a new document version: when the file is opened, changed
	// on disk, undone or redone, or sent by the host. The tool replaces its
	// state; it does not call [Shell.Edit] for it.
	Load(text []byte) error
}

DocumentTool is a Tool whose file is a text document it edits.

type External

type External int

External says what a check of the file found.

const (
	// ExternalNone means the file is as the document last saw it.
	ExternalNone External = iota
	// ExternalReloaded means the file changed and the document had no
	// unsaved edits: it now holds the file's text (the undo stacks are
	// dropped) and the tool should load it.
	ExternalReloaded
	// ExternalConflict means the file changed while the document has
	// unsaved edits: nothing is loaded. The shell reports it in the panel.
	ExternalConflict
)

type Field

type Field struct {
	// ID is unique in the panel; [Tool.Set] receives it.
	ID    string `json:"id"`
	Label string `json:"label"`
	// Widget is the kind of widget.
	Widget Widget `json:"widget"`
	// Value is the current value (see the Widget constants); none for a
	// button.
	Value json.RawMessage `json:"value,omitempty"`
	// Min, Max and Step bound and step a number. A renderer keeps what the
	// user types inside the bounds that are set; with both set it shows a
	// slider too. One bound alone (see [Field.AtLeast]) limits the number
	// without a slider.
	Min  *float64 `json:"min,omitempty"`
	Max  *float64 `json:"max,omitempty"`
	Step *float64 `json:"step,omitempty"`
	// Digits is the decimals a number shows; 0 is an integer and Set
	// receives an integer.
	Digits int `json:"digits,omitempty"`
	// Options are the entries of a dropdown, or the candidate asset keys of
	// an asset field.
	Options []string `json:"options,omitempty"`
	// Kind is the kind of an asset field: [AssetImage] or [AssetShader].
	Kind string `json:"kind,omitempty"`
	// Thumbs maps an asset key to a PNG data URI for the entries of an asset
	// field that are not files the page can fetch (built-in sprites).
	Thumbs map[string]string `json:"thumbs,omitempty"`
	// Readonly shows the widget but does not let the user change it.
	Readonly bool `json:"readonly,omitempty"`
	// Hint is a tooltip.
	Hint string `json:"hint,omitempty"`
	// List, on a dropdown, asks a renderer to draw the options as a
	// scrollable list of this many rows instead of a drop-down (see
	// [Field.AsList]). The value and Set stay the dropdown's: the option
	// index. A renderer that has no list shows a dropdown.
	List int `json:"list,omitempty"`
}

Field is one widget of a Section.

func Asset

func Asset(id, label, kind, key string, options []string) Field

Asset returns an asset field of kind (AssetImage or AssetShader) with the key selected, "" for none, and the candidate keys.

func Button

func Button(id, label string) Field

Button returns a button. Its Set value is null.

func Checkbox

func Checkbox(id, label string, v bool) Field

Checkbox returns a checkbox field.

func Color

func Color(id, label, hex string) Field

Color returns a color field; hex is "#rrggbbaa".

func Dropdown(id, label string, index int, options ...string) Field

Dropdown returns a dropdown field with the option at index selected.

func Label

func Label(id, label, text string) Field

Label returns read-only text: label on the left, text on the right.

func Number

func Number(id, label string, v float64) Field

Number returns a number field with value v and step 1.

func NumberRange

func NumberRange(id, label string, lo, hi float64) Field

NumberRange returns a range field with the value [lo, hi] and step 1.

func Text

func Text(id, label, v string) Field

Text returns a text field.

func (Field) AsList

func (f Field) AsList(rows int) Field

AsList 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 rejects a list on any other widget.

func (Field) AsReadonly

func (f Field) AsReadonly() Field

AsReadonly returns f with Readonly set.

func (Field) AtLeast

func (f Field) AtLeast(lo float64) Field

AtLeast returns f with only a lower bound: no slider, but a renderer does not let the value go below lo.

func (Field) Range

func (f Field) Range(lo, hi float64) Field

Range returns f with its bounds set, which makes a renderer show a slider.

func (Field) WithDigits

func (f Field) WithDigits(n int) Field

WithDigits returns f with the number of decimals shown set.

func (Field) WithHint

func (f Field) WithHint(hint string) Field

WithHint returns f with its tooltip set.

func (Field) WithStep

func (f Field) WithStep(step float64) Field

WithStep returns f with its step set.

func (Field) WithThumbs

func (f Field) WithThumbs(thumbs map[string]string) Field

WithThumbs returns f with the thumbnails of its entries set.

type FileDocument

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

FileDocument 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.

func NewFileDocument

func NewFileDocument(path string, text []byte) *FileDocument

NewFileDocument returns a document for a file that does not exist yet, starting with text. It is dirty until Save creates the file.

func OpenFileDocument

func OpenFileDocument(path string) (*FileDocument, error)

OpenFileDocument reads the file at path.

func (*FileDocument) AddPending

func (d *FileDocument) AddPending(path string, data []byte)

AddPending 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.

func (*FileDocument) CheckDisk

func (d *FileDocument) CheckDisk() (External, error)

CheckDisk compares the file with what the document last read or wrote.

func (*FileDocument) Dirty

func (d *FileDocument) Dirty() bool

Dirty reports whether the text differs from the file's.

func (*FileDocument) Edit

func (u *FileDocument) Edit(text []byte) error

Edit 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.

func (*FileDocument) Path

func (d *FileDocument) Path() string

Path returns the file's path.

func (*FileDocument) Redo

func (u *FileDocument) Redo() bool

Redo undoes an Undo. It reports false when there is nothing to redo.

func (*FileDocument) Save

func (d *FileDocument) Save() error

Save writes the pending files, then the text to the file.

func (*FileDocument) Text

func (u *FileDocument) Text() []byte

Text returns the current text.

func (*FileDocument) Undo

func (u *FileDocument) Undo() bool

Undo returns to the previous text. It reports false when there is none.

type Grid

type Grid struct {
	On bool
	// Cell is the cell size in world units.
	Cell float32
	// OffsetX and OffsetY shift the lines, in world units.
	OffsetX, OffsetY float32
}

Grid is the grid drawn over the viewport. The lines are the multiples of Cell in world units, shifted by Offset.

type GridLine

type GridLine struct {
	// At is the line's position in window pixels along the axis.
	At float32
	// Major is set for every eighth line, counted from the grid origin.
	Major bool
}

GridLine is one line of a grid along one axis.

func GridLines

func GridLines(origin, step, length float32) []GridLine

GridLines 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.

type HostDocument

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

HostDocument 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 filters for the echo of the last edit.

func NewHostDocument

func NewHostDocument(t Transport) *HostDocument

NewHostDocument returns a document that sends its edits over t.

func (*HostDocument) Edit

func (d *HostDocument) Edit(text []byte) error

Edit implements Document: it sends the text to the host.

func (*HostDocument) Receive

func (d *HostDocument) Receive(text []byte) (load bool)

Receive 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.

func (*HostDocument) Text

func (d *HostDocument) Text() []byte

Text implements Document: the last text the host sent or the tool made.

type Inbox

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

Inbox 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.

func (*Inbox) Push

func (b *Inbox) Push(msg []byte)

Push queues one message. It copies msg.

type Initializer

type Initializer interface {
	Init(s *Shell)
}

Initializer is an optional interface of a 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 is set.

type MemoryDocument

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

MemoryDocument is a document that exists only in memory: an untitled effect before Save as. It has the undo stack of a FileDocument, no file and no host, and always counts as having unsaved edits.

func NewMemoryDocument

func NewMemoryDocument(text []byte) *MemoryDocument

NewMemoryDocument returns a document starting with text.

func (*MemoryDocument) Dirty

func (d *MemoryDocument) Dirty() bool

Dirty reports true: an untitled document is never saved.

func (*MemoryDocument) Edit

func (u *MemoryDocument) Edit(text []byte) error

Edit 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.

func (*MemoryDocument) Redo

func (u *MemoryDocument) Redo() bool

Redo undoes an Undo. It reports false when there is nothing to redo.

func (*MemoryDocument) SaveAs

func (d *MemoryDocument) SaveAs(path string) *FileDocument

SaveAs 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.

func (*MemoryDocument) Text

func (u *MemoryDocument) Text() []byte

Text returns the current text.

func (*MemoryDocument) Undo

func (u *MemoryDocument) Undo() bool

Undo returns to the previous text. It reports false when there is none.

type Model

type Model[F any] struct {
	DocStatus
	// File is the decoded file, the zero F until the first valid document.
	File F
	// Encode returns the canonical text of a file.
	Encode func(F) ([]byte, error)
	// Emit takes the text of every edit; nil drops it (tests, no document).
	Emit func(text []byte)
}

Model 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), 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 or DocStatus.MarkStale with the result.

func (*Model[F]) Do

func (m *Model[F]) Do(edit func(F) error) error

Do runs edit on File when 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.

func (*Model[F]) SetFile

func (m *Model[F]) SetFile(f F)

SetFile replaces the file with a new document version and clears a stale mark.

type OverlayFS

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

OverlayFS 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 and to the engine's game.Config.FS, and to Config.Overlay so tools can reach it. It is safe for concurrent use: the asset workers read while the tool sets.

func NewOverlayFS

func NewOverlayFS(base fs.FS) *OverlayFS

NewOverlayFS returns an overlay over base, which may be nil.

func (*OverlayFS) Open

func (o *OverlayFS) Open(name string) (fs.File, error)

Open implements fs.FS: an overlay file, else the base's.

func (*OverlayFS) Set

func (o *OverlayFS) Set(name string, data []byte)

Set serves data under the slash-separated asset key name.

type Panel

type Panel struct {
	// Title names the panel (a window title, a heading).
	Title string `json:"title"`
	// Status is a line at the bottom for messages: a dirty document that
	// changed on disk, a failed load. The shell sets it; tools leave it
	// empty.
	Status   string    `json:"status,omitempty"`
	Sections []Section `json:"sections"`
}

Panel 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.

func (Panel) Check

func (p Panel) Check() error

Check 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.

func (Panel) Find

func (p Panel) Find(id string) (Field, bool)

Find returns the field with id.

type Renderer

type Renderer interface {
	// Update shows p and reports changed widgets through set. It reports
	// whether the panel has the mouse or keyboard (a hovered widget, a
	// focused text field), which keeps the viewport from reacting.
	Update(p Panel, set func(id string, v json.RawMessage)) (captured bool)
	// Draw draws the panel over the final screen.
	Draw(screen ebiten.FinalScreen)
	// Insets are the widths in window pixels the left and right panels of
	// the last Update cover, 0 for a panel not shown. The camera still draws
	// the whole window; the insets only set the free area between the
	// panels (see [Shell.FreeRect]).
	Insets() (left, right int)
}

Renderer draws a panel in a window, as overlays over the viewport: the sections of 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.

type Section

type Section struct {
	// ID is unique in the panel.
	ID    string `json:"id"`
	Label string `json:"label"`
	// Side is the native panel the section is drawn in: [SideLeft] or
	// [SideRight]; empty means right.
	Side Side `json:"side,omitempty"`
	// Collapsed is the initial state; a renderer keeps what the user chose.
	Collapsed bool    `json:"collapsed,omitempty"`
	Fields    []Field `json:"fields"`
}

Section is a collapsible group of fields.

type Shell

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

Shell runs a Tool on a paused engine. It implements 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.

func New

func New(cfg Config) *Shell

New returns a shell for cfg. Config.Tool is required. It panics (with a "toolshell: " message) when Tool is nil.

func (*Shell) Background

func (s *Shell) Background() color.RGBA

Background is the colour the view section's background dropdown selected, for a tool that draws text and must stay readable on it.

func (*Shell) Create

func (s *Shell) Create(key string, text []byte, files []CreateFile) error

Create 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; an untitled MemoryDocument then continues as a 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.

func (*Shell) Dirty

func (s *Shell) Dirty() bool

Dirty reports whether the document has unsaved edits (a FileDocument that differs from its file, or an untitled MemoryDocument).

func (*Shell) Down

func (s *Shell) Down(k input.Key) bool

Down reports whether key is down.

func (*Shell) DrawFinal

func (s *Shell) DrawFinal(e *game.Engine, screen ebiten.FinalScreen)

DrawFinal implements game.Tool: grid, then the tool's overlays, then the panels (unless Tab hid them).

func (*Shell) Edit

func (s *Shell) Edit(text []byte)

Edit 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.

func (*Shell) Engine

func (s *Shell) Engine() *game.Engine

Engine returns the engine the shell runs on, nil before the engine exists.

func (*Shell) FS

func (s *Shell) FS() fs.FS

FS returns Config.FS: the asset filesystem, nil if the command set none.

func (*Shell) Files

func (s *Shell) Files() []string

Files returns Config.Files: the asset keys the host listed, nil if it listed none (walk Shell.FS then).

func (*Shell) FillRect

func (s *Shell) FillRect(screen ebiten.FinalScreen, x, y, w, h float32, c color.RGBA)

FillRect fills a window-pixel rectangle with c, for overlays. The colour is premultiplied (color.RGBA).

func (*Shell) Frame

func (s *Shell) Frame(r gfx.Rect)

Frame centers the camera on r and zooms to fit it, and remembers r as the content the Fit button and the F key frame.

func (*Shell) FreeRect

func (s *Shell) FreeRect() image.Rectangle

FreeRect 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).

func (*Shell) Grid

func (s *Shell) Grid() Grid

Grid returns the grid settings.

func (*Shell) Init

func (s *Shell) Init(e *game.Engine)

Init implements game.Tool. It calls the tool's Initializer.

func (*Shell) Input

func (s *Shell) Input(src input.Source) input.Source

Input implements game.Tool. The paused engine skips its input stage, so the shell polls the device itself; the game reads the same source.

func (*Shell) Key

func (s *Shell) Key() string

Key returns the asset key of the document's file, "" while it is untitled.

func (*Shell) Mouse

func (s *Shell) Mouse() input.MouseFrame

Mouse returns this tick's mouse state, in logical pixels (which are window pixels: the shell's engine draws 1:1).

func (*Shell) MouseWorld

func (s *Shell) MouseWorld() gfx.Vec2

MouseWorld returns the world position under the mouse.

func (*Shell) OpenFile

func (s *Shell) OpenFile(key string) error

OpenFile 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.

func (*Shell) Overlay

func (s *Shell) Overlay() *OverlayFS

Overlay returns Config.Overlay, nil if the command set none.

func (*Shell) PanHeld

func (s *Shell) PanHeld() bool

PanHeld reports whether Space is held, which turns the left button into a pan.

func (*Shell) PanelsHidden

func (s *Shell) PanelsHidden() bool

PanelsHidden reports whether Tab hid the panels of the native window.

func (*Shell) Pressed

func (s *Shell) Pressed(k input.Key) bool

Pressed reports whether key went down this tick.

func (*Shell) Receive

func (s *Shell) Receive(msg []byte)

Receive queues one message from the host; it is safe from any goroutine.

func (*Shell) ReportError

func (s *Shell) ReportError(err error)

ReportError 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).

func (*Shell) ScreenSize

func (s *Shell) ScreenSize() image.Point

ScreenSize returns the logical screen size the camera maps to.

func (*Shell) SetContent

func (s *Shell) SetContent(r gfx.Rect)

SetContent remembers r as the content Fit and the F key frame, without moving the camera.

func (*Shell) SetView

func (s *Shell) SetView(id string, v json.RawMessage) (bool, error)

SetView applies a change of a widget of Shell.ViewSection. It reports whether id belongs to the view section.

func (*Shell) StrokeLine

func (s *Shell) StrokeLine(screen ebiten.FinalScreen, x0, y0, x1, y1, width float32, c color.RGBA)

StrokeLine 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).

func (*Shell) StrokePolyline

func (s *Shell) StrokePolyline(screen ebiten.FinalScreen, pts []gfx.Vec2, closed bool, width float32, c color.RGBA)

StrokePolyline draws the segments between consecutive points in window pixels; closed also joins the last point to the first.

func (*Shell) Tick

func (s *Shell) Tick(e *game.Engine) game.TickMode

Tick implements game.Tool. It always pauses the game: only the engine's own stages run.

func (*Shell) ViewSection

func (s *Shell) ViewSection() Section

ViewSection 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 handles its widgets. It is on the left side.

func (*Shell) WindowPoint

func (s *Shell) WindowPoint(p gfx.Vec2) gfx.Vec2

WindowPoint maps a world position to window pixels through the camera.

func (*Shell) WindowRect

func (s *Shell) WindowRect(r gfx.Rect) gfx.Rect

WindowRect maps a world rectangle to window pixels through the camera.

type Side

type Side string

Side is the panel of the native window a Section is drawn in.

const (
	SideLeft  Side = "left"
	SideRight Side = "right"
)

The 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.

type Syncer

type Syncer interface {
	Sync(s *Shell)
}

Syncer is an optional interface of a 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.

type Tool

type Tool interface {
	// Open loads what the file at asset key key needs. It is called on the
	// first tick, after the engine exists, and again for every host open
	// message of a [Closer]. An error is shown in the panel's status line and
	// reported to the host.
	Open(s *Shell, key string) error
	// Update handles viewport input. It is not called while a panel has the
	// mouse or keyboard.
	Update(s *Shell)
	// Draw draws overlays in window pixels, over the grid and under the
	// panel.
	Draw(s *Shell, screen ebiten.FinalScreen)
	// Panel returns the panel as it is now. It is called every tick and must
	// be cheap; include [Shell.ViewSection] to get the shared view controls.
	Panel() Panel
	// Set applies a changed widget, from either renderer. The value is the
	// widget's JSON value, null for a button. [Shell.SetView] has already
	// taken the view section's widgets.
	Set(id string, v json.RawMessage) error
}

Tool 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.

The shell handles some input before 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).

type Transport

type Transport interface {
	Send(msg []byte)
}

Transport 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.

type Undoer

type Undoer interface {
	Document
	Undo() bool
	Redo() bool
}

Undoer 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.

type Widget

type Widget string

Widget is the kind of a panel Field.

const (
	// WidgetNumber is a number field (a slider too when Min and Max are
	// both set). Its value is a JSON number.
	WidgetNumber Widget = "number"
	// WidgetCheckbox is a checkbox. Its value is a JSON boolean.
	WidgetCheckbox Widget = "checkbox"
	// WidgetDropdown picks one of Options. Its value is the option index.
	WidgetDropdown Widget = "dropdown"
	// WidgetText is a one-line text field; Set receives the text when the
	// user confirms it (Enter or blur). Its value is a JSON string.
	WidgetText Widget = "text"
	// WidgetButton is a button. It has no value; Set receives null.
	WidgetButton Widget = "button"
	// WidgetLabel is read-only text such as "512 × 256 px" or the mouse
	// position. Its value is a JSON string.
	WidgetLabel Widget = "label"
	// WidgetRange is a pair of numbers, low and high, that never cross. Min,
	// Max, Step and Digits bound and format both. Its value is the JSON array
	// [lo, hi].
	WidgetRange Widget = "range"
	// WidgetColor is a color picker with an alpha channel. Its value is the
	// string "#rrggbbaa".
	WidgetColor Widget = "color"
	// WidgetAsset picks an asset key from Options. Its value is the key, ""
	// for none. Kind says what the asset is and Thumbs holds the pictures of
	// the entries the page cannot fetch.
	WidgetAsset Widget = "asset"
)

The widgets of M4a. A widget exists only once a tool needs it, and then in both renderers in the same change.

Directories

Path Synopsis
Package debugpanel draws a toolshell.Panel with debugui, in the native window of wpix-editor.
Package debugpanel draws a toolshell.Panel with debugui, in the native window of wpix-editor.

Jump to

Keyboard shortcuts

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