Documentation
¶
Overview ¶
Package resources gives a scene a namespace for its files.
An application ships a resources/ directory next to its main package:
//go:embed all:resources
var appFS embed.FS
bundle := resources.New()
bundle.Mount("res", appFS, "resources")
scene, _ := view.LoadBundle(bundle, "res://scenes/main.qml", ...)
QML then refers to files as res://images/hero.png. The toolkit's own defaults (fonts, themes) live in the meui:// namespace. External directories can be mounted over either namespace at runtime, so an app can read a theme from disk without giving up the bundled defaults; the mount decides whether the external copy or the bundled one wins.
Every name is a slash-separated path inside a mount. Absolute paths and ".." are refused, so a scene cannot escape its bundle. External mounts go through os.Root, which refuses symlinks that leave the mounted directory.
Index ¶
- Variables
- func IsURI(s string) bool
- func Open(uri string) (fs.File, error)
- func ReadFile(uri string) ([]byte, error)
- func ReadFileLimit(uri string, limit int64) ([]byte, error)
- func RegisterBuiltin(fsys fs.FS)
- func Use(b *Bundle)
- type Bundle
- func (b *Bundle) Exists(uri string) bool
- func (b *Bundle) Mount(scheme string, fsys fs.FS, root string) error
- func (b *Bundle) MountExternal(scheme, dir string) error
- func (b *Bundle) Open(uri string) (fs.File, error)
- func (b *Bundle) ReadDir(uri string) ([]fs.DirEntry, error)
- func (b *Bundle) ReadFile(uri string) ([]byte, error)
- func (b *Bundle) ReadFileLimit(uri string, limit int64) ([]byte, error)
- func (b *Bundle) Resolve(sceneURI, ref string) (string, bool)
- func (b *Bundle) SetOrder(scheme string, order Order) error
- func (b *Bundle) Stat(uri string) (fs.FileInfo, error)
- func (b *Bundle) Unmount(scheme string)
- type Order
Constants ¶
This section is empty.
Variables ¶
var ErrNoScheme = errors.New("resources: URI has no scheme")
ErrNoScheme means the URI does not start with "<scheme>://".
Functions ¶
func IsURI ¶
IsURI reports whether s is a resource URI. Any "<scheme>://" counts except the network and file schemes, which are not bundles: http(s) stays the renderer's clear "remote images are not fetched" error, and file:// is a disk path.
func ReadFileLimit ¶
ReadFileLimit reads from the default bundle with a byte cap.
func RegisterBuiltin ¶
RegisterBuiltin mounts fsys at meui://. It is called by the meui package's init from its embedded files; a no_embed build registers nothing.
Types ¶
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
Bundle is a set of namespaces. The zero value is not usable; call New.
func Default ¶
func Default() *Bundle
Default returns the process-wide bundle the widgets resolve URIs against.
func (*Bundle) Mount ¶
Mount installs fsys at scheme, rooted at root inside fsys. Mounting a scheme again replaces its layers.
func (*Bundle) MountExternal ¶
MountExternal adds an external directory as a layer of scheme. The layer is embedded-first unless SetOrder makes it external-first. The directory must exist.
func (*Bundle) Open ¶
Open opens a resource URI. Directories are openable too; callers that need a file should Stat it.
func (*Bundle) ReadDir ¶
ReadDir merges the layers. The higher-precedence layer wins on a duplicate name; the result is sorted by name so a theme list is stable.
func (*Bundle) ReadFile ¶
ReadFile reads a regular file. It is capped so a bad name cannot exhaust memory; callers that keep the bytes apply their own tighter limits.
func (*Bundle) ReadFileLimit ¶
ReadFileLimit reads a regular file no larger than limit bytes.
func (*Bundle) Resolve ¶
Resolve turns a reference found in a scene into a resource URI. An explicit scheme is returned unchanged (and checked). A relative reference is tried against the scene's directory first, then against the bundle root.