viewkit

package
v0.0.0-...-94fff03 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 13 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 viewkit holds what the wpix-editor tools that show a texture share: the texture sprite kept on screen (Texture), the frames over it with hover, selection, labels and a list to pick from (Frames), and the overlay text in window pixels (Labels). The previewers of package viewer and the sheet tool use it, so a sheet and an atlas draw their frames the same way. See doc/design/tool-shell.md#tools.

Index

Constants

View Source
const FrameRows = 8

FrameRows is the rows the frame list shows before it scrolls.

View Source
const LabelSize = 13

LabelSize is the size of the overlay text in device-independent pixels; the cache multiplies it by the display's scale factor.

View Source
const MinLabelPx = 24

MinLabelPx is the least width, in device-independent pixels, of a box that gets its label without being hovered or selected; smaller boxes would only be covered by their labels.

Variables

View Source
var DeviceScale = func() float64 {
	if m := ebiten.Monitor(); m != nil {
		return max(m.DeviceScaleFactor(), 1)
	}
	return 1
}

DeviceScale is the display's scale factor (devicePixelRatio in a browser), at least 1: window pixels are device pixels. It is a variable so tests can set it: the real lookup (ebiten.Monitor) initializes the windowing system, which a headless test has no display for.

View Source
var LabelModeNames = []string{"Index and name", "Index", "Name", "None"}

LabelModeNames are the entries of the Labels dropdown.

Functions

func DrawBorder

func DrawBorder(s *toolshell.Shell, screen ebiten.FinalScreen, r gfx.Rect, c color.RGBA)

DrawBorder draws a one pixel border in c just outside the world rectangle r, in window pixels.

func DrawOutline

func DrawOutline(s *toolshell.Shell, screen ebiten.FinalScreen, r gfx.Rect, c color.RGBA)

DrawOutline draws a one pixel outline in c along the inside of the window rectangle r.

func FrameAt

func FrameAt(frames []Frame, p gfx.Vec2) int

FrameAt returns the index in frames of the frame under texture point p, or -1. Where frames overlap (a packer may share pixels) the smallest wins, so a small frame inside a big one can still be picked.

func LabelFace

func LabelFace(px float64) *text.GoTextFace

LabelFace is the face of the overlay text at size px: Go Regular, so it needs no file.

func PointText

func PointText(p gfx.Vec2) string

PointText is "x, y" of p.

func RectText

func RectText(r gfx.Rect) string

RectText is "x, y, w × h" of r.

Types

type Frame

type Frame struct {
	// Index is the position in the atlas's file order.
	Index int
	// Name is the key of the frame ("idle_0", "3").
	Name string
	// Rect is the frame's pixels in the texture.
	Rect gfx.Rect
	// Size is the untrimmed size, Offset where the trimmed image starts in
	// it, and Pivot the default pivot in untrimmed pixels.
	Size, Offset, Pivot gfx.Vec2
}

Frame is one frame of an atlas or a sheet as a tool shows it.

func FramesOf

func FramesOf(a *render.Atlas, sprites render.SpriteStore) []Frame

FramesOf lists the frames of a loaded atlas in file order. A frame that is not ready (it cannot happen after a successful load) is left out.

type Frames

type Frames struct {
	// Prefix starts the ids of the widgets ("atlas", "sheet").
	Prefix string
	// List is the frames in file order.
	List []Frame
	// Hover and Sel index List, -1 for none.
	Hover, Sel int
	// Mode is what each frame is labelled with.
	Mode LabelMode
	// MinPx is the narrowest frame, in window pixels, that Draw outlines
	// (the hovered and the selected one always are); 0 means 3. Below it
	// the outlines are only a smudge.
	MinPx float32
	// contains filtered or unexported fields
}

Frames is the frames over a texture as a tool shows them: every frame outlined and labelled, the one under the mouse and the selected one highlighted, and a left section with the label mode and a list to pick a frame from. Its widget ids are Prefix + ".labels" and Prefix + ".frame".

func NewFrames

