Documentation
¶
Index ¶
- Variables
- func CachedRenderer(wid core.Widget) (core.WidgetRenderer, bool)
- func Clean(canvasRefreshed bool)
- func CleanCanvas(canvas core.Canvas)
- func DeleteTextTexturesFor(canvas core.Canvas)
- func DeleteTexture(obj core.CanvasObject)
- func DestroyRenderer(wid core.Widget)
- func GetCanvasForObject(obj core.CanvasObject) core.Canvas
- func GetFontMetrics(text string, fontSize float32, style bellui.TextStyle, source bellui.Resource) (size geo.Size, base float32)
- func GetSvg(name string, o core.CanvasObject, w int, h int) *image.NRGBA
- func IsRendered(wid core.Widget) bool
- func IsValid(texture TextureType) bool
- func NoteSelectableMode(mode bellui.SelectableMode)
- func OverrideTheme(o core.CanvasObject, th bellui.Theme)
- func OverrideThemeMatchingScope(o, parent core.CanvasObject) bool
- func RangeExpiredTexturesFor(canvas core.Canvas, f func(core.CanvasObject))
- func RangeTexturesFor(canvas core.Canvas, f func(core.CanvasObject))
- func RenderedWidgets() map[core.Widget]struct{}
- func Renderer(wid core.Widget) core.WidgetRenderer
- func ResetThemeCaches()
- func SelectableModeSet() bool
- func SetCanvasForObject(obj core.CanvasObject, c core.Canvas, setup func())
- func SetFontMetrics(text string, fontSize float32, style bellui.TextStyle, source bellui.Resource, ...)
- func SetSvg(name string, o core.CanvasObject, pix *image.NRGBA, w int, h int)
- func SetTextTexture(ent FontCacheEntry, texture TextureType, canvas core.Canvas, free func())
- func SetTexture(obj core.CanvasObject, texture TextureType, canvas core.Canvas)
- func ThemeCacheGeneration() uint64
- func WidgetScopeID(o core.CanvasObject) string
- func WidgetTheme(o core.CanvasObject) bellui.Theme
- type CanvasRegistration
- type FontCacheEntry
- type TextureType
Constants ¶
This section is empty.
Variables ¶
var ( ValidDuration = 1 * time.Minute // CleanHooks are additional cleanup functions called during each Clean() cycle. // Used to allow packages like painter to register cache sweeps without circular imports. CleanHooks []func() )
var NoTexture = TextureType(0)
Functions ¶
func CachedRenderer ¶
func CachedRenderer(wid core.Widget) (core.WidgetRenderer, bool)
CachedRenderer looks up the cached render implementation for a widget If a renderer does not exist in the cache, it returns nil, false.
func Clean ¶
func Clean(canvasRefreshed bool)
Clean run cache clean task, it should be called on paint events.
func CleanCanvas ¶
CleanCanvas performs a complete remove of all the objects that belong to the specified canvas. Usually used to free all objects from a closing window. Also sweeps any expired renderers to avoid GPU resource leaks from widgets whose canvas entries expired before the canvas was closed.
func DeleteTextTexturesFor ¶
DeleteTextTexturesFor deletes all text textures for the given canvas.
func DeleteTexture ¶
func DeleteTexture(obj core.CanvasObject)
DeleteTexture deletes the texture from the cache map.
func DestroyRenderer ¶
DestroyRenderer frees a render implementation for a widget. This is typically for internal use only.
func GetCanvasForObject ¶
func GetCanvasForObject(obj core.CanvasObject) core.Canvas
GetCanvasForObject returns the canvas for the specified object.
func GetFontMetrics ¶
func GetFontMetrics(text string, fontSize float32, style bellui.TextStyle, source bellui.Resource) (size geo.Size, base float32)
GetFontMetrics looks up a calculated size and baseline required for the specified text parameters.
func IsRendered ¶
IsRendered returns true of the widget currently has a renderer. One will be created the first time a widget is shown but may be removed after it is hidden.
func IsValid ¶
func IsValid(texture TextureType) bool
IsValid will return true if the passed texture is potentially a texture.
func NoteSelectableMode ¶ added in v1.2.0
func NoteSelectableMode(mode bellui.SelectableMode)
NoteSelectableMode records that a canvas's selectable mode was set to mode. Every canvas implementation calls it from SetSelectableMode.
func OverrideTheme ¶
func OverrideTheme(o core.CanvasObject, th bellui.Theme)
OverrideTheme allows an app to specify that a single object should use a different theme to the app. This should be used sparingly to avoid a jarring user experience. If the object is a container it will theme the children, if it is a canvas primitive it will do nothing.
Since: 1.0
func OverrideThemeMatchingScope ¶
func OverrideThemeMatchingScope(o, parent core.CanvasObject) bool
func RangeExpiredTexturesFor ¶
func RangeExpiredTexturesFor(canvas core.Canvas, f func(core.CanvasObject))
RangeExpiredTexturesFor range over the expired textures for the specified canvas.
Note: If this is used to free textures, then it should be called inside a current gl context to ensure textures are deleted from gl.
func RangeTexturesFor ¶
func RangeTexturesFor(canvas core.Canvas, f func(core.CanvasObject))
RangeTexturesFor range over the textures for the specified canvas. It will not return the texture for a `canvas.Text` as their render lifecycle is handled separately.
Note: If this is used to free textures, then it should be called inside a current gl context to ensure textures are deleted from gl.
func RenderedWidgets ¶ added in v1.2.0
RenderedWidgets returns the widgets that currently have a cached renderer. Tests and benchmarks use it to release, at the end, the renderers they created: a test canvas never registers its objects, so closing a test window leaves them cached for ValidDuration, and a benchmark that builds a large widget per run piled them up by the gigabyte (#508).
func Renderer ¶
func Renderer(wid core.Widget) core.WidgetRenderer
Renderer looks up the render implementation for a widget. If one does not exist, it creates and caches a renderer for the widget. If two goroutines race to create the renderer, the loser's renderer is destroyed to prevent leaks.
func ResetThemeCaches ¶
func ResetThemeCaches()
ResetThemeCaches clears all the svg and text size cache maps
func SelectableModeSet ¶ added in v1.2.0
func SelectableModeSet() bool
SelectableModeSet reports whether any canvas may be in a selectable mode other than bellui.SelectablePerWidget.
func SetCanvasForObject ¶
func SetCanvasForObject(obj core.CanvasObject, c core.Canvas, setup func())
SetCanvasForObject sets the canvas for the specified object. The passed function will be called if the item was not previously attached to this canvas. An object registered to another canvas is moved to this one: it is shown here now, so refreshes and focus must reach this canvas (#448).
func SetFontMetrics ¶
func SetFontMetrics(text string, fontSize float32, style bellui.TextStyle, source bellui.Resource, size geo.Size, base float32)
SetFontMetrics stores a calculated font size and baseline for parameters that were missing from the cache.
func SetTextTexture ¶
func SetTextTexture(ent FontCacheEntry, texture TextureType, canvas core.Canvas, free func())
SetTextTexture sets cached texture for a text run.
func SetTexture ¶
func SetTexture(obj core.CanvasObject, texture TextureType, canvas core.Canvas)
SetTexture sets cached texture.
func ThemeCacheGeneration ¶
func ThemeCacheGeneration() uint64
ThemeCacheGeneration returns a counter bumped each time the theme/font caches are reset (ResetThemeCaches). A widget-level measurement memo compares this against the generation it was built under and drops itself when it differs, so it stays consistent with the authoritative global metrics cache (pre-rebrand tracker #896).
func WidgetScopeID ¶
func WidgetScopeID(o core.CanvasObject) string
func WidgetTheme ¶
func WidgetTheme(o core.CanvasObject) bellui.Theme
Types ¶
type CanvasRegistration ¶ added in v1.2.0
type CanvasRegistration struct {
// contains filtered or unexported fields
}
CanvasRegistration is the entry the canvas map holds for an object, as RegisterCanvasForObject returns it. A walk that keeps it can skip the map lookup while Current reports true (#487).
func RegisterCanvasForObject ¶ added in v1.2.0
func RegisterCanvasForObject(obj core.CanvasObject, c core.Canvas, setup func()) CanvasRegistration
RegisterCanvasForObject is SetCanvasForObject, and returns the entry the map holds for obj afterwards.
func (CanvasRegistration) Current ¶ added in v1.2.0
func (r CanvasRegistration) Current(c core.Canvas) bool
Current reports whether the entry still maps its object to c and has not expired. Such an entry cannot have been deleted: Clean deletes only entries that expired before the clock sample it cuts off at, which is never later than the one read here, and CleanCanvas only the entries of a canvas being closed, whose walks end with it. Nor replaced: moving an object to another canvas expires the entry it replaces.
type FontCacheEntry ¶
type FontCacheEntry struct {
Canvas core.Canvas
Color color.Color
// contains filtered or unexported fields
}
FontCacheEntry is the cache key for rendered text textures.
type TextureType ¶
type TextureType = uint32
TextureType is an opaque WebGPU texture handle under the `webgpu` build: a uint32 registry key into the webgpu painter's texture table (internal/painter/ webgpu/texture.go), used uniformly on every platform (desktop/wasm/mobile) instead of the GL-specific gl.Texture types. The desktop GL path already used uint32 here, so this only changes wasm/mobile webgpu builds.
func GetTextTexture ¶
func GetTextTexture(ent FontCacheEntry) (TextureType, bool)
GetTextTexture gets cached texture for a text run.
func GetTexture ¶
func GetTexture(obj core.CanvasObject) (TextureType, bool)
GetTexture gets cached texture.