imageload

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

README

ui/internal/imageload

ui/markdown 的图片:调用 core.DecodeImage 解析来源(文件路径、file://、data:、http(s)://),在后台 goroutine 加载解码,限制文件大小和像素数,加载中和失败时画占位。

  • 依赖:ui/core、ui/theme、ui/locale、ui/internal/loop。
  • 被谁依赖:ui/markdown(公开为 markdown.ImageLoader 和 markdown.DecodeImage)。

Load 返回 *Asset,加载完成后通过 core.Update 写回并重绘;Revision 变化表示状态变了。View 画图片,Agent 看到的角色是 image,值是 loading / loaded / error。kit 的 Image 直接接收 image.Image,不经过这里。

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