Documentation
¶
Overview ¶
Package graphics is the meui drawing seam: meui-owned value types, a Paint, and a Canvas facade. Toolkit packages depend on this package rather than on the renderer that backs it, so a second backend can be supplied without touching widget code.
Neutral-type migration (P1) is in progress. Color, Point, Rect, Size, Matrix and Paint are meui-owned here. Path and Image are still aliases to the mobilegles types and become owned interfaces when the Canvas facade is split over a Device (P1b-3); until then the conversions below are how the seam talks to the renderer.
Index ¶
- Variables
- func BlurHorizontal(pix []uint32, w, h int)
- func BlurVertical(pix []uint32, w, h int)
- func CaptureOffscreen(dev Device, width, height int, draw func(*Canvas), done func(*image.NRGBA))
- func MaskRoundedCorners(pix []uint32, w, h int, radius float32)
- func NeedsShaping(text string) bool
- func NewSoftDevice(w, h int) *softDevice
- func RegisterDeviceFactory(f func(width, height float32) Device)
- func RegisterFontFamily(family, path string, w weight.Enum, sl slant.Enum) error
- func RegisteredFamilies() []string
- func RenderShapedText(text string, f Font, col uint32) (*image.RGBA, bool)
- func SetShapedTextSupport(on bool)
- func ShapedTextEnabled() bool
- func ShouldShapeText(text string) bool
- func WeightEnum(w int) weight.Enum
- type BackdropBlurrer
- type BlendMode
- type Canvas
- func (c *Canvas) BlurBackdrop(r Rect, cornerRadius float32) bool
- func (c *Canvas) Clear(col uint32)
- func (c *Canvas) ClearWithViewport(col uint32, x, y, w, h int32)
- func (c *Canvas) ClipBounds() Rect
- func (c *Canvas) ClipDepth() int
- func (c *Canvas) ClipPath(path *Path) bool
- func (c *Canvas) ClipRect(rect Rect, _ pathop.Enum, _ bool)
- func (c *Canvas) Device() Device
- func (c *Canvas) DrawArc(rect Rect, start, sweep float32, paint *Paint)
- func (c *Canvas) DrawCircle(cx, cy, r float32, paint *Paint)
- func (c *Canvas) DrawDashedLine(x1, y1, x2, y2 float32, dash []float32, phase float32, paint *Paint)
- func (c *Canvas) DrawImageInRect(img *Image, rect Rect, _ *Image, paint *Paint)
- func (c *Canvas) DrawImageRectInRect(img *Image, _, dst Rect, _ *Image, paint *Paint)
- func (c *Canvas) DrawLine(x1, y1, x2, y2 float32, paint *Paint)
- func (c *Canvas) DrawOval(rect Rect, paint *Paint)
- func (c *Canvas) DrawPath(path *Path, paint *Paint)
- func (c *Canvas) DrawRect(rect Rect, paint *Paint)
- func (c *Canvas) DrawRoundedRect(rect Rect, rx, ry float32, paint *Paint)
- func (c *Canvas) DrawSimpleString(s string, x, y float32, font Font, paint *Paint)
- func (c *Canvas) DrawText(text string, x, y float32, font Font, p *Paint)
- func (c *Canvas) DropShadow(rect Rect, paint *Paint, offsetX, offsetY, radius float32)
- func (c *Canvas) Height() float32
- func (c *Canvas) IsClipEmpty() bool
- func (c *Canvas) Origin() (float32, float32)
- func (c *Canvas) QuickRejectRect(r Rect) bool
- func (c *Canvas) ResetClip()
- func (c *Canvas) Restore()
- func (c *Canvas) RestoreToCount(n int)
- func (c *Canvas) Rotate(degrees float32)
- func (c *Canvas) Save()
- func (c *Canvas) SaveAndRestore(fn func())
- func (c *Canvas) Scale(x, y float32)
- func (c *Canvas) Skew(kx, ky float32)
- func (c *Canvas) Translate(x, y float32)
- func (c *Canvas) Width() float32
- func (c *Canvas) WithClip(rect Rect, fn func(*Canvas))
- type Color
- type Device
- type Font
- type FontDescriptor
- type FontFace
- type FontFaceDescriptor
- type FontImpl
- func (f *FontImpl) Baseline() float32
- func (f *FontImpl) Descriptor() FontDescriptor
- func (f *FontImpl) Face() *FontFace
- func (f *FontImpl) Family() string
- func (f *FontImpl) Font() *truetype.Font
- func (f *FontImpl) FontFace() *FontFace
- func (f *FontImpl) ForText(text string) Font
- func (f *FontImpl) LineHeight() float32
- func (f *FontImpl) PositionedGlyphs(text string) ([]PositionedGlyph, float32, bool)
- func (f *FontImpl) RasterSize() float32
- func (f *FontImpl) ShapedCaretX(text string, byteOffset int) (float32, bool)
- func (f *FontImpl) ShapedIndexAtX(text string, x float32) (int, bool)
- func (f *FontImpl) ShapedText(text string) ([]textshape.Run, error)
- func (f *FontImpl) ShapedTextDir(text string, dir textshape.Direction) ([]textshape.Run, error)
- func (f *FontImpl) ShapedWidth(text string) (float32, bool)
- func (f *FontImpl) SimpleWidth(text string) float32
- func (f *FontImpl) Size() float32
- func (f *FontImpl) Source() []byte
- func (f *FontImpl) Synthetic() (bold, italic bool)
- func (f *FontImpl) TextWidth(text string) float32
- func (f *FontImpl) TruetypeFace() *truetype.Font
- type Gradient
- type GradientKind
- type GradientStop
- type Image
- func NewImage(rgba []uint32, w, h int32) *Image
- func NewImageFromBytes(data []byte) (*Image, error)
- func NewImageFromDrawing(dev Device, width, height, ppi int, draw func(*Canvas)) (*Image, error)
- func NewImageFromFilePathOrURL(filePathOrURL string, scale float32) (*Image, error)
- func NewImageFromRGBA(rgba []byte, w, h int) (*Image, error)
- func (i *Image) Bounds() Rect
- func (i *Image) Height() int32
- func (i *Image) LogicalSize() Size
- func (i *Image) PixelAt(x, y int) Color
- func (i *Image) Pixels() []uint32
- func (i *Image) PutImage(src *Image, dx, dy int)
- func (i *Image) Scaled(scale float32) *Image
- func (i *Image) SetPixel(x, y int, c Color)
- func (i *Image) SetPixels(pix []uint32)
- func (i *Image) ToPNG(compressionLevel int) ([]byte, error)
- func (i *Image) Width() int32
- type Ink
- type Matrix
- type Paint
- func (p *Paint) Antialias() bool
- func (p *Paint) BlendMode() BlendMode
- func (p *Paint) ClearGradient()
- func (p *Paint) Color() Color
- func (p *Paint) GlobalAlpha() float32
- func (p *Paint) Gradient() Gradient
- func (p *Paint) MiterLimit() float32
- func (p *Paint) SetAntialias(on bool)
- func (p *Paint) SetBlendMode(m BlendMode)
- func (p *Paint) SetColor(c Color)
- func (p *Paint) SetConicGradient(center Point, startAngle float32, stops []GradientStop)
- func (p *Paint) SetGlobalAlpha(a float32)
- func (p *Paint) SetGradient(g Gradient)
- func (p *Paint) SetLinearGradient(start, end Point, stops []GradientStop)
- func (p *Paint) SetMiterLimit(limit float32)
- func (p *Paint) SetRadialGradient(center Point, radius float32, stops []GradientStop)
- func (p *Paint) SetStrokeCap(c StrokeCap)
- func (p *Paint) SetStrokeJoin(j StrokeJoin)
- func (p *Paint) SetStrokeWidth(w float32)
- func (p *Paint) SetStyle(style int32)
- func (p *Paint) StrokeCap() StrokeCap
- func (p *Paint) StrokeJoin() StrokeJoin
- func (p *Paint) StrokeWidth() float32
- func (p *Paint) Style() int32
- type Path
- type PathOp
- type PathOpKind
- type Point
- type PositionedGlyph
- type Rect
- type Size
- type StrokeCap
- type StrokeJoin
- type SystemFontInfo
- type TestDevice
- func (d *TestDevice) Clear(col uint32)
- func (d *TestDevice) ClearWithViewport(col uint32, x, y, w, h int32)
- func (d *TestDevice) ClipBounds() Rect
- func (d *TestDevice) ClipDepth() int
- func (d *TestDevice) ClipPath(path *Path) bool
- func (d *TestDevice) ClipRect(r Rect)
- func (d *TestDevice) Count(op string) int
- func (d *TestDevice) DrawArc(x, y, w, h, start, sweep float32, p *Paint)
- func (d *TestDevice) DrawCircle(cx, cy, r float32, p *Paint)
- func (d *TestDevice) DrawDashedLine(x1, y1, x2, y2 float32, dash []float32, phase float32, p *Paint)
- func (d *TestDevice) DrawImage(img *Image, r Rect, p *Paint)
- func (d *TestDevice) DrawLine(x1, y1, x2, y2 float32, p *Paint)
- func (d *TestDevice) DrawOval(x, y, w, h float32, p *Paint)
- func (d *TestDevice) DrawPath(path *Path, p *Paint)
- func (d *TestDevice) DrawRect(x, y, w, h float32, p *Paint)
- func (d *TestDevice) DrawRoundedRect(r Rect, rx, ry float32, p *Paint)
- func (d *TestDevice) DrawSimpleString(text string, x, y float32, f Font, p *Paint)
- func (d *TestDevice) DrawText(text string, x, y float32, f Font, p *Paint)
- func (d *TestDevice) DropShadow(r Rect, p *Paint, dx, dy, radius float32)
- func (d *TestDevice) GetMatrix() Matrix
- func (d *TestDevice) Height() float32
- func (d *TestDevice) IsClipEmpty() bool
- func (d *TestDevice) QuickRejectRect(r Rect) bool
- func (d *TestDevice) RenderOffscreen(width, height int, draw func(*Canvas)) (*Image, error)
- func (d *TestDevice) ResetClip()
- func (d *TestDevice) Restore()
- func (d *TestDevice) RestoreToCount(n int)
- func (d *TestDevice) Rotate(deg float32)
- func (d *TestDevice) Save() int
- func (d *TestDevice) Scale(sx, sy float32)
- func (d *TestDevice) Skew(kx, ky float32)
- func (d *TestDevice) TransformRect(x, y, w, h float32) (float32, float32, float32, float32)
- func (d *TestDevice) Translate(dx, dy float32)
- func (d *TestDevice) Width() float32
- type Text
- type TextDecoration
Constants ¶
This section is empty.
Variables ¶
var ErrNoOffscreen = errors.New("graphics: offscreen rendering unavailable")
Device is the complete backend contract the seam draws through. A Device owns the surface, the transform/clip state stack and every draw operation; Canvas is a thin facade over one, so the toolkit never names a backend.
This is P1's L1 seam (design §5.2). It is deliberately shaped around what the toolkit actually calls rather than around any one renderer: the used surface is ~25 operations, which is what makes a second backend feasible. ErrNoOffscreen reports that no backend is installed or that it cannot render to an offscreen surface.
var MonospacedFont = SystemFont
MonospacedFont falls back to SystemFont; core has no monospace distinction.
Functions ¶
func BlurHorizontal ¶ added in v0.5.5
Renderer adapters that need the same blur kernel as the software device use these wrappers; the seam keeps the implementation private.
func BlurVertical ¶ added in v0.5.5
func CaptureOffscreen ¶
CaptureOffscreen renders draw into an offscreen surface on dev and hands the pixels to done as a composited NRGBA image. A nil device or a backend that cannot render offscreen simply produces nothing, matching the previous behaviour when the renderer had no context.
func MaskRoundedCorners ¶ added in v0.5.5
func NeedsShaping ¶ added in v0.5.19
NeedsShaping reports whether text contains a non-ASCII rune. The default gate keeps Latin metrics on the existing path while complex scripts use the shaped engine; MEUI_SHAPED_TEXT=1 forces shaping for every string.
func NewSoftDevice ¶
func NewSoftDevice(w, h int) *softDevice
NewSoftDevice returns a software device of the given size. The pixels are white-transparent until something clears them.
func RegisterDeviceFactory ¶ added in v0.5.5
RegisterDeviceFactory installs the process-wide renderer-backed Device. A backend calls this once during initialization.
func RegisterFontFamily ¶
RegisterFontFamily parses a TTF and registers it under family at a weight and slant. An empty family uses the font's own name table. OTF is not accepted: the parser this tree uses cannot read it (that is a separate gap, recorded in WEB.md).
func RegisteredFamilies ¶
func RegisteredFamilies() []string
RegisteredFamilies lists the app-supplied families, sorted.
func RenderShapedText ¶ added in v0.5.21
RenderShapedText rasterizes a shaped line into a transparent RGBA image. It is the shared bridge for backends that present text as a texture (SDL GPU) instead of drawing glyph quads. Coordinates are pen-relative, with the baseline at y=em.
func SetShapedTextSupport ¶ added in v0.5.19
func SetShapedTextSupport(on bool)
SetShapedTextSupport enables the default shaped path for backends that can draw glyph IDs. It is additive with MEUI_SHAPED_TEXT=1; a backend without glyph-run rendering leaves it false so layout and drawing stay rune-based.
func ShapedTextEnabled ¶ added in v0.5.19
func ShapedTextEnabled() bool
ShapedTextEnabled reports whether shaped layout/drawing is active.
func ShouldShapeText ¶ added in v0.5.19
ShouldShapeText is the default draw/layout decision for a string.
func WeightEnum ¶
WeightEnum maps a CSS-style numeric weight (100..900) to the face-weight enum. It is the ONE mapping: the QML `font.weight` handler and the theme presets both call it, so a 600 cannot mean "semibold" in a scene and "bold" in a preset.
Types ¶
type BackdropBlurrer ¶
BackdropBlurrer is implemented by devices that can blur what they have already painted — the frosted-glass operation. The GL device does it through its blur FBO, the software device with the same 7-tap kernel (see softdevice_blur.go).
type BlendMode ¶
type BlendMode int
BlendMode selects how a draw composites with what is already there.
const ( BlendModeNormal BlendMode = iota BlendModeMultiply BlendModeScreen BlendModeOverlay BlendModeDarken BlendModeLighten BlendModeColorDodge BlendModeColorBurn BlendModeHardLight BlendModeSoftLight BlendModeDifference BlendModeExclusion BlendModeHue BlendModeSaturation BlendModeColor BlendModeLuminosity )
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is the drawing facade the toolkit paints through. It holds a Device and owns no backend state of its own, so swapping the Device swaps the renderer without touching a single widget call site.
func NewSoftwareCanvas ¶
NewSoftwareCanvas returns a Canvas drawing into a fresh software surface of the given size, plus the device so the caller can take its pixels. Callers use it to rasterise a widget on the CPU - the same draw code, a different canvas.
func (*Canvas) BlurBackdrop ¶
BlurBackdrop blurs the painted surface inside r and composites it back, masked to a rounded rect of cornerRadius (0 is a plain rectangle). It reports false when the device has no blur path, so a widget can fall back to a plain translucent fill instead of drawing nothing.
func (*Canvas) ClearWithViewport ¶
func (*Canvas) ClipBounds ¶
ClipBounds is the clip in force, in device space.
func (*Canvas) ClipPath ¶
ClipPath intersects the clip with the interior of path, transformed by the current matrix like every other local-space draw call. Exact for convex outlines; a concave outline clips to its bounding rectangle (a superset) and returns false.
func (*Canvas) DrawCircle ¶
DrawCircle: meui signature (cx, cy, r float32, paint *Paint).
func (*Canvas) DrawDashedLine ¶
func (c *Canvas) DrawDashedLine(x1, y1, x2, y2 float32, dash []float32, phase float32, paint *Paint)
DrawDashedLine: meui signature (x1, y1, x2, y2, dash, phase, paint).
func (*Canvas) DrawImageInRect ¶
DrawImageInRect accepts the meui (img, rect, sampling, paint) signature. sampling is ignored.
func (*Canvas) DrawImageRectInRect ¶
DrawImageRectInRect: approximation, ignores srcRect and sampling.
func (*Canvas) DrawRoundedRect ¶
DrawRoundedRect: meui signature (rect Rect, rx, ry float32, paint *Paint).
func (*Canvas) DrawSimpleString ¶
DrawSimpleString: meui signature (s string, x, y float32, font Font, paint *Paint).
func (*Canvas) DrawText ¶
DrawText: meui signature (s string, x, y float32, font Font, paint *Paint).
func (*Canvas) DropShadow ¶
DropShadow: meui signature (rect Rect, paint *Paint, offsetX, offsetY, radius float32).
func (*Canvas) IsClipEmpty ¶
IsClipEmpty reports a clip that admits nothing — which is NOT the same as a clip covering the whole surface, and is what a widget checks before drawing at all.
func (*Canvas) QuickRejectRect ¶
QuickRejectRect reports whether a rect lies entirely outside the clip, so a widget drawing many items can skip the ones that cannot be seen. It is a conservative test: false only means "not provably invisible".
func (*Canvas) RestoreToCount ¶
func (*Canvas) SaveAndRestore ¶
func (c *Canvas) SaveAndRestore(fn func())
func (*Canvas) WithClip ¶
ClipRect: meui passes (rect, pathop, antialias). The rect is in the canvas's LOCAL (user) space, exactly like every other draw call, so it is transformed by the current matrix before becoming a device clip. (The shim previously mistook the antialias flag for a "local" toggle and skipped the transform, clipping widgets at their untranslated positions.) WithClip draws with a clip and restores the previous one, whatever fn does.
It is the transaction form of ClipRect, and it exists because the manual form leaks: the historic TextField bug was a paint that pushed a clip and never popped it, poisoning everything painted after it in that frame. A defer cannot be forgotten, so prefer this to Save/ClipRect/Restore.
type Color ¶
type Color uint32
Color is a meui-owned 0xAARRGGBB colour. It is deliberately kept as a scalar with the same encoding: the toolkit uses raw colour literals throughout and compares them to untyped constants.
func ARGB ¶
ARGB matches the reference signature: alpha as a 0.0–1.0 float and red/green/blue as 0–255 ints. mobilegles has only uint8 RGBA, so scale alpha to 0–255 and clamp.
func ColorDecode ¶
ColorDecode parses CSS-style color strings: hex (#RGB, #RRGGBB), rgb(r,g,b), rgba(r,g,b,a), or named colors. This is a partial implementation of the reference ColorDecode.
type Device ¶
type Device interface {
// Surface
Width() float32
Height() float32
Clear(col uint32)
ClearWithViewport(col uint32, x, y, w, h int32)
// Transform and clip state
Save() int
Restore()
RestoreToCount(n int)
Translate(dx, dy float32)
Scale(sx, sy float32)
Rotate(deg float32)
Skew(kx, ky float32)
GetMatrix() Matrix
TransformRect(x, y, w, h float32) (float32, float32, float32, float32)
ClipRect(r Rect)
// ClipPath intersects the clip with the interior of path. It reports
// whether the clip is exact: a concave or over-complex outline falls back
// to its bounding rectangle (a superset, so nothing is hidden) and returns
// false.
ClipPath(path *Path) bool
ResetClip()
ClipDepth() int
// ClipBounds is the clip in force, in device space. A widget that draws many
// items uses it with QuickRejectRect to skip what cannot be seen.
ClipBounds() Rect
// IsClipEmpty reports a clip that admits nothing, which is different from a
// clip that happens to be the whole surface.
IsClipEmpty() bool
// QuickRejectRect reports whether a rect lies entirely outside the clip.
QuickRejectRect(r Rect) bool
// Drawing
DrawRect(x, y, w, h float32, p *Paint)
DrawRoundedRect(r Rect, rx, ry float32, p *Paint)
DrawCircle(cx, cy, r float32, p *Paint)
DrawOval(x, y, w, h float32, p *Paint)
DrawArc(x, y, w, h, start, sweep float32, p *Paint)
DrawLine(x1, y1, x2, y2 float32, p *Paint)
DrawDashedLine(x1, y1, x2, y2 float32, dash []float32, phase float32, p *Paint)
DrawPath(path *Path, p *Paint)
DrawImage(img *Image, r Rect, p *Paint)
DrawText(text string, x, y float32, f Font, p *Paint)
DrawSimpleString(text string, x, y float32, f Font, p *Paint)
DropShadow(r Rect, p *Paint, dx, dy, radius float32)
// RenderOffscreen draws into a separate surface and returns it. Widget
// caches and screenshot paths use this, so the backend owns offscreen
// creation instead of the seam reaching for a renderer.
RenderOffscreen(width, height int, draw func(*Canvas)) (*Image, error)
}
type Font ¶
type Font = *FontImpl
Font is an alias for *FontImpl. It is shaped as a pointer so a zero value of Font is a nil pointer (matching the reference Font interface zero-value semantics) and `Font: nil` works in struct literals.
var SystemFont Font = wrapSystemFont()
SystemFont is pre-allocated to a Font wrapping the resolved system face. It may be nil if no system font is loaded.
func ReloadSystemFont ¶
func ReloadSystemFont() Font
ReloadSystemFont re-resolves SystemFont (and MonospacedFont) from the platform's CURRENT system font.
SystemFont is resolved once, at package init, and a widget captures the face it was built with — so installing a font later changed the underlying face without changing anything an app could see. That made LoadFontFace, which is documented as the way to ship your own UI font, silently ineffective: text already laid out kept the old glyphs and the theme kept pointing at them, with no error anywhere.
Changing a font at runtime needs both halves: this re-resolves the font, and theme.UseSystemFont makes the theme use it. Neither package can do the other's half, because theme imports graphics and not the reverse.
type FontDescriptor ¶
type FontDescriptor struct {
Family string
Weight weight.Enum
Spacing spacing.Enum
Slant slant.Enum
Size float32
Face *truetype.Font // concrete face; nil = resolve by family
}
FontDescriptor describes a font by family, weight, spacing, slant, and size. Calling .Font() produces a Font at the given size, with the requested weight/spacing/slant baked in.
func (*FontDescriptor) Font ¶
func (fd *FontDescriptor) Font() Font
Font returns a Font of the given size based on this descriptor.
type FontFace ¶
type FontFace struct {
Weight weight.Enum
Spacing spacing.Enum
Slant slant.Enum
// Synthetic styles for faces without real bold/italic companions
// (rasterized emboldened/sheared — Skia-style synthesis).
SyntheticBold bool
SyntheticItalic bool
// contains filtered or unexported fields
}
FontFace is our own FontFace type. It carries a descriptor; calling Font(size) produces a Font at the given size. Family is exposed via the Family() method, not a field, to match the reference FontFace API. face, when non-nil, is the concrete truetype font the family resolved to (embedded Roboto faces); nil means "use the system font".
func LoadFontFace ¶
LoadFontFace loads a truetype/otf font from path and returns a FontFace for it — lets applications ship their own UI fonts (e.g. fonts/InterDisplay-Regular.otf) instead of falling through the system-font candidate list.
func MatchFontFace ¶
MatchFontFace resolves a family/style to a concrete font face. Reference parity: only the embedded Roboto family resolves (the reference embeds Roboto and, unlike skia's font manager here, we do not fall back to arbitrary system fonts); unknown families return nil so callers fall back exactly like production.
func (*FontFace) Face ¶
Face returns this descriptor as a *FontFace. Used in code that iterates over `[]FontFaceDescriptor` and rebuilds fonts at a new size: `for _, fd := range all { f := fd.Face().Font(size) }`.
func (*FontFace) Family ¶
Family returns the family name. Method form (mirrors the reference FontFace.Family()).
type FontFaceDescriptor ¶
type FontFaceDescriptor = FontFace
FontFaceDescriptor is a placeholder for compatibility.
func AllFontFaces ¶
func AllFontFaces() (all, monospaced []FontFaceDescriptor)
type FontImpl ¶
type FontImpl struct {
// contains filtered or unexported fields
}
FontImpl is our own Font type. It holds font metadata and the parsed face; a renderer adapter builds its glyph engine from Descriptor/RasterSize.
func (*FontImpl) Descriptor ¶
func (f *FontImpl) Descriptor() FontDescriptor
func (*FontImpl) Face ¶
Face returns a FontFace descriptor for this font. Used to re-create the font at a different size. Carries the resolved truetype face so re-created fonts rasterize with the same family (reference parity — dropping it silently swapped the family for the system font).
func (*FontImpl) Font ¶
Font returns the underlying *truetype.Font. Matches the reference Font interface signature so meui code that does `meuishim.MonospacedFont.Font.Face()` works as if it were the truetype face. nil if no truetype face is available.
func (*FontImpl) FontFace ¶
FontFace returns a descriptor for this font. Used for re-creating the font at a different size.
func (*FontImpl) ForText ¶ added in v0.5.24
ForText returns a Font that can draw every rune in text. The primary face is used when it covers the string; otherwise the discovered system face is tried as a whole-string fallback. Per-script face fallback would need a font map, but this removes the tofu boxes a single-script font produced for mixed text.
func (*FontImpl) LineHeight ¶
func (*FontImpl) PositionedGlyphs ¶ added in v0.5.19
func (f *FontImpl) PositionedGlyphs(text string) ([]PositionedGlyph, float32, bool)
PositionedGlyphs lays a single line out in visual slots. It is the bridge software and GPU renderers use so they all walk the same bidi order.
func (*FontImpl) RasterSize ¶ added in v0.5.5
RasterSize is the fitted em size the renderer uses to build its glyph atlas. It is exported for backend adapters; widgets use Size/Baseline.
func (*FontImpl) ShapedCaretX ¶ added in v0.5.16
ShapedCaretX returns the x offset of the caret before byteOffset in text. Mixed-direction runs are placed with the UAX #9 L2 visual order, so this is not limited to all-LTR or all-RTL lines.
func (*FontImpl) ShapedIndexAtX ¶ added in v0.5.16
ShapedIndexAtX is the inverse of ShapedCaretX: the byte offset whose caret is nearest x.
func (*FontImpl) ShapedText ¶ added in v0.5.10
ShapedText shapes text with the canonical textshape engine at this font's em size. The result is for measurement/selection and the future glyph-ID draw path; renderers still draw runes until TEXT-3 is wired.
func (*FontImpl) ShapedTextDir ¶ added in v0.5.10
ShapedTextDir is ShapedText with an explicit paragraph direction.
func (*FontImpl) ShapedWidth ¶ added in v0.5.14
ShapedWidth returns the widest shaped line, or false when the font has no retained source. It is the measurement half of the shaped draw path, so enabling MEUI_SHAPED_TEXT keeps label sizing and glyph placement agreeing.
func (*FontImpl) SimpleWidth ¶
SimpleWidth is an alias for TextWidth.
func (*FontImpl) Source ¶ added in v0.5.13
Source returns the raw TTF this face was parsed from, when the loader retained it. It is for shaping bridges; callers must not modify it.
func (*FontImpl) Synthetic ¶
Synthetic reports whether the face lacks real bold/italic and the atlas synthesizes them (raster embolden/shear).
func (*FontImpl) TruetypeFace ¶
TruetypeFace returns the underlying truetype font face, or nil.
type Gradient ¶
type Gradient struct {
Kind GradientKind
Stops []GradientStop
Start Point
End Point
// Center/Radius serve GradientRadial and GradientConic; Radius is unused by
// the conic form, which uses StartAngle.
Center Point
Radius float32
StartAngle float32
}
Gradient is a meui-owned multi-stop gradient. Exactly one geometry applies, chosen by Kind:
GradientLinear: the ramp runs from Start to End. GradientRadial: the ramp runs from Center out to Radius. GradientConic: the ramp sweeps around Center from StartAngle degrees.
type GradientKind ¶
type GradientKind int
GradientKind selects a gradient's geometry.
const ( GradientNone GradientKind = iota GradientLinear GradientRadial GradientConic )
type GradientStop ¶
GradientStop is one colour stop at Offset (0..1) along the gradient.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is meui-owned: it holds the pixel buffer and dimensions, and the backend image is built from it on demand. A Device therefore never has to be handed a renderer object by the caller.
func NewImageFromBytes ¶
NewImageFromBytes decodes PNG, JPEG or GIF bytes into an image.
The result is premultiplied, which is the seam's image convention: an Image is handed to the backend as premultiplied pixels (offscreen readbacks already are, and decoded straight-alpha data is premultiplied here so both kinds composite identically).
func NewImageFromDrawing ¶
NewImageFromDrawing renders draw into an offscreen surface belonging to dev and returns the result. The backend owns offscreen creation, so the seam never reaches for a renderer itself.
func NewImageFromFilePathOrURL ¶
NewImageFromFilePathOrURL loads an image from a filesystem path.
Remote URLs are deliberately NOT fetched: the drawing seam performs no network I/O. Fetch the bytes with whatever HTTP client the app already uses and pass them to NewImageFromBytes.
scale resamples the decoded image (bilinear); 0 and 1 mean "as decoded".
func NewImageFromRGBA ¶
The display path for a rendered buffer: sRGB-encoded RGBA8 in, a graphics.Image out.
It exists because the two sides disagree about three things at once, and every caller getting all three right by hand is not a reasonable thing to ask:
- Alpha: the 8-bit world (PNG, JPEG, a document's display buffer) carries STRAIGHT alpha, and the seam's word is PREMULTIPLIED, so each pixel is premultiplied exactly once here.
- Order: the seam stores pixels BOTTOM-UP, like the GL readbacks the renderer already feeds it, while a decoded or rendered buffer arrives TOP-DOWN, so the rows are flipped on the way in.
- Packing: the seam's word is 0xAARRGGBB.
Getting any one of them wrong produces a picture that looks plausible — a subtly dark image, an upside-down one, or red and blue swapped — which is exactly why this is one function rather than a paragraph of instructions.
func (*Image) LogicalSize ¶
LogicalSize returns the dimensions as a seam Size, for layout.
func (*Image) PixelAt ¶
PixelAt returns the pixel at (x, y), in TOP-LEFT image coordinates, with straight alpha (the inverse of the premultiplication SetPixel applies). Out-of-range reads return a fully transparent colour.
func (*Image) PutImage ¶
PutImage copies src over the receiver with its top-left corner at (dx, dy) — the canvas putImageData operation. Both images are premultiplied, so the copy is a straight blit; the parts of src that fall outside the receiver are dropped and the backend texture is marked stale.
func (*Image) Scaled ¶
Scaled returns a bilinear resample of the image. A scale of 0 or 1 returns the receiver unchanged. Interpolating premultiplied pixels is the correct way to resample alpha-carrying content.
func (*Image) SetPixel ¶
SetPixel writes c at (x, y), given in TOP-LEFT image coordinates, and marks the backend texture stale so the next draw re-uploads it. c is straight alpha and is premultiplied here; writes outside the image are ignored.
func (*Image) SetPixels ¶
SetPixels replaces the image's pixel buffer in place, for a buffer that is re-rendered on the same surface (a cached layer). The dimensions must match: the backend keeps one texture per image, and swapping a different-sized buffer under it would re-upload at the wrong extent. The next draw re-uploads.
type Ink ¶
Ink is anything that can produce a Paint for a rect. It is meui-owned — no backend type appears in the signature. Color satisfies it, which is what TextDecoration.OnBackgroundInk is normally set to.
type Paint ¶
type Paint struct {
// contains filtered or unexported fields
}
Paint is a meui-owned draw state. Its fields stay unexported and are read/written through methods, matching the call sites the toolkit already uses; the renderer's own paint is built lazily behind it.
func NewPaint ¶
func NewPaint() *Paint
NewPaint returns a paint with the same defaults the renderer uses: opaque white, filled, 1px stroke, butt caps, miter joins (limit 4), antialiased, fully opaque, normal blend.
func (*Paint) ClearGradient ¶
func (p *Paint) ClearGradient()
func (*Paint) GlobalAlpha ¶
func (*Paint) MiterLimit ¶
func (*Paint) SetAntialias ¶
SetAntialias turns edge antialiasing on or off for this paint. Text and images are unaffected: they sample a texture and have no edge ramp.
func (*Paint) SetBlendMode ¶
func (*Paint) SetConicGradient ¶
func (p *Paint) SetConicGradient(center Point, startAngle float32, stops []GradientStop)
SetConicGradient sets a multi-stop gradient sweeping around center from startAngle degrees.
func (*Paint) SetGlobalAlpha ¶
SetGlobalAlpha multiplies the alpha of everything this paint draws, on top of the colour's own alpha. Values outside 0..1 are clamped; 1 is no modulation. Unlike SetAntialias this applies to text and images too.
func (*Paint) SetGradient ¶
SetGradient replaces the paint's gradient wholesale.
func (*Paint) SetLinearGradient ¶
func (p *Paint) SetLinearGradient(start, end Point, stops []GradientStop)
SetLinearGradient sets a multi-stop gradient running start→end.
func (*Paint) SetMiterLimit ¶
SetMiterLimit sets how far a miter join may spike, in multiples of half the stroke width, before it is beveled. Values <= 0 restore the default of 4.
func (*Paint) SetRadialGradient ¶
func (p *Paint) SetRadialGradient(center Point, radius float32, stops []GradientStop)
SetRadialGradient sets a multi-stop gradient running from center out to radius.
func (*Paint) SetStrokeCap ¶
func (*Paint) SetStrokeJoin ¶
func (p *Paint) SetStrokeJoin(j StrokeJoin)
func (*Paint) SetStrokeWidth ¶
func (*Paint) StrokeJoin ¶
func (p *Paint) StrokeJoin() StrokeJoin
func (*Paint) StrokeWidth ¶
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
func (*Path) CubicTo ¶
CubicTo adds a cubic bezier segment from the current point through the two controls to end. A Device flattens it into whatever its rasterizer supports.
type PathOp ¶
type PathOp struct {
Kind PathOpKind
P0, P1 Point
P2 Point
}
PathOp is one recorded path operation. P0 is the control point for PathQuadTo and the target for the others; for PathQuadTo P1 is the end point, and for PathCubicTo P0/P1 are the two controls and P2 the end.
type PathOpKind ¶
type PathOpKind uint8
Path is meui-owned pure data: it records the ops the caller issues, and a Device replays them into whatever path representation the backend uses. No renderer type is involved, which is what lets a second backend render paths.
const ( PathMoveTo PathOpKind = iota PathLineTo PathQuadTo PathCubicTo PathClose )
type Point ¶
type Point struct{ X, Y float32 }
Point, Rect, Size and Matrix are plain meui-owned value types. The toolkit only ever reads their fields, so they carry no geometry methods.
type PositionedGlyph ¶ added in v0.5.19
PositionedGlyph is one shaped glyph at a pen-relative x offset. Y is the shaping offset from the baseline; callers add the baseline themselves.
type Rect ¶
type Rect struct{ X, Y, Width, Height float32 }
func (Rect) Intersects ¶
Intersects reports whether the rectangles overlap. Kept on the owned type because the toolkit uses it (debug tree layout).
type StrokeJoin ¶
type StrokeJoin int
StrokeJoin is the line-join style for stroked draws.
const ( StrokeJoinMiter StrokeJoin = iota StrokeJoinRound StrokeJoinBevel )
type SystemFontInfo ¶
type SystemFontInfo struct {
Family string // family name from the font's name table
Path string // font file to load with LoadFontFace
}
SystemFontInfo describes one discovered outline font family.
func ListSystemFonts ¶
func ListSystemFonts(extraDirs ...string) []SystemFontInfo
ListSystemFonts scans the standard font directories (plus any extra dirs, e.g. an app's bundled fonts/) and returns one entry per family. When several faces share a family the "Regular" file wins. Family names come from each font's name table; unparseable files are skipped. The result is scanned once and cached — the first call reads every font file, so call it before the UI is shown.
type TestDevice ¶
type TestDevice struct {
// Calls counts operations by name.
Calls map[string]int
// Total is the number of recorded operations.
Total int
// LastText and LastRect capture the most recent text/rect arguments, and
// LastBlend/LastMiterLimit/LastAntialias the paint state of the most recent
// stroke, so a test can prove the paint reaches the device rather than
// being stored and ignored.
LastText string
LastRect Rect
LastBlend BlendMode
LastMiterLimit float32
LastAntialias bool
LastGlobalAlpha float32
// LastClipPathOps is the op count of the most recent ClipPath, so a test can
// prove the path reached the device.
LastClipPathOps int
// contains filtered or unexported fields
}
TestDevice is a recording, drawing-free Device. It covers the seam with a second backend: every operation is counted and the transform/clip stack is emulated so a Canvas over it behaves plausibly. Widget tests paint through it, which proves the toolkit cannot depend on renderer behaviour.
func NewTestDevice ¶
func NewTestDevice(width, height float32) *TestDevice
NewTestDevice returns a recording Device with the given surface size.
func (*TestDevice) Clear ¶
func (d *TestDevice) Clear(col uint32)
func (*TestDevice) ClearWithViewport ¶
func (d *TestDevice) ClearWithViewport(col uint32, x, y, w, h int32)
func (*TestDevice) ClipBounds ¶
func (d *TestDevice) ClipBounds() Rect
func (*TestDevice) ClipDepth ¶
func (d *TestDevice) ClipDepth() int
func (*TestDevice) ClipPath ¶
func (d *TestDevice) ClipPath(path *Path) bool
func (*TestDevice) ClipRect ¶
func (d *TestDevice) ClipRect(r Rect)
func (*TestDevice) Count ¶
func (d *TestDevice) Count(op string) int
Count returns how many times an operation was recorded.
func (*TestDevice) DrawArc ¶
func (d *TestDevice) DrawArc(x, y, w, h, start, sweep float32, p *Paint)
func (*TestDevice) DrawCircle ¶
func (d *TestDevice) DrawCircle(cx, cy, r float32, p *Paint)
func (*TestDevice) DrawDashedLine ¶
func (d *TestDevice) DrawDashedLine(x1, y1, x2, y2 float32, dash []float32, phase float32, p *Paint)
func (*TestDevice) DrawLine ¶
func (d *TestDevice) DrawLine(x1, y1, x2, y2 float32, p *Paint)
func (*TestDevice) DrawOval ¶
func (d *TestDevice) DrawOval(x, y, w, h float32, p *Paint)
func (*TestDevice) DrawPath ¶
func (d *TestDevice) DrawPath(path *Path, p *Paint)
func (*TestDevice) DrawRect ¶
func (d *TestDevice) DrawRect(x, y, w, h float32, p *Paint)
func (*TestDevice) DrawRoundedRect ¶
func (d *TestDevice) DrawRoundedRect(r Rect, rx, ry float32, p *Paint)
func (*TestDevice) DrawSimpleString ¶
func (d *TestDevice) DrawSimpleString(text string, x, y float32, f Font, p *Paint)
func (*TestDevice) DrawText ¶
func (d *TestDevice) DrawText(text string, x, y float32, f Font, p *Paint)
func (*TestDevice) DropShadow ¶
func (d *TestDevice) DropShadow(r Rect, p *Paint, dx, dy, radius float32)
func (*TestDevice) GetMatrix ¶
func (d *TestDevice) GetMatrix() Matrix
func (*TestDevice) Height ¶
func (d *TestDevice) Height() float32
func (*TestDevice) IsClipEmpty ¶
func (d *TestDevice) IsClipEmpty() bool
func (*TestDevice) QuickRejectRect ¶
func (d *TestDevice) QuickRejectRect(r Rect) bool
func (*TestDevice) RenderOffscreen ¶
func (d *TestDevice) RenderOffscreen(width, height int, draw func(*Canvas)) (*Image, error)
RenderOffscreen runs draw against a fresh recording device so widgets still exercise their offscreen path, but reports failure: a drawing-free device cannot produce pixels. Callers already treat that as "no cache image".
func (*TestDevice) ResetClip ¶
func (d *TestDevice) ResetClip()
func (*TestDevice) Restore ¶
func (d *TestDevice) Restore()
func (*TestDevice) RestoreToCount ¶
func (d *TestDevice) RestoreToCount(n int)
func (*TestDevice) Rotate ¶
func (d *TestDevice) Rotate(deg float32)
func (*TestDevice) Save ¶
func (d *TestDevice) Save() int
func (*TestDevice) Scale ¶
func (d *TestDevice) Scale(sx, sy float32)
func (*TestDevice) Skew ¶
func (d *TestDevice) Skew(kx, ky float32)
func (*TestDevice) TransformRect ¶
TransformRect maps the rect's corners through the current matrix and returns their bounding box, matching what a device clip needs.
func (*TestDevice) Translate ¶
func (d *TestDevice) Translate(dx, dy float32)
func (*TestDevice) Width ¶
func (d *TestDevice) Width() float32
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a stub matching the reference Text API surface used by meui. A faithful implementation needs shaping, layout, and per-glyph metrics that mobilegles does not expose. Until then, Text.Draw forwards to Canvas.DrawText with the decoration's font.
func NewText ¶
func NewText(str string, decoration *TextDecoration) *Text
func (*Text) AddString ¶
func (t *Text) AddString(s string, dec *TextDecoration)
AddString appends a string with the given decoration. Stub: the meui code that uses it (markdown rendering) ignores the result for now.
type TextDecoration ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
enums
|
|
|
paintstyle
Package paintstyle mirrors the reference toolkit's paint-style enum.
|
Package paintstyle mirrors the reference toolkit's paint-style enum. |
|
pathop
Package pathop mirrors the reference toolkit's path-op enum.
|
Package pathop mirrors the reference toolkit's path-op enum. |
|
slant
Package slant mirrors the reference toolkit's slant enum.
|
Package slant mirrors the reference toolkit's slant enum. |
|
spacing
Package spacing mirrors the reference toolkit's spacing enum.
|
Package spacing mirrors the reference toolkit's spacing enum. |
|
weight
Package weight mirrors the reference toolkit's weight enum.
|
Package weight mirrors the reference toolkit's weight enum. |
|
Package textshape provides the pure-Go shaping foundation for MeUI.
|
Package textshape provides the pure-Go shaping foundation for MeUI. |