func NewFrames(prefix string) Frames

NewFrames returns frames with the widget id prefix and nothing hovered or selected.

func (*Frames) Draw

func (f *Frames) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)

Draw outlines the frames on screen and labels those wide enough, then highlights the hovered and the selected frame with their full label.

func (*Frames) Section

func (f *Frames) Section() toolshell.Section

Section is the left section to pick frames from: the label mode and the list of frames, "(none)" first (index 0 clears the selection).

func (*Frames) Set

func (f *Frames) Set(id string, val json.RawMessage) (ok bool, err error)

Set applies a widget of the section; ok is false for any other id.

func (*Frames) SetList

func (f *Frames) SetList(list []Frame)

SetList replaces the frames (a reload) and keeps the selection while it still exists.

func (*Frames) Shown

func (f *Frames) Shown() (Frame, bool)

Shown is the frame a panel describes: the selected one, else the one under the mouse.

func (*Frames) Update

func (f *Frames) Update(s *toolshell.Shell)

Update sets the frame under the mouse; a click (not a pan) selects it, or clears the selection when it is the selected one or none.

type LabelMode

type LabelMode int

LabelMode says what a tool writes on each frame.

const (
	LabelBoth LabelMode = iota
	LabelIndex
	LabelName
	LabelNone
)

The label modes, in the order of the panel's dropdown.

func (LabelMode) Text

func (m LabelMode) Text(f Frame) string

Text is the label of f: its index, its name, or both (the name only once when it is the index, as in a grid sheet).

type Labels

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

Labels renders overlay text once; the zero value is ready to use. The shell draws overlays on a FinalScreen, which text.Draw cannot target, so each string becomes a small image drawn with DrawImage. The final screen is in device pixels, so on a HiDPI display (scale 2) text of LabelSize device pixels would show at half its size: the cache renders at LabelSize times the scale, and starts over when the scale changes (the window moved to another display).

func (*Labels) Draw

func (c *Labels) Draw(screen ebiten.FinalScreen, s string, x, y float32)

Draw puts the label at window pixel (x, y), its top-left corner.

func (*Labels) Fits

func (c *Labels) Fits(s string, w float32) bool

Fits reports whether the label for s fits in a box w window pixels wide that is also at least MinLabelPx device-independent pixels wide.

func (*Labels) Width

func (c *Labels) Width(s string) float32

Width is the window width of the label for s.

type Texture

type Texture struct {
	// Sprite is the texture shown, the zero handle for none.
	Sprite gfx.SpriteHandle
	// contains filtered or unexported fields
}

Texture is one texture shown as a sprite entity with its top-left corner at world (0, 0), so a world point is a texture pixel. The zero value shows nothing until Texture.Spawn.

func (*Texture) Close

func (t *Texture) Close(s *toolshell.Shell)

Close deletes the sprite entity.

func (*Texture) Entity

func (t *Texture) Entity() ecs.Entity

Entity is the sprite entity, for tools that set more of its Sprite (a shader and its Params).

func (*Texture) SetSprite

func (t *Texture) SetSprite(s *toolshell.Shell, h gfx.SpriteHandle)

SetSprite shows h instead of the current texture.

func (*Texture) Size

func (t *Texture) Size(s *toolshell.Shell) gfx.Vec2

Size reads the texture's size from the asset store, which a hot reload can change; zero without a texture.

func (*Texture) Spawn

func (t *Texture) Spawn(s *toolshell.Shell, h gfx.SpriteHandle)

Spawn creates the sprite entity for h. Call it once; Texture.SetSprite changes the texture later.

func (*Texture) Sync

func (t *Texture) Sync(s *toolshell.Shell)

Sync keeps the texture visible; call it from the tool's toolshell.Syncer. The engine culls a sprite by its position alone, so a texture whose top-left corner left the screen would vanish while most of it is still visible. The sprite is instead pinned at the center of the part of the texture that is on screen, with its pivot set so the texture stays where it is.

Jump to

Keyboard shortcuts

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