gruid-js – github.com/anaseto/gruid-js Index | Files

package js

import "github.com/anaseto/gruid-js"

Package js provides a Driver for making browser apps using wasm.

Index

Types

type Config

type Config struct {
	TileManager TileManager // for retrieving tiles (required)
	Width       int         // initial screen width in cells (default: 80)
	Height      int         // initial screen height in cells (default: 24)
	AppCanvasId string      // application's canvas id (default: appcanvas)
	AppDivId    string      // application's div containing the canvas id (default: appdiv)
}

Config contains configurations options for the driver.

type Driver

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

Driver implements gruid.Driver using the syscall/js interface for the browser using javascript and wasm.

func NewDriver

func NewDriver(cfg Config) *Driver

NewDriver returns a new driver with given configuration options.

func (*Driver) ClearCache

func (dr *Driver) ClearCache()

ClearCache clears the tiles internal cache.

func (*Driver) Close

func (dr *Driver) Close()

Close implements gruid.Driver.Close.

func (*Driver) Flush

func (dr *Driver) Flush(frame gruid.Frame)

Flush implements gruid.Driver.Flush.

func (*Driver) Init

func (dr *Driver) Init() error

Init implements gruid.Driver.Init.

func (*Driver) PollMsgs

func (dr *Driver) PollMsgs(ctx context.Context, msgs chan<- gruid.Msg) error

PollMsgs implements gruid.Driver.PollMsgs. To avoid conflicts with browser or OS shortcuts, keydown events with modifier keys may not be reported. If the script screenfull is available, it binds F11 for a portable canvas fullscreen.

func (*Driver) SetTileManager

func (dr *Driver) SetTileManager(tm TileManager)

SetTileManager allows to change the used tile manager.

type TileManager

type TileManager interface {
	// GetImage returns the image to be used for a given cell style.
	GetImage(gruid.Cell) image.Image

	// TileSize returns the (width, height) in pixels of the tiles. Both
	// should be positive and non-zero.
	TileSize() gruid.Point
}

TileManager manages tiles fetching.

Source Files

js.go

Version
v0.1.1 (latest)
Published
Feb 19, 2021
Platform
linux/amd64
Imports
8 packages
Last checked
3 weeks ago

Tools for package owners.