imageload

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 14 Imported by: 0

README

ui/internal/imageload

English | 简体中文

Image loading for ui/markdown: core.DecodeImage resolves file paths, file://, data:, and http(s):// sources. A background goroutine loads and decodes the image with byte and pixel limits; the view draws placeholders while loading or after failure.

  • Dependencies: ui/core, ui/theme, ui/locale, and ui/internal/loop.
  • Used by: ui/markdown, exposed as markdown.ImageLoader and markdown.DecodeImage.

Load returns an *Asset. On completion, core.Update applies the result and requests a redraw; a change in Revision indicates a state change. View draws the image. Agents see role image and value loading / loaded / error. The kit Image also accepts an image.Image directly without using this package.

Documentation

Overview

Package imageload loads images off the UI thread and draws them with a placeholder until they arrive. ui/markdown uses it for Markdown images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

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

Asset is shared image data. Read its state under the UI lock. A completed load invalidates windows through core.Update.

func Load

func Load(source string, loader Loader) *Asset

Load reads a local path, file URL, HTTP(S) URL or data URL in the background. A nil loader uses core.DecodeImage. The request has a 15-second deadline.

func (*Asset) Error

func (a *Asset) Error() error

func (*Asset) Ready

func (a *Asset) Ready() bool

func (*Asset) Revision

func (a *Asset) Revision() uint64

Revision changes when the asset finishes loading, for render caches.

func (*Asset) Size

func (a *Asset) Size() image.Point

Size is the image's size in pixels, zero until it has loaded.

type Loader

type Loader func(context.Context, string) (image.Image, error)

Loader reads an image source off the UI thread. Apps provide one for authenticated requests or paths relative to a document.

type View

type View struct {
	Asset *Asset
	Alt   string
}

View draws an asset at its natural size in dp, scaled down to fit, or a placeholder with the alt text while it loads or after it fails.

func (*View) Layout

func (v *View) Layout(gtx core.C) core.D

Jump to

Keyboard shortcuts

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