Documentation
¶
Overview ¶
Package render provides the core engine for maintaining the render tree. It bridges the logical DOM tree with the Layout and Style engines via render objects that track dirty state and computed styles.
Render objects do not own sparse style state (author styles or element defaults); they act as stateless proxies that query their underlying logical DOM node dynamically.
RenderView and Overlays ¶
The RenderView is the root of the render tree and represents the viewport. It manages the main document flow and a list of overlay render roots that are painted on top of the main flow. LayoutPhase handles both the main tree and all active overlays in a single pass.
Index ¶
- func LayoutPhase(ctx *layout.Context, root Object, available geom.Size)
- func LayoutSubtree(ctx *layout.Context, root Object, space layout.ConstraintSpace) *layout.Fragment
- func Unlink(obj Object)
- type BaseRender
- func (b *BaseRender) CachedBlockSize(width int) (int, bool)
- func (b *BaseRender) CachedLayout(space layout.ConstraintSpace) *layout.Fragment
- func (b *BaseRender) CachedMinMaxSizes() (layout.MinMaxSizes, bool)
- func (b *BaseRender) Children() iter.Seq[Object]
- func (b *BaseRender) ClearDirty(f DirtyFlag)
- func (b *BaseRender) ClearDirtyLayout()
- func (b *BaseRender) ClearDirtyRecursive(f DirtyFlag)
- func (b *BaseRender) ComputedStyle() *style.Computed
- func (b *BaseRender) EventTarget() event.EventTarget
- func (b *BaseRender) FirstChild() Object
- func (b *BaseRender) FirstLayoutChild() layout.Node
- func (b *BaseRender) Flags() DirtyFlag
- func (b *BaseRender) Fragment() *layout.Fragment
- func (b *BaseRender) HasChildNeedsPaint() bool
- func (b *BaseRender) Init(self Object, logicalNode dom.Node, target event.EventTarget)
- func (b *BaseRender) InsertChild(child, before Object)
- func (b *BaseRender) IsAnonymous() bool
- func (b *BaseRender) IsDetached() bool
- func (b *BaseRender) IsDirtyLayout() bool
- func (b *BaseRender) IsDirtyPaint() bool
- func (b *BaseRender) LastChild() Object
- func (b *BaseRender) LogicalNode() dom.Node
- func (b *BaseRender) MarkChildrenDirty()
- func (b *BaseRender) MarkDirty(f DirtyFlag)
- func (b *BaseRender) MaxScroll() (x, y int)
- func (b *BaseRender) NextLayoutSibling(child layout.Node) layout.Node
- func (b *BaseRender) NextSibling() Object
- func (b *BaseRender) Offset() geom.Point
- func (b *BaseRender) Parent() Object
- func (b *BaseRender) PreviousSibling() Object
- func (b *BaseRender) RemoveChild(child Object)
- func (b *BaseRender) SetCachedBlockSize(width, height int)
- func (b *BaseRender) SetCachedLayout(space layout.ConstraintSpace, frag *layout.Fragment)
- func (b *BaseRender) SetCachedMinMaxSizes(sizes layout.MinMaxSizes)
- func (b *BaseRender) SetComputedStyle(c *style.Computed)
- func (b *BaseRender) SetOffset(p geom.Point)
- func (b *BaseRender) Style() *style.Computed
- type Block
- type Box
- type CustomObjectProvider
- type DirtyFlag
- type NodeOrder
- type Object
- type Overlay
- type OverlaySelection
- type RenderObjectHook
- type RenderView
- func (v *RenderView) ComputedStyle() *style.Computed
- func (v *RenderView) Inline() bool
- func (v *RenderView) InvalidateMediaStyles()
- func (v *RenderView) IsDetached() bool
- func (v *RenderView) Overlays() []Object
- func (v *RenderView) SetComputedStyle(*style.Computed)
- func (v *RenderView) SetInline(inline bool)
- func (v *RenderView) SetLogicalNode(n dom.Node)
- func (v *RenderView) SetOverlays(overlays []Object)
- func (v *RenderView) SetViewportSize(sz geom.Size)
- func (v *RenderView) Style() *style.Computed
- func (v *RenderView) ViewportSize() geom.Size
- type SelectionRange
- type SelectionRect
- type SelectionSource
- type Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LayoutPhase ¶
LayoutPhase runs the layout process for the given subtree using the LayoutNG-inspired architecture.
func LayoutSubtree ¶
LayoutSubtree lays out a render subtree with the given constraint space.
Types ¶
type BaseRender ¶
type BaseRender struct {
// contains filtered or unexported fields
}
BaseRender provides a default implementation for many render.Object methods.
func (*BaseRender) CachedBlockSize ¶
func (b *BaseRender) CachedBlockSize(width int) (int, bool)
func (*BaseRender) CachedLayout ¶
func (b *BaseRender) CachedLayout(space layout.ConstraintSpace) *layout.Fragment
func (*BaseRender) CachedMinMaxSizes ¶
func (b *BaseRender) CachedMinMaxSizes() (layout.MinMaxSizes, bool)
func (*BaseRender) ClearDirty ¶
func (b *BaseRender) ClearDirty(f DirtyFlag)
func (*BaseRender) ClearDirtyLayout ¶
func (b *BaseRender) ClearDirtyLayout()
func (*BaseRender) ClearDirtyRecursive ¶
func (b *BaseRender) ClearDirtyRecursive(f DirtyFlag)
func (*BaseRender) ComputedStyle ¶
func (b *BaseRender) ComputedStyle() *style.Computed
func (*BaseRender) EventTarget ¶
func (b *BaseRender) EventTarget() event.EventTarget
func (*BaseRender) FirstChild ¶
func (b *BaseRender) FirstChild() Object
func (*BaseRender) FirstLayoutChild ¶
func (b *BaseRender) FirstLayoutChild() layout.Node
func (*BaseRender) Flags ¶
func (b *BaseRender) Flags() DirtyFlag
func (*BaseRender) Fragment ¶
func (b *BaseRender) Fragment() *layout.Fragment
func (*BaseRender) HasChildNeedsPaint ¶
func (b *BaseRender) HasChildNeedsPaint() bool
func (*BaseRender) Init ¶
func (b *BaseRender) Init(self Object, logicalNode dom.Node, target event.EventTarget)
Init sets the self-pointer and logical identity for the BaseRender.
func (*BaseRender) InsertChild ¶
func (b *BaseRender) InsertChild(child, before Object)
func (*BaseRender) IsAnonymous ¶
func (b *BaseRender) IsAnonymous() bool
func (*BaseRender) IsDetached ¶
func (b *BaseRender) IsDetached() bool
func (*BaseRender) IsDirtyLayout ¶
func (b *BaseRender) IsDirtyLayout() bool
func (*BaseRender) IsDirtyPaint ¶
func (b *BaseRender) IsDirtyPaint() bool
func (*BaseRender) LastChild ¶
func (b *BaseRender) LastChild() Object
func (*BaseRender) LogicalNode ¶
func (b *BaseRender) LogicalNode() dom.Node
func (*BaseRender) MarkChildrenDirty ¶
func (b *BaseRender) MarkChildrenDirty()
func (*BaseRender) MarkDirty ¶
func (b *BaseRender) MarkDirty(f DirtyFlag)
func (*BaseRender) MaxScroll ¶
func (b *BaseRender) MaxScroll() (x, y int)
func (*BaseRender) NextLayoutSibling ¶
func (b *BaseRender) NextLayoutSibling(child layout.Node) layout.Node
func (*BaseRender) NextSibling ¶
func (b *BaseRender) NextSibling() Object
func (*BaseRender) Offset ¶
func (b *BaseRender) Offset() geom.Point
func (*BaseRender) Parent ¶
func (b *BaseRender) Parent() Object
func (*BaseRender) PreviousSibling ¶
func (b *BaseRender) PreviousSibling() Object
func (*BaseRender) RemoveChild ¶
func (b *BaseRender) RemoveChild(child Object)
func (*BaseRender) SetCachedBlockSize ¶
func (b *BaseRender) SetCachedBlockSize(width, height int)
func (*BaseRender) SetCachedLayout ¶
func (b *BaseRender) SetCachedLayout(space layout.ConstraintSpace, frag *layout.Fragment)
func (*BaseRender) SetCachedMinMaxSizes ¶
func (b *BaseRender) SetCachedMinMaxSizes(sizes layout.MinMaxSizes)
func (*BaseRender) SetComputedStyle ¶
func (b *BaseRender) SetComputedStyle(c *style.Computed)
func (*BaseRender) SetOffset ¶
func (b *BaseRender) SetOffset(p geom.Point)
func (*BaseRender) Style ¶
func (b *BaseRender) Style() *style.Computed
type Block ¶
type Block struct {
BaseRender
}
Block represents a standard block-level formatting object.
type Box ¶
type Box struct {
BaseRender
}
type CustomObjectProvider ¶
type CustomObjectProvider interface {
CreateRenderObject() Object
}
CustomObjectProvider is an interface that logical nodes can implement to provide a custom render object instead of the default render.Box.
type DirtyFlag ¶
type DirtyFlag uint16
DirtyFlag is a bitmask that describes what work a render object (or its subtree) needs on the next frame.
All mutations to flags must happen on the main goroutine; this package provides no atomic operations.
const ( // Clean is the zero value; no work is pending. Clean DirtyFlag = 0 // DirtyStyle means the computed style is stale and must be re-resolved // before layout. DirtyStyle DirtyFlag = 1 << 0 // DirtyLayout means the box geometry is stale and must be re-measured. DirtyLayout DirtyFlag = 1 << 1 // DirtyPaint means visible output is stale and the object must be redrawn. DirtyPaint DirtyFlag = 1 << 2 // DirtyScroll means the scroll offset changed. Style and layout caches are // preserved; only the paint walk is needed. The paint phase clears // DirtyScroll together with DirtyPaint. DirtyScroll DirtyFlag = 1 << 3 // ChildNeedsStyle means some descendant has DirtyStyle set. ChildNeedsStyle DirtyFlag = 1 << 5 // ChildNeedsLayout means some descendant has DirtyLayout. ChildNeedsLayout DirtyFlag = 1 << 6 // ChildNeedsPaint means some descendant has DirtyPaint or DirtyScroll. ChildNeedsPaint DirtyFlag = 1 << 7 )
type Object ¶
type Object interface {
// EventTarget returns the event target associated with this render object.
// This is typically the logical DOM node.
EventTarget() event.EventTarget
Parent() Object
FirstChild() Object
LastChild() Object
NextSibling() Object
PreviousSibling() Object
Children() iter.Seq[Object]
InsertChild(child, before Object)
RemoveChild(child Object)
ComputedStyle() *style.Computed
SetComputedStyle(*style.Computed)
Flags() DirtyFlag
MarkDirty(DirtyFlag)
ClearDirty(DirtyFlag)
MarkChildrenDirty()
ClearDirtyRecursive(DirtyFlag)
IsDetached() bool
// layout.Node implementation (Task 05)
Style() *style.Computed
FirstLayoutChild() layout.Node
NextLayoutSibling(layout.Node) layout.Node
IsDirtyLayout() bool
IsDirtyPaint() bool
HasChildNeedsPaint() bool
ClearDirtyLayout()
Fragment() *layout.Fragment
CachedLayout(layout.ConstraintSpace) *layout.Fragment
SetCachedLayout(layout.ConstraintSpace, *layout.Fragment)
CachedMinMaxSizes() (layout.MinMaxSizes, bool)
SetCachedMinMaxSizes(layout.MinMaxSizes)
CachedBlockSize(width int) (int, bool)
SetCachedBlockSize(width, height int)
LogicalNode() dom.Node
// Offset returns the physical offset of this object relative to its parent.
// For most objects, this is managed by the parent's layout algorithm.
// For overlays, this is calculated by the overlay's own layout algorithm.
Offset() geom.Point
// SetOffset updates the physical offset of this object.
SetOffset(geom.Point)
// IsAnonymous reports whether this object is a virtual layout-only node.
IsAnonymous() bool
// MaxScroll returns the maximum horizontal and vertical scroll offsets
// based on the current layout fragment and content extent.
MaxScroll() (x, y int)
}
Object is the interface for all renderable objects that sit in the render tree.
type Overlay ¶
type Overlay struct {
Box
}
Overlay represents an anchored overlay render object.
func NewOverlay ¶
func NewOverlay(logicalNode dom.Node, target event.EventTarget) *Overlay
NewOverlay creates a new Overlay render object.
type OverlaySelection ¶
type RenderObjectHook ¶
type RenderObjectHook interface {
OnRenderObjectCreated(ro Object)
}
RenderObjectHook is an optional interface that logical nodes can implement to be notified when their render object is created or replaced.
type RenderView ¶
type RenderView struct {
BaseRender
// contains filtered or unexported fields
}
RenderView is the root of a render tree. It represents the viewport.
func (*RenderView) ComputedStyle ¶
func (v *RenderView) ComputedStyle() *style.Computed
func (*RenderView) Inline ¶
func (v *RenderView) Inline() bool
Inline reports whether inline mode is enabled.
func (*RenderView) InvalidateMediaStyles ¶
func (v *RenderView) InvalidateMediaStyles()
func (*RenderView) IsDetached ¶
func (v *RenderView) IsDetached() bool
func (*RenderView) Overlays ¶
func (v *RenderView) Overlays() []Object
Overlays returns the list of overlay render trees.
func (*RenderView) SetComputedStyle ¶
func (v *RenderView) SetComputedStyle(*style.Computed)
func (*RenderView) SetInline ¶
func (v *RenderView) SetInline(inline bool)
SetInline configures the render view for inline mode.
func (*RenderView) SetLogicalNode ¶
func (v *RenderView) SetLogicalNode(n dom.Node)
func (*RenderView) SetOverlays ¶
func (v *RenderView) SetOverlays(overlays []Object)
SetOverlays replaces the list of overlay render trees.
func (*RenderView) SetViewportSize ¶
func (v *RenderView) SetViewportSize(sz geom.Size)
SetViewportSize updates the viewport dimensions.
func (*RenderView) Style ¶
func (v *RenderView) Style() *style.Computed
func (*RenderView) ViewportSize ¶
func (v *RenderView) ViewportSize() geom.Size
ViewportSize returns the current viewport dimensions.
type SelectionRange ¶
type SelectionRange interface {
StartContainerAny() any
EndContainerAny() any
StartOffset() int
EndOffset() int
IsCollapsed() bool
StartIndex() int
EndIndex() int
}
SelectionRange is an interface for a selection range.
type SelectionRect ¶
SelectionRect represents a physical rectangle of selected content.
func ResolveSelection ¶
func ResolveSelection( root *layout.Fragment, overlays []OverlaySelection, sel SelectionSource, nodeOrder map[any]NodeOrder, ) []SelectionRect
ResolveSelection maps the active selection to physical screen rectangles.
type SelectionSource ¶
type SelectionSource interface {
RangeCount() int
GetRangeAt(index int) SelectionRange
}
SelectionSource is an interface that provides access to selection ranges.
type Text ¶
type Text struct {
BaseRender
// contains filtered or unexported fields
}
Text represents a text-level render object.
func NewText ¶
func NewText(logicalNode dom.Node, target event.EventTarget) *Text
NewText creates a new Text render object.