Documentation ¶
Overview ¶
Widget and Layout definition and implementation.
Index ¶
- Variables
- func IsMounted(n *tree.Node[Widget]) bool
- func NeedRenderEventListener(handler func(NeedRenderEvent)) (events.Type, events.Handler)
- func ParentStyle(parent *tree.Node) styles.ComputedStyle
- type BaseLayout
- type BaseLayoutRenderable
- type ChildLayout
- type ChildrenLayout
- type ComposedWidget
- type Event
- type InheritStyle
- type LayoutChildren
- type LayoutChildrenFunc
- type LayoutRenderable
- type LayoutRenderableCache
- type NeedRenderEvent
- type PanicWidget
- type Root
- type Style
- func (s Style) Background(c colors.Color) Style
- func (s Style) Blink(b bool) Style
- func (s Style) Bold(b bool) Style
- func (s Style) Border(borders ...styles.BorderSide) Style
- func (s Style) BorderBottom(b styles.BorderSide) Style
- func (s Style) BorderLeft(b styles.BorderSide) Style
- func (s Style) BorderRight(b styles.BorderSide) Style
- func (s Style) BorderTop(b styles.BorderSide) Style
- func (s Style) BorderX(b styles.BorderSide) Style
- func (s Style) BorderY(b styles.BorderSide) Style
- func (s Style) Compute() styles.ComputedStyle
- func (s Style) Dim(b bool) Style
- func (s Style) Foreground(c colors.Color) Style
- func (s Style) InheritBackground() Style
- func (s Style) InheritBorders() Style
- func (s Style) InheritForeground() Style
- func (s Style) InheritMargin() Style
- func (s Style) InheritPadding() Style
- func (s Style) InheritTextDecoration() Style
- func (s Style) Italic(b bool) Style
- func (s Style) Margin(margins ...int) Style
- func (s Style) MarginBottom(m int) Style
- func (s Style) MarginLeft(m int) Style
- func (s Style) MarginRight(m int) Style
- func (s Style) MarginTop(m int) Style
- func (s Style) MarginX(m int) Style
- func (s Style) MarginY(m int) Style
- func (s Style) Padding(paddings ...int) Style
- func (s Style) PaddingBottom(l int) Style
- func (s Style) PaddingLeft(l int) Style
- func (s Style) PaddingRight(l int) Style
- func (s Style) PaddingTop(l int) Style
- func (s Style) PaddingX(l int) Style
- func (s Style) PaddingY(l int) Style
- func (s Style) Reverse(b bool) Style
- func (s Style) StrikeThrough(b bool) Style
- func (s Style) Style() styles.Style
- func (s Style) Underline(b bool) Style
- type StyledLayoutRenderable
- type Widget
Constants ¶
This section is empty.
Variables ¶
var (
NeedRenderEventType = events.NewType("NeedRender")
)
Functions ¶
func NeedRenderEventListener ¶
func NeedRenderEventListener(handler func(NeedRenderEvent)) (events.Type, events.Handler)
NeedRenderEventListener returns an events.Listener that will call the given handler on resize events.
func ParentStyle ¶
func ParentStyle(parent *tree.Node) styles.ComputedStyle
ParentStyle finds the first ancestor of node that is styled and returns its computed style.
Types ¶
type BaseLayout ¶
type BaseLayout struct { Widget LayoutRenderable }
BaseLayout is a basic layout widget. It can either be used alone or embedded within a struct. BaseLayout - Dispatch mouse events to children - Drawing children
func NewBaseLayout ¶
func NewBaseLayout( widget Widget, renderable LayoutRenderable, ) *BaseLayout
NewBaseLayout returns a BaseLayout that embed the given widget.
func (*BaseLayout) Renderable ¶
func (bl *BaseLayout) Renderable() render.Renderable
Renderable implements render.RenderableAccessor.
func (*BaseLayout) Style ¶
func (bl *BaseLayout) Style() styles.Style
Style implements styles.Styled.
type BaseLayoutRenderable ¶
type BaseLayoutRenderable struct { *render.VoidRenderable // contains filtered or unexported fields }
BaseLayoutRenderable is a wrapper of render.VoidRenderable that implements LayoutRenderable.
func NewBaseLayoutRenderable ¶
func NewBaseLayoutRenderable(nodeAccessor tree.NodeAccessor, layoutChildren LayoutChildren) *BaseLayoutRenderable
NewBaseLayoutRenderable returns a new LayoutRenderable for the given NodeAccessor.
func (BaseLayoutRenderable) ChildrenLayout ¶
func (lr BaseLayoutRenderable) ChildrenLayout() *ChildrenLayout
ChildrenRects implements LayoutRenderable.
func (BaseLayoutRenderable) Draw ¶
func (lr BaseLayoutRenderable) Draw(surface draw.Surface)
Draw implements layout.Layout. BaseLayoutRenderable draw
func (BaseLayoutRenderable) Layout ¶
func (lr BaseLayoutRenderable) Layout(co layout.Constraint) geometry.Size
Layout implements layout.Layout.
type ChildLayout ¶
type ChildLayout struct { // Node associated to rectangle. Node *tree.Node // Bounds relative to layout origin. Bounds geometry.Rectangle }
ChildLayout define position and size of a child Node.
type ChildrenLayout ¶
type ChildrenLayout struct {
// contains filtered or unexported fields
}
ChildrenLayout contains position and size of children Node.
func (*ChildrenLayout) Append ¶
func (cl *ChildrenLayout) Append(child ChildLayout)
Append appends the given ChildLayout.
func (*ChildrenLayout) Get ¶
func (cl *ChildrenLayout) Get(i int) ChildLayout
Get returns ChildLayout relative to parent origin.
func (*ChildrenLayout) Size ¶
func (cl *ChildrenLayout) Size() int
Size returns number of ChildLayout stored.
type ComposedWidget ¶
type ComposedWidget struct { *PanicWidget styles.Styled render.RenderableAccessor }
ComposedWidget define a Widget composed of a PanicWidget, a styles.Styled and a render.RenderableAccessor.
func NewComposedWidget ¶
func NewComposedWidget(styled styles.Styled, renderableAccessor render.RenderableAccessor) *ComposedWidget
func (ComposedWidget) Renderable ¶
func (cw ComposedWidget) Renderable() render.Renderable
Renderable implements render.RenderableAccessor.
func (ComposedWidget) Style ¶
func (cw ComposedWidget) Style() styles.Style
Style implements styles.Styled.
type Event ¶
type Event interface { events.Event // Target returns targeted widget by the event. Target() Widget }
Event define an event within a widget tree.
type InheritStyle ¶
type InheritStyle struct { // NodeAccessor provide node associated with this style. It is used to retrieve // parent node and thus parent style. NodeAccessor tree.NodeAccessor // Style associated with this node. Nil property are inherited on Compute. InnerStyle Style }
InheritStyle define a Style wrapper that adds inheritance capability to it. Inheritance happens when styles.Style.Compute is called.
func (InheritStyle) Compute ¶
func (i InheritStyle) Compute() styles.ComputedStyle
Compute implements styles.Style.
func (InheritStyle) Style ¶
func (i InheritStyle) Style() styles.Style
Style implements styles.Styled.
type LayoutChildren ¶
type LayoutChildren interface { // LayoutChildren layout each children and append them in the given // ChildrenLayout. LayoutChildren(_ layout.Constraint, _ *ChildrenLayout) geometry.Size }
LayoutChildren define any type that can layout its children.
type LayoutChildrenFunc ¶
type LayoutChildrenFunc func(_ layout.Constraint, _ *ChildrenLayout) geometry.Size
LayoutChildrenFunc is function type that implements LayoutChildren interface.
func (LayoutChildrenFunc) LayoutChildren ¶
func (lcf LayoutChildrenFunc) LayoutChildren(co layout.Constraint, r *ChildrenLayout) geometry.Size
LayoutChildren implements LayoutChildren.
type LayoutRenderable ¶
type LayoutRenderable interface { render.Renderable // Returns children bounding rectangle relative to layout origin ChildrenLayout() *ChildrenLayout }
LayoutRenderable define render.Renderable for layouts Widget.
type LayoutRenderableCache ¶
type LayoutRenderableCache struct { render.Cache[*BaseLayoutRenderable] }
LayoutRenderableCache define a LayoutRenderable with cache.
func NewLayoutRenderableCache ¶
func NewLayoutRenderableCache(nodeAccessor tree.NodeAccessor, layout LayoutChildren) LayoutRenderableCache
NewLayoutRenderableCache returns a new LayoutRenderable.
func (LayoutRenderableCache) ChildrenLayout ¶
func (lrc LayoutRenderableCache) ChildrenLayout() *ChildrenLayout
ChildrenLayout implements LayoutRenderable.
type NeedRenderEvent ¶
NeedRenderEvent is emitted by Root widget when widgets tree needs to be rendered.
type PanicWidget ¶
type PanicWidget struct {
// contains filtered or unexported fields
}
PanicWidget define a minimal (and incomplete) Widget type. PanicWidget implements panic methods for styles.Styled and render.RenderableAccessor interfaces.
func NewPanicWidget ¶
func NewPanicWidget(nodeData Widget) *PanicWidget
NewPanicWidget returns a new PanicWidget object configured with the given options.
func (*PanicWidget) Node ¶
func (bw *PanicWidget) Node() *tree.Node[Widget]
Node implements the Widget interface.
func (*PanicWidget) Renderable ¶
func (*PanicWidget) Renderable() render.Renderable
Renderable implements Widget.
func (*PanicWidget) Style ¶
func (*PanicWidget) Style() styles.Style
Style implements styles.Styled.
type Root ¶
type Root struct { Widget // contains filtered or unexported fields }
Root define root of widgets tree.
func NewRoot ¶
NewRoot returns a new Root widget that wraps the given Widget and its render.Renderable.
func (Root) Renderable ¶
func (r Root) Renderable() render.Renderable
Renderable implements render.RenderableAccessor.
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style define a basic style type for widgets.
func (Style) BorderBottom ¶
func (s Style) BorderBottom(b styles.BorderSide) Style
func (Style) BorderLeft ¶
func (s Style) BorderLeft(b styles.BorderSide) Style
func (Style) BorderRight ¶
func (s Style) BorderRight(b styles.BorderSide) Style
func (Style) Compute ¶
func (s Style) Compute() styles.ComputedStyle
Compute implements styles.Style.
func (Style) InheritBackground ¶
func (Style) InheritBorders ¶
func (Style) InheritForeground ¶
func (Style) InheritMargin ¶
func (Style) InheritPadding ¶
func (Style) InheritTextDecoration ¶
func (Style) MarginBottom ¶
func (Style) MarginLeft ¶
func (Style) MarginRight ¶
func (Style) PaddingBottom ¶
func (Style) PaddingLeft ¶
func (Style) PaddingRight ¶
func (Style) PaddingTop ¶
func (Style) StrikeThrough ¶
type StyledLayoutRenderable ¶
type StyledLayoutRenderable struct { styles.Renderable[LayoutRenderable] }
StyledLayoutRenderable define a LayoutRenderable wrapper that adds styling to it.
func NewStyledLayoutRenderable ¶
func NewStyledLayoutRenderable(styled styles.Styled, layoutRenderable LayoutRenderable) StyledLayoutRenderable
NewStyledLayoutRenderable returns a new StyledLayoutRenderable that wraps the given LayoutRenderable.
func (StyledLayoutRenderable) ChildrenLayout ¶
func (slr StyledLayoutRenderable) ChildrenLayout() *ChildrenLayout
ChildrenLayout implements LayoutRenderable.
func (StyledLayoutRenderable) Draw ¶
func (slr StyledLayoutRenderable) Draw(surface draw.Surface)
Draw implements draw.Drawer.
func (StyledLayoutRenderable) Layout ¶
func (slr StyledLayoutRenderable) Layout(co layout.Constraint) geometry.Size
Layout implements layout.Layout.
func (StyledLayoutRenderable) Style ¶
func (slr StyledLayoutRenderable) Style() styles.Style
Style implements styled.Styled.
type Widget ¶
type Widget interface { events.Target styles.Styled tree.NodeAccessor[Widget] render.RenderableAccessor // Swap swaps this widget node with node of the given one. Swap(Widget) // contains filtered or unexported methods }
Widget is a generic interface that define any component part of the widget/element tree. Any types that implement the Widget interface can be added to the widget tree. You must embed *BaseWidget or *BoxWidget to implement this interface as it contains private methods.